Class: SiSU_XML_ODF_ODT::Source::Scroll

Inherits:
SiSU_XML_ODF_ODT::Source show all
Includes:
SiSU_Parts_XML
Defined in:
lib/sisu/xml_odf_odt.rb

Constant Summary collapse

@@img_count =
0
@@docstart =
true
@@fns =
nil

Instance Method Summary collapse

Methods included from SiSU_Parts_XML

#_url_path_image_base, #band1, #band2, #banner_band, #black, #blue_ink, #blue_tinge, #grey, #grey_medium, #grey_pale, #home_button_only, #ico, #png_home, #png_home_button, #set_face, #set_fonts, #table1, #table2, #the_banner, #the_color, #the_font, #the_line_break, #the_png, #the_table_close, #the_url_decoration, #txt_close, #txt_open, #white, #xml_close, #xml_open, #yellow_light

Methods included from SiSU_Parts_Generic

#footer_signature, #home, #home_txt, #i_choice, #i_home_button, #i_ico, #i_new, #rl_root, #root_http, #sisu, #sisu_txt, #sisudoc, #site, #the_icon, #the_text, #the_url, #txt_home, #txt_hp, #txt_hp_alias, #txt_signature, #urify, #url_close, #url_open

Methods inherited from SiSU_XML_ODF_ODT::Source

#read

Constructor Details

#initialize(particulars) ⇒ Scroll

Returns a new instance of Scroll.



132
133
134
135
136
137
138
# File 'lib/sisu/xml_odf_odt.rb', line 132

def initialize(particulars)
  @md,@env,@ao_array=particulars.md,particulars.env,particulars.ao_array
  @make=SiSU_Env::ProcessingSettings.new(@md)
  @tab="\t"
  @br=(@md.opt.act[:maintenance][:set]==:on) \
  ? '' : ''
end

Instance Method Details

#block(dob, p_num) ⇒ Object

P4 #same as verse



536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
# File 'lib/sisu/xml_odf_odt.rb', line 536

def block(dob,p_num)                                                            #P4 #same as verse
  parray=[]
  dob.obj=dob.obj.gsub(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/,
      '<text:a xl:type="simple" xl:href="\1">\1</text:a>'). #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}<text:a xl:type="simple" xl:href="mailto:\\1">\\1</text:a>#{the_url_decoration.xml_close}}).
    gsub(/#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,
      %{#{the_url_decoration.xml_open}<text:a xl:type="simple" xl:href="\\1">\\1</text:a>#{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(/&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+/
  end
  dob.obj=parray.join \
  + %{<text:p text:style-name="P_group">#{p_num[:display]}</text:p>} \
  + '<text:p text:style-name="Standard"/>'
  dob
end

#break_lineObject



157
158
159
160
# File 'lib/sisu/xml_odf_odt.rb', line 157

def break_line
  (@md.opt.act[:maintenance][:set]==:on) \
  ? "\n" : ''
end

#code(dob, p_num) ⇒ Object

P5



562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
# File 'lib/sisu/xml_odf_odt.rb', line 562

def code(dob,p_num)                                                             #P5
  if dob.is==:code
    dob.obj=dob.obj.gsub(/\s\s/,'&#160;&#160;')
    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*$/,'<br />').
        gsub(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/,
          '<text:a xl:type="simple" xl:href="\1">\1</text:a>') #http ftp matches escaped, no decoration
      parray << %{<text:p text:style-name="P_code">#{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>} \
    + '<text:p text:style-name="Standard"/>'
  end
  dob
end

#extract_endnotes(dob = '') ⇒ Object

Used for extraction of endnotes from paragraphs



162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/sisu/xml_odf_odt.rb', line 162

def extract_endnotes(dob='')
  notes=dob.obj.scan(/#{Mx[:en_a_o]}(\d+\s+.+?)#{Mx[:en_a_c]}/)[1] #FIX
  @n=[]
  notes.each do |n| #high cost to deal with <br> 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

#fontface(dob) ⇒ Object



437
438
# File 'lib/sisu/xml_odf_odt.rb', line 437

def fontface(dob)
end

#footnote(t_o) ⇒ Object



446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
# File 'lib/sisu/xml_odf_odt.rb', line 446

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]}/,
        '<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>})
        @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]}/,
          %{<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
    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]}/,
          %{<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
  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

#footnote_urls(str) ⇒ Object



439
440
441
442
443
444
445
# File 'lib/sisu/xml_odf_odt.rb', line 439

def footnote_urls(str)
  str=str.gsub(/#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,
    %{#{the_url_decoration.xml_open}<text:a xl:type="simple" xl:href="\\1">\\1</text:a>#{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

#group(dob, p_num) ⇒ Object

P4 #same as verse



511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
# File 'lib/sisu/xml_odf_odt.rb', line 511

def group(dob,p_num)                                                            #P4 #same as verse
  parray=[]
  dob.obj=dob.obj.gsub(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/,
      '<text:a xl:type="simple" xl:href="\1">\1</text:a>'). #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}<text:a xl:type="simple" xl:href="mailto:\\1">\\1</text:a>#{the_url_decoration.xml_close}}).
    gsub(/#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,
      %{#{the_url_decoration.xml_open}<text:a xl:type="simple" xl:href="\\1">\\1</text:a>#{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(/&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+/
  end
  dob.obj=parray.join \
  + %{<text:p text:style-name="P_group">#{p_num[:display]}</text:p>} \
  + '<text:p text:style-name="Standard"/>'
  dob
end

#group_clean(str) ⇒ Object



491
492
493
494
495
496
497
# File 'lib/sisu/xml_odf_odt.rb', line 491

def group_clean(str)
  str=str.gsub(/&amp;nbsp;|&nbsp;|#{Mx[:nbsp]}/,'&#160;').
    gsub(/</,'&lt;').gsub(/>/,'&gt;').
    gsub(/&lt;(text:span text:style-name="Span_\S+?"|\/text:span)&gt;/,'<\1>'). #works, not ideal
    gsub(/#{Mx[:br_line]}/,'<br />').
    gsub(/&lt;br(?:\s+\/)?&gt;/,'<br />')
end

#heading(dob, p_num) ⇒ Object



206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
# File 'lib/sisu/xml_odf_odt.rb', line 206

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)
      '<text:p text:style-name="P_normal_page_new"> </text:p>'
    elsif @md.pageline \
    and @md.pageline =~m #fix
    else ''
    end
  end
  @@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>}
  else dob.tmp,dob.obj='',''
  end
  dob
end

#image(dob) ⇒ Object



320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
# File 'lib/sisu/xml_odf_odt.rb', line 320

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

#image_odf(img) ⇒ Object



289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
# File 'lib/sisu/xml_odf_odt.rb', line 289

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
    %{<draw:frame draw:style-name="fr1" draw:name="graphics#{@@img_count}" text:anchor-type="as-char" svg:width="#{w}cm" svg:height="#{h}cm" draw:z-index="2"><draw:image xl:href="Pictures/#{i}" xl:type="simple" xl:show="embed" xl:actuate="onLoad"/></draw:frame>#{c}} #anchor-type: as-char or paragraph or char or ...
  else %{<text:p text:style-name="P_normal">[image omitted]</text:p>}
  end
end

#image_src(i) ⇒ Object



246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
# File 'lib/sisu/xml_odf_odt.rb', line 246

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

#markup(data) ⇒ Object

Used for major markup instructions



647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
# File 'lib/sisu/xml_odf_odt.rb', line 647

def markup(data)                                                                 # Used for major markup instructions
  #safe_characters=/[^a-zA-Z0-9}{\/?,."';:)(><\-_&!@%~#\]\[*=$| \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
  
  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(/</,'&lt;').gsub(/>/,'&gt;')
    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(/&nbsp;/,'&#160;')
          if w !~/(?:&\S{2,7}?;)+/
            w=w.gsub(/&/,'&amp;')
          end
          if w !~/&\S{1,7}?;(?:&\S{1,7}?;)+/    #imperfect
            w=w.gsub(/(&\S{1,7};)+&/,'\1&amp;')
          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(/(^|[^}])_(?:<|&lt;)/m,'\1&lt;').gsub(/(^|[^}])_(?:>|&gt;)/m,'\1&gt;').
        gsub(/(^|[^}])_(?:<|&lt;)/m,'\1&lt;').gsub(/(^|[^}])_(?:>|&gt;)/m,'\1&gt;')
    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]}/,'<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[: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='<draw:frame draw:style-name="gr1" text:anchor-type="as-char" svg:width="0.22cm" svg:height="0.22cm" draw:z-index="2"><draw:image xl:href="Pictures/bullet_09.png" xl:type="simple" xl:show="embed" xl:actuate="onLoad"/></draw:frame> ' +
        dob.obj
    end
    dob.obj=dob.obj.gsub(/#{Mx[:br_line]}/,'<br />').
      gsub(/&#169;/,'©'). #too arbitrary
      gsub(/.+?<-#>/,'').                                           # remove dummy headings (used by html) #check
      gsub(/#{Mx[:fa_bold_o]}(.+?)#{Mx[:fa_bold_c]}/,
        '<text:span text:style-name="Span_bold">\1</text:span>').
      gsub(/#{Mx[:fa_italics_o]}(.+?)#{Mx[:fa_italics_c]}/,
        '<text:span text:style-name="Span_italic">\1</text:span>').
      gsub(/#{Mx[:fa_underscore_o]}(.+?)#{Mx[:fa_underscore_c]}/,
        '<text:span text:style-name="Span_underscore">\1</text:span>').
      gsub(/#{Mx[:fa_superscript_o]}(.+?)#{Mx[:fa_superscript_c]}/,
        '<text:span text:style-name="Span_superscript">\1</text:span>').
      gsub(/#{Mx[:fa_subscript_o]}(.+?)#{Mx[:fa_subscript_c]}/,
        '<text:span text:style-name="Span_subscript">\1</text:span>').
      gsub(/#{Mx[:fa_monospace_o]}(.+?)#{Mx[:fa_monospace_c]}/,
        '<text:span text:style-name="Span_monospace">\1</text:span>').
      gsub(/­/u,'-').
      gsub(//u, ' ').       # space identify
      gsub(//u, ' ').       # space identify
      gsub(/·/u,'*').
      gsub(/[­–—]/u,'-').   #— – chk
      gsub(/ < /i,'&#060;').
      gsub(/\\copy(?:right)?\b/,'&#169;').
      gsub(/\\trademark\b|\\tm\b/,'&#174;').
      gsub(/\44/,'&#36;'). #$ watch
      gsub(/<a href=".+?">(.+?)<\/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

#normal(dob, p_num) ⇒ Object

P1 - P3



417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
# File 'lib/sisu/xml_odf_odt.rb', line 417

def normal(dob,p_num)                                                           #P1 - P3
  dob=footnote(dob)
  dob.obj=dob.obj.gsub(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/,
      '<text:a xl:type="simple" xl:href="\1">\1</text:a>'). #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}<text:a xl:type="simple" xl:href="mailto:\\1">\\1</text:a>#{the_url_decoration.xml_close}}).
    gsub(/#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,
      %{#{the_url_decoration.xml_open}<text:a xl:type="simple" xl:href="\\1">\\1</text:a>#{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
    %{<text:p text:style-name="P_indent_#{dob.indent}">#{p_num[:set_ref]}#{set_bookmark_tag(dob)}#{dob.obj}#{p_num[:display]}</text:p>}
  elsif dob.is==:para \
  and dob.hang.to_s =~/[0-9]/ \
  and dob.indent != dob.hang
    %{<text:p text:style-name="P_h#{dob.hang}_i#{dob.indent}">#{p_num[:set_ref]}#{set_bookmark_tag(dob)}#{dob.obj}#{p_num[:display]}</text:p>}
  else %{<text:p text:style-name="P_normal">#{p_num[:set_ref]}#{set_bookmark_tag(dob)}#{dob.obj}#{p_num[:display]}</text:p>}
  end
  dob
end

#obj_break(dob) ⇒ Object



588
589
590
591
592
593
594
595
596
597
598
599
600
601
# File 'lib/sisu/xml_odf_odt.rb', line 588

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

#odf_book_idxObject



177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/sisu/xml_odf_odt.rb', line 177

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

#odf_metadataObject



193
194
195
196
# File 'lib/sisu/xml_odf_odt.rb', line 193

def 
  @per.=SiSU_Metadata::Summary.new(@md).
    odf.
end

#odf_structure(md, dob) ⇒ Object



602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
# File 'lib/sisu/xml_odf_odt.rb', line 602

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 =~ /<!Th?¡/u
    @per.body << table(dob,p_num).obj << break_line*2
  elsif dob.is==:break
    @per.body << obj_break(dob).obj << break_line*2
  else
    @per.body << normal(dob,p_num).obj << break_line*2 # main text, contents, body KEEP
  end
  @@endnotes_para=[]
end

#odf_tailObject



197
198
199
200
201
202
# File 'lib/sisu/xml_odf_odt.rb', line 197

def odf_tail
  manifest="#{@md.file.output_path.manifest.url}/#{@md.file.base_filename.manifest}"
  @per.tail << %{<text:p text:style-name="P_normal">Available document outputs: <br /> &lt;<text:a xl:type="simple" xl:href="#{manifest}">#{manifest}</text:a>&gt;</text:p>}
  @per.tail << %{\n<text:p text:style-name="P_normal">SiSU: &lt;<text:a xl:type="simple" xl:href="http://www.jus.uio.no/lm">www.jus.uio.no/sisu</text:a>&gt; and &lt;<text:a xl:type="simple" xl:href="http://www.sisudoc.org">www.sisudoc.org</text:a>&gt;</text:p>}
  @per.tail << "\n</office:text></office:body></office:document-content>"
end

#poem(dob, p_num) ⇒ Object

P4 #same as group



498
499
500
501
502
503
504
505
506
507
508
509
510
# File 'lib/sisu/xml_odf_odt.rb', line 498

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 << %{<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>} \
  + '<text:p text:style-name="Standard"/>'
  dob
end

#preObject



760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
# File 'lib/sisu/xml_odf_odt.rb', line 760

def pre
  table=if @md.flag_tables
    x=<<WOK
  <style:style style:name="Table1" style:family="table"><style:table-properties style:width="16.999cm" table:align="margins"/></style:style>
  <style:style style:name="Table1.A" style:family="table-column"><style:table-column-properties style:column-width="16.999cm" style:rel-column-width="65535*"/></style:style>
  <style:style style:name="Table1.B" style:family="table-column"><style:table-column-properties style:column-width="8.499cm" style:rel-column-width="32767*"/></style:style>
  <style:style style:name="Table1.C" style:family="table-column"><style:table-column-properties style:column-width="5.666cm" style:rel-column-width="21845*"/></style:style>
  <style:style style:name="Table1.D" style:family="table-column"><style:table-column-properties style:column-width="4.349cm" style:rel-column-width="16383*"/></style:style>
  <style:style style:name="Table1.E" style:family="table-column"><style:table-column-properties style:column-width="3.399cm" style:rel-column-width="13107*"/></style:style>
  <style:style style:name="Table1.F" style:family="table-column"><style:table-column-properties style:column-width="2.833cm" style:rel-column-width="10922*"/></style:style>
  <style:style style:name="Table1.G" style:family="table-column"><style:table-column-properties style:column-width="2.428cm" style:rel-column-width="9362*"/></style:style>
  <style:style style:name="Table1.H" style:family="table-column"><style:table-column-properties style:column-width="2.124cm" style:rel-column-width="8191*"/></style:style>
  <style:style style:name="Table2" style:family="table"><style:table-properties style:width="16.999cm" table:align="margins"/></style:style>
  <style:style style:name="Table2.A" style:family="table-column"><style:table-column-properties style:column-width="16.999cm" style:rel-column-width="65535*"/></style:style>
  <style:style style:name="Table2.B" style:family="table-column"><style:table-column-properties style:column-width="8.499cm" style:rel-column-width="32767*"/></style:style>
  <style:style style:name="Table2.C" style:family="table-column"><style:table-column-properties style:column-width="5.666cm" style:rel-column-width="21845*"/></style:style>
  <style:style style:name="Table2.D" style:family="table-column"><style:table-column-properties style:column-width="4.349cm" style:rel-column-width="16383*"/></style:style>
  <style:style style:name="Table2.E" style:family="table-column"><style:table-column-properties style:column-width="3.999cm" style:rel-column-width="13107*"/></style:style>
  <style:style style:name="Table2.F" style:family="table-column"><style:table-column-properties style:column-width="2.833cm" style:rel-column-width="10922*"/></style:style>
  <style:style style:name="Table2.G" style:family="table-column"><style:table-column-properties style:column-width="2.428cm" style:rel-column-width="9362*"/></style:style>
  <style:style style:name="Table2.H" style:family="table-column"><style:table-column-properties style:column-width="2.124cm" style:rel-column-width="8191*"/></style:style>
  <style:style style:name="Table2.I" style:family="table-column"><style:table-column-properties style:column-width="1.8887cm" style:rel-column-width="7281*"/></style:style>
  <style:style style:name="Table2.J" style:family="table-column"><style:table-column-properties style:column-width="1.6999cm" style:rel-column-width="6553*"/></style:style>
  <style:style style:name="Table2.K" style:family="table-column"><style:table-column-properties style:column-width="1.5453cm" style:rel-column-width="5957*"/></style:style>
  <style:style style:name="Table2.L" style:family="table-column"><style:table-column-properties style:column-width="1.416cm" style:rel-column-width="5461*"/></style:style>
  <style:style style:name="Table2.M" style:family="table-column"><style:table-column-properties style:column-width="1.307" style:rel-column-width="5041*"/></style:style>
  <style:style style:name="Table2.N" style:family="table-column"><style:table-column-properties style:column-width="1.214cm" style:rel-column-width="4681*"/></style:style>
WOK
    x=x.strip
    x=x.gsub(/\n+/m,'') unless @md.opt.act[:maintenance][:set]==:on
    x
  else ''
  end
  x=<<WOK
<?xml version="1.0" encoding="UTF-8"?>
<office:document-content xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:xl="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:rpt="http://openoffice.org/2005/report" xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:grddl="http://www.w3.org/2003/g/data-view#" xmlns:tableooo="http://openoffice.org/2009/table" xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0" xmlns:formx="urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0" xmlns:css3t="http://www.w3.org/TR/css3-text/" office:version="1.2"><office:scripts/>
<office:font-face-decls><style:font-face style:name="DejaVu Sans Mono" svg:font-family="'DejaVu Sans Mono'" style:font-adornments="Book" style:font-family-generic="modern" style:font-pitch="fixed"/><style:font-face style:name="Inconsolata" svg:font-family="Inconsolata" style:font-adornments="Regular" style:font-pitch="fixed"/><style:font-face style:name="Liberation Mono" svg:font-family="'Liberation Mono'" style:font-adornments="Regular" style:font-family-generic="modern" style:font-pitch="fixed"/><style:font-face style:name="DejaVu Sans" svg:font-family="'DejaVu Sans'" style:font-adornments="ExtraLight" style:font-family-generic="swiss" style:font-pitch="variable"/><style:font-face style:name="Nimbus Sans L" svg:font-family="&apos;Nimbus Sans L&apos;" style:font-pitch="variable"/><style:font-face style:name="Tahoma" svg:font-family="Tahoma, Lucidasans, &apos;Lucida Sans&apos;, &apos;Arial Unicode MS&apos;" style:font-pitch="variable"/><style:font-face style:name="Nimbus Roman No9 L" svg:font-family="&apos;Nimbus Roman No9 L&apos;" style:font-family-generic="roman" style:font-pitch="variable"/><style:font-face style:name="Bitstream Vera Sans" svg:font-family="&apos;Bitstream Vera Sans&apos;" style:font-family-generic="swiss" style:font-pitch="variable"/></office:font-face-decls>
<office:automatic-styles>
#{table}
  <style:style style:name="P_table_cell" style:family="paragraph" style:parent-style-name="Table_Contents"><style:paragraph-properties fo:text-align="justify" style:justify-single-word="false"/></style:style>
</office:automatic-styles>
<office:body>
  <office:text text:use-soft-page-breaks="true">
    <office:forms form:automatic-focus="false" form:apply-design-mode="false"/>
    <text:sequence-decls><text:sequence-decl text:display-outline-level="0" text:name="Illustration"/><text:sequence-decl text:display-outline-level="0" text:name="Table"/><text:sequence-decl text:display-outline-level="0" text:name="Text"/><text:sequence-decl text:display-outline-level="0" text:name="Drawing"/></text:sequence-decls>
WOK
  x=x.strip
  x=x.gsub(/\n+/m,'') unless @md.opt.act[:maintenance][:set]==:on
  @per.head << x
end

#publishObject



810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
# File 'lib/sisu/xml_odf_odt.rb', line 810

def publish
  content=[]
  br_pg='<text:p text:style-name="P_normal_page_new"> </text:p>'
  content <<
    @per.head <<
    @per.toc <<
    br_pg <<
    @per.body <<
    @per.book_idx <<
    br_pg <<
    @per. <<
    @per.tail
  SiSU_XML_ODF_ODT::Source::Output.new(content,@md,@env).odf
  @@odf={ head: [], toc: [], body: [], tail: [], book_idx: [], metadata: [] }
end

#set_bookmark_tag(dob) ⇒ Object



203
204
205
# File 'lib/sisu/xml_odf_odt.rb', line 203

def set_bookmark_tag(dob)
  SiSU_XML_ODF_ODT_Format::Tags.new.set_bookmark_tag(dob)
end

#songsheetObject



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/sisu/xml_odf_odt.rb', line 139

def songsheet
  begin
    @per=SiSU_XML_Persist::Persist.new
    pre
    @data=markup(@ao_array)
    publish
  ensure
    SiSU_XML_Persist::Persist.new.persist_init
    unless (@md.opt.act[:verbose_plus][:set]==:on \
    || @md.opt.act[:maintenance][:set]==:on)
      if @env.processing_path.odt =~/od[ft]/
        #p "rm -r #{@env.processing_path.odt}" if @md.opt.selections.str =~/v/
        FileUtils::rm_r(@env.processing_path.odf_pth)
        #system("rm -r #{@env.processing_path.odt}")
      end
    end
  end
end

#table(dob, p_num) ⇒ Object



580
581
582
583
584
585
586
587
# File 'lib/sisu/xml_odf_odt.rb', line 580

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


371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
# File 'lib/sisu/xml_odf_odt.rb', line 371

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


340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
# File 'lib/sisu/xml_odf_odt.rb', line 340

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?:/
    %{<text:a xl:type="simple" xl:href="#{url}">#{txt.strip}</text:a>#{trail}}
  when /^:/                 # site same document collection html link
    url=url.gsub(/^:/,"#{@env.url.root}/")
    %{<text:a xl:type="simple" xl:href="#{url}">#{txt.strip}</text:a>#{trail}}
  when /^\.\.\//                 # site same document collection html link
    url=url.gsub(/^\.\.\//,"#{@env.url.root}/")
    %{<text:a xl:type="simple" xl:href="#{url}">#{txt.strip}</text:a>#{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] \
    ? (%{<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
end


367
368
369
370
# File 'lib/sisu/xml_odf_odt.rb', line 367

def text_link_odf_bookmark(txt,url,trail)
  SiSU_Particulars::CombinedSingleton.instance.get_map_nametags(@md).nametags_map
  %{<text:bookmark-ref text:reference-format="text" text:ref-name="#{url}">#{txt.strip}</text:bookmark-ref>#{trail}}
end


387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
# File 'lib/sisu/xml_odf_odt.rb', line 387

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


403
404
405
406
407
408
409
410
411
412
413
414
415
416
# File 'lib/sisu/xml_odf_odt.rb', line 403

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

#tidywords(wordlist) ⇒ Object



644
645
646
# File 'lib/sisu/xml_odf_odt.rb', line 644

def tidywords(wordlist)
  wordlist
end

#toc(dob, p_num) ⇒ Object



234
235
236
237
238
239
240
241
242
243
244
245
# File 'lib/sisu/xml_odf_odt.rb', line 234

def toc(dob,p_num)
  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>})
  : dob.tmp
  dob.obj=%{<text:h text:style-name="H_#{dob.ln}" text:outline-level="#{dob.ln}">} \
  + %{#{toc_heading}</text:h>#{hardspace}}
  dob
end