From 960c3088bc88f2db879154053280b06c160d4d70 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Tue, 21 Apr 2015 14:45:52 -0400 Subject: lib/sisu/*, single libs directory (c&d gone) (7) * removed lib/sisu/{current,develop} dir branches v7 (v5 & v6 retired) * simplify dir structure, offer single version per snapshot * have enjoyed carrying stable and development versions v5 & v6 in a single tarball, may return to this structure --- lib/sisu/xml_odf_odt.rb | 887 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 887 insertions(+) create mode 100644 lib/sisu/xml_odf_odt.rb (limited to 'lib/sisu/xml_odf_odt.rb') diff --git a/lib/sisu/xml_odf_odt.rb b/lib/sisu/xml_odf_odt.rb new file mode 100644 index 00000000..fa503e83 --- /dev/null +++ b/lib/sisu/xml_odf_odt.rb @@ -0,0 +1,887 @@ +# encoding: utf-8 +=begin + +* Name: SiSU + +** Description: documents, structuring, processing, publishing, search +*** opendocument text generation + +** Author: Ralph Amissah + + + +** Copyright: (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, + 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 Ralph Amissah, + All Rights Reserved. + +** License: GPL 3 or later: + + SiSU, a framework for document structuring, publishing and search + + Copyright (C) Ralph Amissah + + This program is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + more details. + + You should have received a copy of the GNU General Public License along with + this program. If not, see . + + If you have Internet connection, the latest version of the GPL should be + available at these locations: + + + + + +** SiSU uses: + * Standard SiSU markup syntax, + * Standard SiSU meta-markup syntax, and the + * Standard SiSU object citation numbering and system + +** Hompages: + + + +** Git + + + +=end +module SiSU_XML_ODF_ODT + require_relative 'se_hub_particulars' # se_hub_particulars.rb + include SiSU_Particulars + require_relative 'ao' # ao.rb + require_relative 'se' # se.rb + include SiSU_Env + require_relative 'xml_parts' # xml_parts.rb + require_relative 'xml_odf_odt_format' # xml_odf_odt_format.rb + include SiSU_XML_ODF_ODT_Format + require_relative 'shared_metadata' # shared_metadata.rb + require_relative 'txt_shared' # txt_shared.rb + require_relative 'xml_shared' # xml_shared.rb + include SiSU_XML_Munge + require_relative 'xml_persist' # xml_persist.rb + @@alt_id_count,@@alt_id_count=0,0 + class Source + begin + require 'zlib' + require 'find' + rescue LoadError + SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia). + error('zlib or find NOT FOUND (LoadError)') + end + def initialize(opt) + @opt=opt + @particulars=SiSU_Particulars::CombinedSingleton.instance.get_all(opt) + @@endnotes_para=[] + end + def read + begin + @md,@env,@ao_array=@particulars.md,@particulars.env,@particulars.ao_array + unless @opt.act[:quiet][:set]==:on + tool=(@opt.act[:verbose][:set]==:on \ + || @opt.act[:verbose_plus][:set]==:on \ + || @opt.act[:maintenance][:set]==:on) \ + ? "#{@env.program.odf_viewer} file://#{@md.file.output_path.odt.dir}/#{@md.file.base_filename.odt}" + : "[#{@opt.f_pth[:lng_is]}] #{@opt.fno}" + (@opt.act[:verbose][:set]==:on \ + || @opt.act[:verbose_plus][:set]==:on \ + || @opt.act[:maintenance][:set]==:on) \ + ? SiSU_Screen::Ansi.new( + @opt.act[:color_state][:set], + 'Opendocument (ODF:ODT)', + tool + ).green_hi_blue + : SiSU_Screen::Ansi.new( + @opt.act[:color_state][:set], + 'Opendocument (ODF:ODT)', + tool + ).green_title_hi + if (@opt.act[:verbose_plus][:set]==:on \ + || @opt.act[:maintenance][:set]==:on) + SiSU_Screen::Ansi.new( + @opt.act[:color_state][:set], + @opt.fns, + 'file://' \ + + @md.file.output_path.odt.dir + '/' \ + + @md.file.base_filename.odt + ).flow + end + end + SiSU_XML_ODF_ODT::Source::Scroll.new(@particulars).songsheet + rescue + SiSU_Errors::Rescued.new($!,$@,@opt.selections.str,@opt.fns).location do + __LINE__.to_s + ':' + __FILE__ + end + ensure + Dir.chdir(@opt.f_pth[:pth]) + end + end + private + class Scroll appropriately within odf, consider + n=n.dup.to_s + if n =~/#{Mx[:br_line]}/ + fix=n.split(/#{Mx[:br_line]}/) #watch #added + fix.each do |x| + if x =~/\S+/ then @n << x + end + end + else @n << n + end + end + end + def odf_book_idx + if @md.book_idx + idx_arr=[] + idx_raw=SiSU_Particulars::CombinedSingleton. + instance.get_idx_raw(@md.opt).raw_idx + idx_raw.each do |x| + x=if x.is_a?(String) + SiSU_XML_ODF_ODT_Format::FormatBookIndex.new(x). + book_idx_bookmark + else nil + end + idx_arr << x.strip if x.is_a?(String) + end + @per.book_idx=idx_arr.join + end + end + def odf_metadata + @per.metadata=SiSU_Metadata::Summary.new(@md). + odf.metadata + end + def odf_tail + manifest="#{@md.file.output_path.manifest.url}/#{@md.file.base_filename.manifest}" + @per.tail << %{Available document outputs:
<#{manifest}>
} + @per.tail << %{\nSiSU: <www.jus.uio.no/sisu> and <www.sisudoc.org>} + @per.tail << "\n" + end + def set_bookmark_tag(dob) + SiSU_XML_ODF_ODT_Format::Tags.new.set_bookmark_tag(dob) + end + def heading(dob,p_num) + dob=footnote(dob) + m=/#{$1}/ + breakpage='' + if @md.fns \ + and @md.fns != '' \ + and @md.fns !=@@fns + @@docstart=true + @@fns=@md.fns + end + unless @@docstart + breakpage=if (@md.pagenew || @md.pagebreak) \ + and (@md.pagenew =~m or @md.pagebreak =~m) + ' ' + elsif @md.pageline \ + and @md.pageline =~m #fix + else '' + end + end + @@docstart=false + if dob.use_ != :dummy + dob.tmp=dob.obj + dob.obj=%{#{breakpage}} \ + + %{#{p_num[:set_ref]}#{set_bookmark_tag(dob)}#{dob.obj}#{p_num[:display]}} + else dob.tmp,dob.obj='','' + end + dob + end + def toc(dob,p_num) + hardspace=(dob.lv =~/[A-D]/i) \ + ? '' + : '' + toc_heading=dob.ocn \ + ? (%{} \ + + %{#{dob.tmp}}) + : dob.tmp + dob.obj=%{} \ + + %{#{toc_heading}#{hardspace}} + dob + end + def image_src(i) + if @md.fns =~/\.ss[tm]$/ \ + and FileTest.file?("#{@env.path.image_source_include(@md)}/#{i}") #review + @env.path.image_source_include(@md) + elsif @md.opt.f_pth[:pth] =~/\/\S+?\/sisupod\/\S+?\/sisupod\/doc/ + pt=/(\/\S+?\/sisupod\/\S+?\/sisupod)\/doc/.match(@md.opt.f_pth[:pth])[1] + img_src=pt + '/image' + if FileTest.file?("#{img_src}/#{i}") + img_src + else + SiSU_Screen::Ansi.new( + @md.opt.act[:color_state][:set], + "ERROR - image:", + %{"#{i}" missing}, + "search locations: #{@env.path.image_source_include_local}," \ + + "#{@env.path.image_source_include_remote} and" \ + + "#{@env.path.image_source_include}" + ).error2 unless @md.opt.act[:quiet][:set]==:on + nil + end + elsif @md.fns =~/\.ss[tm]$/ \ + and FileTest.file?("#{@env.path.image_source_include_local}/#{i}") #review + @env.path.image_source_include_local + elsif @md.fns =~/\.ss[tm]$/ \ + and FileTest.file?("#{@env.path.image_source_sisu_includes(@md)}/#{i}") + @env.path.image_source_sisu_includes(@md) + elsif @md.fns =~/\.-ss[tm]$/ \ + and FileTest.file?("#{@env.path.image_source_include_remote}/#{i}") + @env.path.image_source_include_remote + else + SiSU_Screen::Ansi.new( + @md.opt.act[:color_state][:set], + "ERROR - image:", + %{"#{i}" missing}, + "search locations: " \ + + @env.path.image_source_include_local + ',' \ + + @env.path.image_source_include_remote + 'and' \ + + @env.path.image_source_include \ + + @md.opt.sisu_data_dir? + ).error2 unless @md.opt.act[:quiet][:set]==:on + nil + end + end + def image_odf(img) + # copy image to od image directory (unless exists) + # divide pixel dimension by 37.79485 and retain 3 decimal places + m=img[1] + i=/^(\S+?\.(?:png|jpg|gif))/.match(m).captures.join \ + if m =~/^(\S+?\.(?:png|jpg|gif))/ + c=/^\S+?\.(?:png|jpg|gif)\s+.+?"(.*?)"/.match(m).captures.join \ + if m =~/^\S+?\.(?:png|jpg|gif)\s+.+?"(.*?)"/ + w,h=/\s(\d+)x(\d+)/.match(m).captures if m =~/\s\d+x\d+/ + w=(w.to_i/37.79485).to_s + h=(h.to_i/37.79485).to_s + h=/([0-9]+\.\d{0,3})/.match(h).captures.join + w=/([0-9]+\.\d{0,3})/.match(w).captures.join + image_source=image_src(i) + if image_source + if FileTest.file?("#{image_source}/#{i}") + FileUtils::cp( + "#{image_source}/#{i}", + "#{@env.processing_path.odt}/Pictures/#{i}" + ) + else STDERR.puts %{\t*WARN* did not find image - "#{image_source}/#{i}" [#{__FILE__}:#{__LINE__}]} + end + end + img=if i.to_s =~/jpg|png|gif/ \ + and h.to_s =~/\d/ \ + and w.to_s =~/\d/ + @@img_count +=1 + %{#{c}} #anchor-type: as-char or paragraph or char or ... + else %{[image omitted]} + end + end + def image(dob) + m=if dob.obj =~/#{Mx[:lnk_o]}[ ]*(.+?)[ ]*#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/ + dob.obj.scan(/(#{Mx[:lnk_o]}[ ]*(.+?)[ ]*#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]})/) + elsif dob.obj =~/#{Mx[:lnk_o]}[ ]*(.+?)[ ]*#{Mx[:lnk_c]}image/ + dob.obj.scan(/(#{Mx[:lnk_o]}[ ]*(.+?)[ ]*#{Mx[:lnk_c]}(image))/) + else nil + end + if m then m.each do |i| + cont,url=i[1],i[2] + cont=cont.gsub(/([)(\]\[])/,"\\\\\\1"). + gsub(/([+?])/,"\\\\\\1") # incorrect handling of + + url=url.gsub(/([+?])/,"\\\\\\1") + dob.obj=dob.obj.sub(/#{Mx[:lnk_o]}[ ]*#{cont}[ ]*#{Mx[:lnk_c]}image/m,image_odf(i)). + sub(/#{Mx[:lnk_o]}[ ]*#{cont}[ ]*#{Mx[:lnk_c]}#{Mx[:url_o]}#{url}#{Mx[:url_c]}/m,image_odf(i)). + sub(/\\([)(\]\[?])/,'\1') #clumsy fix + end + m=nil + end + dob + end + def text_link_odf(txt,url,trail) + txt=txt.gsub(/(\\\+)/,'+') #this is convoluted, and risky :-( + url=url.gsub(/(\\\+)/,'+') #this is convoluted, and risky :-( + map_nametags=SiSU_Particulars::CombinedSingleton. + instance.get_map_nametags(@md).nametags_map + t=case url + when /^https?:/ + %{#{txt.strip}#{trail}} + when /^:/ # site same document collection html link + url=url.gsub(/^:/,"#{@env.url.root}/") + %{#{txt.strip}#{trail}} + when /^\.\.\// # site same document collection html link + url=url.gsub(/^\.\.\//,"#{@env.url.root}/") + %{#{txt.strip}#{trail}} + else # document internal link + if map_nametags[url] \ + and map_nametags[url][:segname] + else p "NOT FOUND name_tags: #{url}" + end + t=map_nametags[url] \ + && map_nametags[url][:segname] \ + ? (%{} \ + + %{#{txt.strip}#{trail}}) + : %{#{txt.strip}#{trail}} + end + t + end + def text_link_odf_bookmark(txt,url,trail) + SiSU_Particulars::CombinedSingleton.instance.get_map_nametags(@md).nametags_map + %{#{txt.strip}#{trail}} + end + def text_link(dob) + m=dob.obj.scan(/(#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]})/) #sort + if m + m.each do |i| + txt,url,trail=i[1],i[2] + txt=txt.gsub(/([)(\]\[])/,"\\\\\\1"). + gsub(/([+?*])/,"\\\\\\1") # problems with + + url=url.gsub(/([+?])/,"\\\\\\1") # problems with + + dob.obj=dob.obj.gsub(/#{Mx[:lnk_o]}[ ]*#{txt}#{Mx[:lnk_c]}#{Mx[:url_o]}#{url}#{Mx[:url_c]}/m, + text_link_odf(txt,url,trail)). #make sure trailing ']' are not caught in url + gsub(/\\([)(\]\[?])/,'\1') #clumsy fix + end + m=nil + end + dob + end + def text_link_relative(dob) + m=dob.obj.scan(/(#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:rel_o]}(\S+?)#{Mx[:rel_c]})/) #sort + if m + m.each do |i| + txt,url,trail=i[1],i[2] + txt=txt.gsub(/([)(\]\[])/,"\\\\\\1"). + gsub(/([+?*])/,"\\\\\\1") # problems with + + url=url.gsub(/([+?])/,"\\\\\\1") # problems with + + dob.obj=dob.obj.gsub(/#{Mx[:lnk_o]}[ ]*#{txt}#{Mx[:lnk_c]}#{Mx[:rel_o]}#{url}#{Mx[:rel_c]}/m, + text_link_odf_bookmark(txt,url,trail)). #make sure trailing ']' are not caught in url + gsub(/\\([)(\]\[?])/,'\1') #clumsy fix + end + m=nil + end + dob + end + def text_link_relative_(dob) + m=dob.obj.scan(/(#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:rel_o]}(\S+?)#{Mx[:rel_c]})/) #sort + if m + m.each do |i| + txt,url,trail=i[1],i[2] + txt=txt.gsub(/([)(\]\[])/,"\\\\\\1") + dob.obj=dob.obj.gsub(/#{Mx[:lnk_o]}[ ]*#{txt}#{Mx[:lnk_c]}#{Mx[:rel_o]}#{url}#{Mx[:rel_c]}/m, + text_link_odf(txt,url,trail)). #make sure trailing ']' are not caught in url + gsub(/\\([)(\]\[?])/,'\1') #clumsy fix + end + m=nil + end + dob + end + def normal(dob,p_num) #P1 - P3 + dob=footnote(dob) + dob.obj=dob.obj.gsub(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/, + '\1'). #http ftp matches escaped, no decoration + gsub(/#{Mx[:url_o]}([a-zA-Z0-9._-]+\@\S+?\.[a-zA-Z0-9._-]+)#{Mx[:url_c]}/, + %{#{the_url_decoration.xml_open}\\1#{the_url_decoration.xml_close}}). + gsub(/#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/, + %{#{the_url_decoration.xml_open}\\1#{the_url_decoration.xml_close}}) #http ftp matches with decoration + dob.obj= if dob.is==:para \ + and dob.indent.to_s =~/[0-9]/ \ + and dob.indent == dob.hang + %{#{p_num[:set_ref]}#{set_bookmark_tag(dob)}#{dob.obj}#{p_num[:display]}} + elsif dob.is==:para \ + and dob.hang.to_s =~/[0-9]/ \ + and dob.indent != dob.hang + %{#{p_num[:set_ref]}#{set_bookmark_tag(dob)}#{dob.obj}#{p_num[:display]}} + else %{#{p_num[:set_ref]}#{set_bookmark_tag(dob)}#{dob.obj}#{p_num[:display]}} + end + dob + end + def fontface(dob) + end + def footnote_urls(str) + str=str.gsub(/#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/, + %{#{the_url_decoration.xml_open}\\1#{the_url_decoration.xml_close}}) + str=text_link(str) if str =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/ + str=text_link_relative(str) if str =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}/ + str + end + def footnote(t_o) + str=if defined? t_o.obj then t_o.obj + elsif t_o.is_a?(String) then t_o + end + if str + @astx||=10000 + @astxs||=20000 + if str =~/#{Mx[:en_a_o]}\d+\s+/ + str=str.gsub(/#{Mx[:en_a_o]}(\d+)\s+(.+?)#{Mx[:en_a_c]}/, + '\1 \2') + end + if str =~/#{Mx[:en_a_o]}([*]+)\s+/ + a=$1.gsub(/([*])/,"\\\\\\1") + str=str.gsub(/#{Mx[:en_a_o]}([*]+)\s+(.+?)#{Mx[:en_a_c]}/, + %{\\1 \\2}) + @astxs+=1 + end + if str=~/#{Mx[:en_a_o]}[*+]+\s/ + asterisk=str.scan(/#{Mx[:en_a_o]}([*+]+)\s+(.+?)#{Mx[:en_a_c]}/) + asterisk.each do |x| + a=x[0].gsub(/([*+])/,"\\\\\\1") + str=group_clean(str) + str=footnote_urls(str) + str=str.gsub(/#{Mx[:en_a_o]}(#{a})\s+(.+?)#{Mx[:en_a_c]}/, + %{\\1 \\2}) + @astx+=1 + end + end + if str=~/#{Mx[:en_b_o]}[*+]\d+\s/ + asterisk=str.scan(/#{Mx[:en_b_o]}([*+]\d+)\s+(.+?)#{Mx[:en_b_c]}/) + asterisk.each do |x| + a=x[0].gsub(/([*+])/,"\\\\\\1") + str=group_clean(str) + str=footnote_urls(str) + str=str.gsub(/#{Mx[:en_b_o]}(#{a})\s+(.+?)#{Mx[:en_b_c]}/, + %{\\1 \\2}) + @astx+=1 + end + end + end + if defined? t_o.obj then t_o.obj=str + elsif t_o.is_a?(String) then t_o=str + end + t_o + end + def group_clean(str) + str=str.gsub(/&nbsp;| |#{Mx[:nbsp]}/,' '). + gsub(//,'>'). + gsub(/<(text:span text:style-name="Span_\S+?"|\/text:span)>/,'<\1>'). #works, not ideal + gsub(/#{Mx[:br_line]}/,'
'). + gsub(/<br(?:\s+\/)?>/,'
') + end + def poem(dob,p_num) #P4 #same as group + parray=[] + dob.obj.split(/#{Mx[:br_line]}|#{Mx[:br_nl]}/).each_with_index do |parablock,i| + set_ref=(i==0) ? "#{p_num[:set_ref]}#{set_bookmark_tag(dob)}" : '' + parablock=group_clean(parablock) + parablock=footnote(parablock) + parray << %{#{set_ref}#{parablock}} if parablock =~/\S+/ + end + dob.obj=parray.join \ + + %{#{p_num[:display]}} \ + + '' + dob + end + def group(dob,p_num) #P4 #same as verse + parray=[] + dob.obj=dob.obj.gsub(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/, + '\1'). #http ftp matches escaped, no decoration + gsub(/#{Mx[:url_o]}([a-zA-Z0-9._-]+\@\S+?\.[a-zA-Z0-9._-]+)#{Mx[:url_c]}/, + %{#{the_url_decoration.xml_open}\\1#{the_url_decoration.xml_close}}). + gsub(/#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/, + %{#{the_url_decoration.xml_open}\\1#{the_url_decoration.xml_close}}) #http ftp matches with decoration + dob.obj.split(/#{Mx[:br_line]}|#{Mx[:br_nl]}/).each_with_index do |parablock,i| + set_ref=(i==0) ? "#{p_num[:set_ref]}#{set_bookmark_tag(dob)}" : '' + parablock=group_clean(parablock) + parablock=parablock.gsub(/<text:a xl:type="simple" xl:href="(.+?)">/m, + ''). + gsub(/<(\/text:a)>/,'<\1>'). + gsub(/<(text:note text:id=.+?)>/,'<\1>'). + gsub(/<(text:p text:style-name="Footnote")>/,'<\1>'). + gsub(/<(\/?text:(?:note-citation|note-body|note|p))>/,'<\1>') + parablock=footnote(parablock) + parray << %{#{set_ref}#{parablock}} if parablock =~/\S+/ + end + dob.obj=parray.join \ + + %{#{p_num[:display]}} \ + + '' + dob + end + def block(dob,p_num) #P4 #same as verse + parray=[] + dob.obj=dob.obj.gsub(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/, + '\1'). #http ftp matches escaped, no decoration + gsub(/#{Mx[:url_o]}([a-zA-Z0-9._-]+\@\S+?\.[a-zA-Z0-9._-]+)#{Mx[:url_c]}/, + %{#{the_url_decoration.xml_open}\\1#{the_url_decoration.xml_close}}). + gsub(/#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/, + %{#{the_url_decoration.xml_open}\\1#{the_url_decoration.xml_close}}) #http ftp matches with decoration + dob.obj.split(/#{Mx[:br_line]}|#{Mx[:br_nl]}/).each_with_index do |parablock,i| + set_ref=(i==0) ? "#{p_num[:set_ref]}#{set_bookmark_tag(dob)}" : '' + parablock=group_clean(parablock) + parablock=parablock.gsub(/<text:a xl:type="simple" xl:href="(.+?)">/m, + ''). + gsub(/<(\/text:a)>/,'<\1>'). + gsub(/<(text:note text:id=.+?)>/,'<\1>'). + gsub(/<(text:p text:style-name="Footnote")>/,'<\1>'). + gsub(/<(\/?text:(?:note-citation|note-body|note|p))>/,'<\1>') + parablock=footnote(parablock) + parray << %{#{set_ref}#{parablock}} \ + if parablock =~/\S+/ + end + dob.obj=parray.join \ + + %{#{p_num[:display]}} \ + + '' + dob + end + def code(dob,p_num) #P5 + if dob.is==:code + dob.obj=dob.obj.gsub(/\s\s/,'  ') + parray=[] + dob.obj.split(/#{Mx[:br_line]}|#{Mx[:br_nl]}/).each_with_index do |parablock,i| + set_ref=(i==0) ? "#{p_num[:set_ref]}#{set_bookmark_tag(dob)}" : '' + parablock=group_clean(parablock) + parablock=parablock.gsub(/^\s*$/,'
'). + gsub(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/, + '\1') #http ftp matches escaped, no decoration + parray << %{#{set_ref}#{parablock}} if parablock =~/\S+/ + end + dob.obj=parray.join \ + + %{#{p_num[:display]}} \ + + '' + end + dob + end + def table(dob,p_num) # + if dob.is ==:table + dob=footnote(dob) #check + table=SiSU_XML_ODF_ODT_Format::Table.new(@md,dob,p_num) + dob=table.table + end + dob + end + def obj_break(dob) + if dob.is ==:break + br=SiSU_XML_ODF_ODT_Format::FormatObjBreak.new(@md,dob) + if dob.obj==Mx[:br_page] \ + or dob.obj==Mx[:br_page_new] + dob=br.br_page + elsif dob.obj==Mx[:br_page_line] + dob=br.br_page_line + elsif dob.obj==Mx[:br_obj] + dob=br.obj_sep + end + end + dob + end + def odf_structure(md,dob) + @md,@dob=md,dob + dob=if dob.is !=:code + dob=image(dob) if dob.obj =~/#{Mx[:lnk_o]}[ ]*\S+?\.(?:png|jpg|gif)\s.+?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|image)/ + dob=text_link(dob) if dob.obj =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/ + dob=text_link_relative(dob) if dob.obj =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}/ + dob + else dob + end + p_num={ display: '', set_ref: '' } + if dob.is !~/(^#{Rx[:meta]}|#{Mx[:br_eof]}|#{Mx[:br_endnotes]})/ + if @make.build.odt_ocn? + if defined? dob.ocn \ + and dob.ocn.is_a?(Fixnum) + p_num=SiSU_XML_ODF_ODT_Format::ParagraphNumber.new(@make,dob.ocn).set_bookmark_and_display + end + end + end + if dob.is==:heading + @per.body << heading(dob,p_num).obj << break_line*2 + if SiSU_Env::ProcessingSettings.new(md).build.toc? + if dob.lv =~/[A-D1]/i + @per.toc << toc(dob,p_num).obj + end + end + elsif dob.is ==:verse + @per.body << poem(dob,p_num).obj << break_line*2 + elsif dob.is==:group + @per.body << group(dob,p_num).obj << break_line*2 + elsif dob.is==:block + @per.body << block(dob,p_num).obj << break_line*2 + elsif dob.is==:code + @per.body << code(dob,p_num).obj << break_line*2 + elsif dob.is==:table #elsif dob.obj =~ /<\-_&!@%~#\]\[*=$| \n+`#{Mx[:tc_p]}]/u + dir=SiSU_Env::InfoEnv.new(@md.fns) + dir.path.odt_bld + @data_mod,@endnotes,@level,@cont,@copen,@odf_contents_close=Array.new(6){[]} + @rcdc=false + (0..7).each { |x| @cont[x]=@level[x]=false } + (4..7).each { |x| @odf_contents_close[x]='' } + odf_tail #($1,$2) + bullet=image_src('bullet_09.png') + if bullet + if FileTest.file?("#{bullet}/bullet_09.png") + FileUtils::cp("#{bullet}/bullet_09.png","#{@env.processing_path.odt}/Pictures/.") + else STDERR.puts %{\t*WARN* did not find image - "#{bullet}/bullet_09.png" [#{__FILE__}:#{__LINE__}]} + end + end + odf_book_idx + odf_metadata + data.each do |dob| + #p dob.obj if dob.obj =~safe_characters and @md.opt.selections.str =~/V/ #KEEP + dob.obj='' if dob.obj =~/#{Mx[:lv_o]}\d+:.*?#{Mx[:lv_c]}.+?#{Mx[:pa_non_object_dummy_heading]}/ #fix Mx[:lv_o] + para_array=[] + dob.obj=dob.obj.gsub(//,'>') + word=dob.obj.scan(/\S+|\n/) + if word + word.each do |w| # _ - / # | : ! ^ ~ + unless dob =~/^(?:#{Rx[:meta]}|%+ )/m + w=w.gsub(/&#(?:126|152);/,'~'). #126 usual + gsub(/ /,' ') + if w !~/(?:&\S{2,7}?;)+/ + w=w.gsub(/&/,'&') + end + if w !~/&\S{1,7}?;(?:&\S{1,7}?;)+/ #imperfect + w=w.gsub(/(&\S{1,7};)+&/,'\1&') + end + end + para_array << w + end + dob.obj=para_array.join(' ') + dob.obj=dob.obj.strip + end + if dob.is==:code #{Mx[:gr_o]}code#{Mx[:gr_c]}/ #fix #code-block: angle brackets special characters #fix + dob.obj=dob.obj.gsub(/(^|[^}])_(?:<|<)/m,'\1<').gsub(/(^|[^}])_(?:>|>)/m,'\1>'). + gsub(/(^|[^}])_(?:<|<)/m,'\1<').gsub(/(^|[^}])_(?:>|>)/m,'\1>') + end + if dob.of==:block + dob.obj=dob.obj.gsub(/#{Mx[:gl_bullet]}/,'● ') + end + dob.obj=dob.obj.gsub(/#{Mx[:fa_strike_o]}(.+?)#{Mx[:fa_strike_c]}/,'\1'). + gsub(/#{Mx[:fa_insert_o]}(.+?)#{Mx[:fa_insert_c]}/,'\1'). + gsub(/#{Mx[:fa_cite_o]}(.+?)#{Mx[:fa_cite_c]}/,'\1'). + gsub(/#{Mx[:tag_o]}\S+?#{Mx[:tag_c]}/, + ''). #check + gsub(/#{Mx[:mk_o]}#([a-zA-Z]+)#{Mx[:mk_c]}/,'&\1;'). + gsub(/#{Mx[:mk_o]}(#[0-9]+)#{Mx[:mk_c]}/,'&\1;'). + gsub(/#{Mx[:mk_o]}[~-]##{Mx[:mk_c]}/,'') + if dob.is==:para \ + and dob.bullet_ + dob.obj=' ' + + dob.obj + end + dob.obj=dob.obj.gsub(/#{Mx[:br_line]}/,'
'). + gsub(/©/,'©'). #too arbitrary + gsub(/.+?<-#>/,''). # remove dummy headings (used by html) #check + gsub(/#{Mx[:fa_bold_o]}(.+?)#{Mx[:fa_bold_c]}/, + '\1'). + gsub(/#{Mx[:fa_italics_o]}(.+?)#{Mx[:fa_italics_c]}/, + '\1'). + gsub(/#{Mx[:fa_underscore_o]}(.+?)#{Mx[:fa_underscore_c]}/, + '\1'). + gsub(/#{Mx[:fa_superscript_o]}(.+?)#{Mx[:fa_superscript_c]}/, + '\1'). + gsub(/#{Mx[:fa_subscript_o]}(.+?)#{Mx[:fa_subscript_c]}/, + '\1'). + gsub(/#{Mx[:fa_monospace_o]}(.+?)#{Mx[:fa_monospace_c]}/, + '\1'). + gsub(/­/u,'-'). + gsub(/ /u, ' '). # space identify + gsub(/ /u, ' '). # space identify + gsub(/·/u,'*'). + gsub(/[­–—]/u,'-'). #— – chk + gsub(/ < /i,'<'). + gsub(/\\copy(?:right)?\b/,'©'). + gsub(/\\trademark\b|\\tm\b/,'®'). + gsub(/\44/,'$'). #$ watch + gsub(/(.+?)<\/a>/,'\1'). + gsub(/#{Mx[:mk_o]}name#\S+?#{Mx[:mk_c]}/,'') # remove name links + wordlist=dob.obj.scan(/\S+/) + dob.obj=tidywords(wordlist).join(' ').strip + @rcdc=true if @rcdc==false \ + and (dob.obj =~/~metadata/ \ + or dob =~/#{Mx[:lv_o]}1:meta#{Mx[:lv_x]}\s*Document Information/) #fix Mx[:lv_o] + if dob.is !~/(^#{Rx[:meta]}|#{Mx[:br_eof]}|#{Mx[:br_endnotes]})/ #check + if defined? dob.ocn and dob.ocn =~/\d+/ + @p_num=SiSU_XML_ODF_ODT_Format::ParagraphNumber.new(@make,dob.ocn) + end + if dob.is ==:heading \ + || dob.is ==:para \ + || dob.is ==:group \ + || dob.is ==:verse \ + || dob.is ==:code \ + || dob.is ==:table \ + || dob.is ==:break + odf_structure(@md,dob) + end + if dob.obj ## Clean Prepared Text + dob.obj=dob.obj.gsub(//,' '). + gsub(/#{Mx[:tc_o]}.+?#{Mx[:tc_c]}/,' '). + gsub(/<:\S+>/,' ') + end + end + end + end + def pre + table=if @md.flag_tables + x=< + + + + + + + + + + + + + + + + + + + + + + + +WOK + x=x.strip + x=x.gsub(/\n+/m,'') unless @md.opt.act[:maintenance][:set]==:on + x + else '' + end + x=< + + + +#{table} + + + + + + +WOK + x=x.strip + x=x.gsub(/\n+/m,'') unless @md.opt.act[:maintenance][:set]==:on + @per.head << x + end + def publish + content=[] + br_pg=' ' + content << + @per.head << + @per.toc << + br_pg << + @per.body << + @per.book_idx << + br_pg << + @per.metadata << + @per.tail + SiSU_XML_ODF_ODT::Source::Output.new(content,@md,@env).odf + @@odf={ head: [], toc: [], body: [], tail: [], book_idx: [], metadata: [] } + end + end + class Output