aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/sisu/v6/xml_odf_odt.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sisu/v6/xml_odf_odt.rb')
-rw-r--r--lib/sisu/v6/xml_odf_odt.rb97
1 files changed, 65 insertions, 32 deletions
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}<text:h text:style-name="H_#{dob.ln}" text:outline-level="#{dob.ln}">#{p_num[:set_ref]}#{set_bookmark_tag(dob)}#{dob.obj}#{p_num[:display]}</text:h>}
+ dob.obj=%{#{breakpage}<text:h text:style-name="H_#{dob.ln}" text:outline-level="#{dob.ln}">} \
+ + %{#{p_num[:set_ref]}#{set_bookmark_tag(dob)}#{dob.obj}#{p_num[:display]}</text:h>}
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) \
? '<text:p text:style-name="Standard"/>'
: ''
toc_heading=dob.ocn \
- ? %{<text:bookmark-ref text:reference-format="text" text:ref-name="#{dob.ocn}">#{dob.tmp}</text:bookmark-ref>}
+ ? (%{<text:bookmark-ref text:reference-format="text" text:ref-name="#{dob.ocn}">} \
+ + %{#{dob.tmp}</text:bookmark-ref>})
: dob.tmp
- dob.obj=%{<text:h text:style-name="H_#{dob.ln}" text:outline-level="#{dob.ln}">#{toc_heading}</text:h>#{hardspace}}
+ dob.obj=%{<text:h text:style-name="H_#{dob.ln}" text:outline-level="#{dob.ln}">} \
+ + %{#{toc_heading}</text:h>#{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?:/
%{<text:a xl:type="simple" xl:href="#{url}">#{txt.strip}</text:a>#{trail}}
@@ -342,7 +361,8 @@ module SiSU_XML_ODF_ODT
end
t=map_nametags[url] \
&& map_nametags[url][:segname] \
- ? %{<text:a xl:type="simple" xl:href="#{@env.url.root}/#{@md.fnb}/#{map_nametags[url][:segname]}#{Sfx[:html]}##{url}">#{txt.strip}</text:a>#{trail}}
+ ? (%{<text:a xl:type="simple" xl:href="#{@env.url.root}/#{@md.fnb}/#{map_nametags[url][:segname]}#{Sfx[:html]}##{url}">} \
+ + %{#{txt.strip}</text:a>#{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]}/,'<text:note text:id="ftn\1" text:note-class="footnote"><text:note-citation>\1</text:note-citation><text:note-body><text:p text:style-name="Footnote"> \2</text:p><text:p text:style-name="Footnote"/></text:note-body></text:note>')
+ str=str.gsub(/#{Mx[:en_a_o]}(\d+)\s+(.+?)#{Mx[:en_a_c]}/,
+ '<text:note text:id="ftn\1" text:note-class="footnote"><text:note-citation>\1</text:note-citation><text:note-body><text:p text:style-name="Footnote"> \2</text:p><text:p text:style-name="Footnote"/></text:note-body></text:note>')
end
if str =~/#{Mx[:en_a_o]}([*]+)\s+/
a=$1.gsub(/([*])/,"\\\\\\1")
- str=str.gsub(/#{Mx[:en_a_o]}([*]+)\s+(.+?)#{Mx[:en_a_c]}/,%{<text:note text:id="ftn#{@astx.to_s}" text:note-class="footnote"><text:note-citation text:label="\\1">\\1</text:note-citation><text:note-body><text:p text:style-name="Footnote"> \\2</text:p><text:p text:style-name="Footnote"/></text:note-body></text:note>})
+ str=str.gsub(/#{Mx[:en_a_o]}([*]+)\s+(.+?)#{Mx[:en_a_c]}/,
+ %{<text:note text:id="ftn#{@astx.to_s}" text:note-class="footnote"><text:note-citation text:label="\\1">\\1</text:note-citation><text:note-body><text:p text:style-name="Footnote"> \\2</text:p><text:p text:style-name="Footnote"/></text:note-body></text:note>})
@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]}/,%{<text:note text:id="ftn#{@astx.to_s}" text:note-class="footnote"><text:note-citation text:label="\\1">\\1</text:note-citation><text:note-body><text:p text:style-name="Footnote"> \\2</text:p><text:p text:style-name="Footnote"/></text:note-body></text:note>})
+ str=str.gsub(/#{Mx[:en_a_o]}(#{a})\s+(.+?)#{Mx[:en_a_c]}/,
+ %{<text:note text:id="ftn#{@astx.to_s}" text:note-class="footnote"><text:note-citation text:label="\\1">\\1</text:note-citation><text:note-body><text:p text:style-name="Footnote"> \\2</text:p><text:p text:style-name="Footnote"/></text:note-body></text:note>})
@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]}/,%{<text:note text:id="ftn#{@astx.to_s}" text:note-class="footnote"><text:note-citation text:label="\\1">\\1</text:note-citation><text:note-body><text:p text:style-name="Footnote"> \\2</text:p><text:p text:style-name="Footnote"/></text:note-body></text:note>})
+ str=str.gsub(/#{Mx[:en_b_o]}(#{a})\s+(.+?)#{Mx[:en_b_c]}/,
+ %{<text:note text:id="ftn#{@astx.to_s}" text:note-class="footnote"><text:note-citation text:label="\\1">\\1</text:note-citation><text:note-body><text:p text:style-name="Footnote"> \\2</text:p><text:p text:style-name="Footnote"/></text:note-body></text:note>})
@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(/&lt;text:a xl:type="simple" xl:href="(.+?)"&gt;/m,'<text:a xl:type="simple" xl:href="\1">').
+ parablock=parablock.gsub(/&lt;text:a xl:type="simple" xl:href="(.+?)"&gt;/m,
+ '<text:a xl:type="simple" xl:href="\1">').
gsub(/&lt;(\/text:a)&gt;/,'<\1>').
gsub(/&lt;(text:note text:id=.+?)&gt;/,'<\1>').
gsub(/&lt;(text:p text:style-name="Footnote")&gt;/,'<\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(/&lt;text:a xl:type="simple" xl:href="(.+?)"&gt;/m,'<text:a xl:type="simple" xl:href="\1">').
+ parablock=parablock.gsub(/&lt;text:a xl:type="simple" xl:href="(.+?)"&gt;/m,
+ '<text:a xl:type="simple" xl:href="\1">').
gsub(/&lt;(\/text:a)&gt;/,'<\1>').
gsub(/&lt;(text:note text:id=.+?)&gt;/,'<\1>').
gsub(/&lt;(text:p text:style-name="Footnote")&gt;/,'<\1>').
gsub(/&lt;(\/?text:(?:note-citation|note-body|note|p))&gt;/,'<\1>')
parablock=footnote(parablock)
- parray << %{<text:p text:style-name="P_group">#{set_ref}#{parablock}</text:p>} if parablock =~/\S+/
+ parray << %{<text:p text:style-name="P_group">#{set_ref}#{parablock}</text:p>} \
+ if parablock =~/\S+/
end
dob.obj=parray.join \
+ %{<text:p text:style-name="P_group">#{p_num[:display]}</text:p>} \
@@ -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]}/,'<del>\1</del>').
gsub(/#{Mx[:fa_insert_o]}(.+?)#{Mx[:fa_insert_c]}/,'<ins>\1</ins>').
gsub(/#{Mx[:fa_cite_o]}(.+?)#{Mx[:fa_cite_c]}/,'<cite>\1</cite>').
- gsub(/#{Mx[:tag_o]}\S+?#{Mx[:tag_c]}/,'<text:bookmark-start text:name="\1"/><text:bookmark-end text:name="\1"/>'). #check
+ gsub(/#{Mx[:tag_o]}\S+?#{Mx[:tag_c]}/,
+ '<text:bookmark-start text:name="\1"/><text:bookmark-end text:name="\1"/>'). #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