From 879a4e6cbe97721bbc6cd18b324524159b4807ef Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Thu, 9 May 2013 22:21:33 -0400 Subject: v5 dev branch opened (starts as copy of v4 stable branch); v3 branch closed * 5.0.0 dev opened * 4.1.0 stable * 3.* branch gone --- lib/sisu/v3/odf.rb | 823 ----------------------------------------------------- 1 file changed, 823 deletions(-) delete mode 100644 lib/sisu/v3/odf.rb (limited to 'lib/sisu/v3/odf.rb') diff --git a/lib/sisu/v3/odf.rb b/lib/sisu/v3/odf.rb deleted file mode 100644 index 71cbcca5..00000000 --- a/lib/sisu/v3/odf.rb +++ /dev/null @@ -1,823 +0,0 @@ -# encoding: utf-8 -=begin - - * Name: SiSU - - * Description: a framework for document structuring, publishing and search - - * Author: Ralph Amissah - - * Copyright: (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, - 2007, 2008, 2009, 2010, 2011, 2012, 2013 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: - - - - * Download: - - - * Git - - - - * Ralph Amissah - - - - ** Description: opendocument text generation - -=end -module SiSU_ODF - require_relative 'particulars' # particulars.rb - include SiSU_Particulars - require_relative 'dal' # dal.rb - require_relative 'sysenv' # sysenv.rb - include SiSU_Env - include SiSU_Viz - require_relative 'odf_format' # odf_format.rb - include SiSU_ODF_Format - require_relative 'shared_metadata' # shared_metadata.rb - require_relative 'shared_txt' # shared_txt.rb - @@alt_id_count,@@alt_id_count,@@tablehead,@@number_of_cols=0,0,0,0 - class Source - require 'zlib' - require 'find' - def initialize(opt) - @opt=opt - @particulars=SiSU_Particulars::CombinedSingleton.instance.get_all(opt) - @@endnotes_para=[] - end - def read - begin - @md,@env,@dal_array=@particulars.md,@particulars.env,@particulars.dal_array - unless @opt.cmd =~/q/ - tool=(@opt.cmd =~/[MVv]/) \ - ? "#{@env.program.odf_viewer} file://#{@md.file.output_path.odt.dir}/#{@md.file.base_filename.odt}" - : "[#{@opt.f_pth[:lng_is]}] #{@opt.fno}" - @opt.cmd=~/[MVvz]/ \ - ? SiSU_Screen::Ansi.new(@opt.cmd,'Opendocument (ODF:ODT)',tool).green_hi_blue - : SiSU_Screen::Ansi.new(@opt.cmd,'Opendocument (ODF:ODT)',tool).green_title_hi - SiSU_Screen::Ansi.new(@opt.cmd,@opt.fns,"file://#{@md.file.output_path.odt.dir}/#{@md.file.base_filename.odt}").flow if @opt.cmd =~/[MV]/ - end - SiSU_ODF::Source::Scroll.new(@particulars).songsheet - SiSU_Env::InfoSkin.new(@md).select - rescue - SiSU_Errors::InfoError.new($!,$@,@opt.cmd,@opt.fns).error do - __LINE__.to_s + ':' + __FILE__ - end - ensure - 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_ODF_Format::FormatBookIndex.new(x).book_idx_bookmark - else nil - end - idx_arr << x.strip if x.is_a?(String) - end - @@odf[:book_idx]=idx_arr.join - end - end - def odf_metadata - @@odf[:metadata]=SiSU_Metadata::Summary.new(@md).odf.metadata - end - def odf_tail - generator="Generated by: #{@md.sisu_version[:project]} #{@md.sisu_version[:version]} of #{@md.sisu_version[:date_stamp]} (#{@md.sisu_version[:date]})" if @md.sisu_version[:version] - lastdone="Last Generated on: #{Time.now}" - rubyv="Ruby version: #{@md.ruby_version}" - sc=if @md.sc_info - "Source file: #{@md.sc_filename}\nVersion number: #{@md.sc_number}\nVersion date: #{@md.sc_date}\n" - else '' - end - url=@md.fnb - fn=@md.file.base_filename.manifest - manifest="#{@md.file.output_path.manifest.url}/#{@md.file.base_filename.manifest}" - @@odf[:tail] << %{Available document outputs:
<#{manifest}>
} - @@odf[:tail] << %{\nSiSU: <www.jus.uio.no/sisu> and <www.sisudoc.org>} - @@odf[:tail] << "\n" - end - def set_bookmark_tag(dob) - tags=SiSU_ODF_Format::Tags.new.set_bookmark_tag(dob) - end - def heading(dob,p_num) - 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 or @md.pagebreak) \ - and (@md.pagenew =~ m or @md.pagebreak =~m) - ' ' - else '' - end - end - @@docstart=false - dob.tmp=dob.obj - dob.obj=%{#{breakpage}#{p_num[:set_ref]}#{set_bookmark_tag(dob)}#{dob.obj}#{p_num[:display]}} - dob - end - def toc(dob,p_num) - m=/#{$1}/ - hardspace=(dob.lv =~/[A-C]/i) \ - ? '' - : '' - toc_heading=dob.ocn \ - ? %{#{dob.tmp}} - : dob.tmp - dob.obj=%{#{toc_heading}#{hardspace}} - dob - end - def image_src(i) - image_source=if @md.fns =~/\.ss[tm]$/ \ - and FileTest.file?("#{@env.path.image_source_include}/#{i}") #review - @env.path.image_source_include - 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.cmd,"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.cmd =~/q/ - 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}/#{i}") - @env.path.image_source_sisu_includes - 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.cmd,"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.cmd =~/q/ - 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,u=img[1],img[2] - 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) - pwd=Dir.pwd - 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) - map_nametags=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.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]}/, - %{#{@brace_url.xml_open}\\1#{@brace_url.xml_close}}). - gsub(/#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/, - %{#{@brace_url.xml_open}\\1#{@brace_url.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]}/, - %{#{@brace_url.xml_open}\\1#{@brace_url.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) - 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]}/, - %{#{@brace_url.xml_open}\\1#{@brace_url.xml_close}}). - gsub(/#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/, - %{#{@brace_url.xml_open}\\1#{@brace_url.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 xlink:type="simple" xlink: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]}/, - %{#{@brace_url.xml_open}\\1#{@brace_url.xml_close}}). - gsub(/#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/, - %{#{@brace_url.xml_open}\\1#{@brace_url.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 xlink:type="simple" xlink: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 - table=SiSU_ODF_Format::Table.new(@md,dob,p_num) - dob=table.table - end - dob - end - def obj_break(dob) - if dob.is ==:break - br=SiSU_ODF_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_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 defined? dob.ocn \ - and dob.ocn.is_a?(Fixnum) - p_num=SiSU_ODF_Format::ParagraphNumber.new(dob.ocn).set_bookmark_and_display - #p_num=SiSU_ODF_Format::ParagraphNumber.new(dob.ocn).set_ref_and_display - end - end - dob=footnote(dob) - if dob.is==:heading - @@odf[:body] << heading(dob,p_num).obj << @br*2 - if SiSU_Env::ProcessingSettings.new(md).build.toc? - if dob.lv =~/[A-C1]/i - @@odf[:toc] << toc(dob,p_num).obj - end - end - elsif dob.is ==:verse - @@odf[:body] << poem(dob,p_num).obj << @br*2 - elsif dob.is==:group - @@odf[:body] << group(dob,p_num).obj << @br*2 - elsif dob.is==:block - @@odf[:body] << block(dob,p_num).obj << @br*2 - elsif dob.is==:code - @@odf[:body] << code(dob,p_num).obj << @br*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..6).each { |x| @cont[x]=@level[x]=false } - (4..6).each { |x| @odf_contents_close[x]='' } - odf_tail #($1,$2) - fix=[] - 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.cmd =~/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_ODF_Format::ParagraphNumber.new(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.cmd=~/M/ - x - else '' - end - breakpage=if @md.pagenew \ - or @md.pagebreak - ' fo:break-before="page"' - else '' - end - x=< - - - -#{table} - - - - - - -WOK - x=x.strip - x=x.gsub(/\n+/m,'') unless @md.opt.cmd=~/M/ - @@odf[:head] << x - end - def post - end - def publish - divider='=' - content=[] - br_pg=' ' - data=@data - content << - @@odf[:head] << - @@odf[:toc] << - br_pg << - @@odf[:body] << - @@odf[:book_idx] << - br_pg << - @@odf[:metadata] << - @@odf[:tail] - SiSU_ODF::Source::Output.new(content,@md,@env).odf - @@odf={ head: [], toc: [], body: [], tail: [], book_idx: [], metadata: [] } - end - end - class Output