From 6bc3b814011e829db684ec96bb3abd1e4abb29c3 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Fri, 8 Aug 2014 00:34:25 -0400 Subject: v5 v6: extend document structure, headings A - D, 1 - 4 * sql db table structure changed (needs to be rebuilt) --- lib/sisu/v6/xml_odf_odt.rb | 97 +++++++++++++++++++++++++++++++--------------- 1 file changed, 65 insertions(+), 32 deletions(-) (limited to 'lib/sisu/v6/xml_odf_odt.rb') diff --git a/lib/sisu/v6/xml_odf_odt.rb b/lib/sisu/v6/xml_odf_odt.rb index bb69be5d..c5e06109 100644 --- a/lib/sisu/v6/xml_odf_odt.rb +++ b/lib/sisu/v6/xml_odf_odt.rb @@ -111,7 +111,9 @@ module SiSU_XML_ODF_ODT SiSU_Screen::Ansi.new( @opt.act[:color_state][:set], @opt.fns, - "file://#{@md.file.output_path.odt.dir}/#{@md.file.base_filename.odt}" + 'file://' \ + + @md.file.output_path.odt.dir + '/' \ + + @md.file.base_filename.odt ).flow end end @@ -173,16 +175,19 @@ module SiSU_XML_ODF_ODT if x =~/\S+/ then @n << x end end - else @n << n + 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_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 + SiSU_XML_ODF_ODT_Format::FormatBookIndex.new(x). + book_idx_bookmark else nil end idx_arr << x.strip if x.is_a?(String) @@ -191,7 +196,8 @@ module SiSU_XML_ODF_ODT end end def odf_metadata - @@odf[:metadata]=SiSU_Metadata::Summary.new(@md).odf.metadata + @@odf[:metadata]=SiSU_Metadata::Summary.new(@md). + odf.metadata end def odf_tail manifest="#{@md.file.output_path.manifest.url}/#{@md.file.base_filename.manifest}" @@ -224,19 +230,22 @@ module SiSU_XML_ODF_ODT @@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]}} + 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-C]/i) \ + hardspace=(dob.lv =~/[A-D]/i) \ ? '' : '' toc_heading=dob.ocn \ - ? %{#{dob.tmp}} + ? (%{} \ + + %{#{dob.tmp}}) : dob.tmp - dob.obj=%{#{toc_heading}#{hardspace}} + dob.obj=%{} \ + + %{#{toc_heading}#{hardspace}} dob end def image_src(i) @@ -253,7 +262,9 @@ module SiSU_XML_ODF_ODT @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}" + "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 @@ -271,7 +282,9 @@ module SiSU_XML_ODF_ODT @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}" + "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 @@ -280,8 +293,10 @@ module SiSU_XML_ODF_ODT # 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+.+?"(.*?)"/ + 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 @@ -290,7 +305,10 @@ module SiSU_XML_ODF_ODT 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}") + 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 @@ -325,7 +343,8 @@ module SiSU_XML_ODF_ODT 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 + map_nametags=SiSU_Particulars::CombinedSingleton. + instance.get_map_nametags(@md).nametags_map t=case url when /^https?:/ %{#{txt.strip}#{trail}} @@ -342,7 +361,8 @@ module SiSU_XML_ODF_ODT end t=map_nametags[url] \ && map_nametags[url][:segname] \ - ? %{#{txt.strip}#{trail}} + ? (%{} \ + + %{#{txt.strip}#{trail}}) : %{#{txt.strip}#{trail}} end t @@ -359,7 +379,8 @@ module SiSU_XML_ODF_ODT 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 + 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 @@ -374,7 +395,8 @@ module SiSU_XML_ODF_ODT 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 + 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 @@ -387,7 +409,8 @@ module SiSU_XML_ODF_ODT 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 + 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 @@ -431,11 +454,13 @@ module SiSU_XML_ODF_ODT @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') + 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}) + str=str.gsub(/#{Mx[:en_a_o]}([*]+)\s+(.+?)#{Mx[:en_a_c]}/, + %{\\1 \\2}) @astxs+=1 end if str=~/#{Mx[:en_a_o]}[*+]+\s/ @@ -444,7 +469,8 @@ module SiSU_XML_ODF_ODT 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}) + str=str.gsub(/#{Mx[:en_a_o]}(#{a})\s+(.+?)#{Mx[:en_a_c]}/, + %{\\1 \\2}) @astx+=1 end end @@ -454,7 +480,8 @@ module SiSU_XML_ODF_ODT 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}) + str=str.gsub(/#{Mx[:en_b_o]}(#{a})\s+(.+?)#{Mx[:en_b_c]}/, + %{\\1 \\2}) @astx+=1 end end @@ -495,7 +522,8 @@ module SiSU_XML_ODF_ODT 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,''). + 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>'). @@ -519,13 +547,15 @@ module SiSU_XML_ODF_ODT 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,''). + 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+/ + parray << %{#{set_ref}#{parablock}} \ + if parablock =~/\S+/ end dob.obj=parray.join \ + %{#{p_num[:display]}} \ @@ -593,7 +623,7 @@ module SiSU_XML_ODF_ODT if dob.is==:heading @@odf[:body] << heading(dob,p_num).obj << break_line*2 if SiSU_Env::ProcessingSettings.new(md).build.toc? - if dob.lv =~/[A-C1]/i + if dob.lv =~/[A-D1]/i @@odf[:toc] << toc(dob,p_num).obj end end @@ -623,8 +653,8 @@ module SiSU_XML_ODF_ODT dir.path.odt_bld @data_mod,@endnotes,@level,@cont,@copen,@odf_contents_close=Array.new(6){[]} @rcdc=false - (0..6).each { |x| @cont[x]=@level[x]=false } - (4..6).each { |x| @odf_contents_close[x]='' } + (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 @@ -668,7 +698,8 @@ module SiSU_XML_ODF_ODT 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[: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]}/,'') @@ -706,7 +737,8 @@ module SiSU_XML_ODF_ODT 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] + 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) @@ -835,7 +867,8 @@ WOK end od.close opendoc=@md.file.base_filename.odt #watch where output by language - FileUtils::mkdir_p(@md.file.output_path.odt.dir) unless FileTest.directory?(@md.file.output_path.odt.dir) + FileUtils::mkdir_p(@md.file.output_path.odt.dir) \ + unless FileTest.directory?(@md.file.output_path.odt.dir) if FileTest.directory?(@env.processing_path.odt) \ and SiSU_Env::SystemCall.new.zip pwd=Dir.pwd -- cgit v1.2.3