From f37d75fba7597e466447877f52d20d21b3355807 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Mon, 2 Dec 2013 23:08:06 -0500 Subject: v5: dal_doc_str.rb, changes related to collapsed level * for headings added for structure, without ocn * testing required --- lib/sisu/v5/dal_doc_str.rb | 373 ++++++++++++++++++++++++++------------------- 1 file changed, 215 insertions(+), 158 deletions(-) (limited to 'lib') diff --git a/lib/sisu/v5/dal_doc_str.rb b/lib/sisu/v5/dal_doc_str.rb index 203bc988..7a89dfb1 100644 --- a/lib/sisu/v5/dal_doc_str.rb +++ b/lib/sisu/v5/dal_doc_str.rb @@ -868,7 +868,6 @@ has incorrect level and/or parent level} && (dob.of !=:comment \ && dob.of !=:layout \ && dob.of !=:meta) \ - && dob.obj !~/#{Mx[:pa_non_object_no_heading]}|#{Mx[:pa_non_object_dummy_heading]}/ \ && dob.ocn_ #dob.ln now is determined, and set earlier, check how best to remove this --> if dob.is==:heading @@ -884,181 +883,239 @@ has incorrect level and/or parent level} when '6'; 9 end end - if not dob.obj =~/<:#>|~#|-#/ \ - or not dob.toc_ # fix this no longer in dob.obj + if not dob.obj =~/~#|-#/ ocn+=1 - if dob.is==:heading \ - and (ln.to_s =~/^[1-9]/ \ - or ln.to_s =~@md.lv1 \ - or ln.to_s =~@md.lv2 \ - or ln.to_s =~@md.lv3 \ - or ln.to_s =~@md.lv4 \ - or ln.to_s =~@md.lv5 \ - or ln.to_s =~@md.lv6) + end + if dob.is==:heading \ + and (ln.to_s =~/^[1-9]/ \ + or ln.to_s =~@md.lv1 \ + or ln.to_s =~@md.lv2 \ + or ln.to_s =~@md.lv3 \ + or ln.to_s =~@md.lv4 \ + or ln.to_s =~@md.lv5 \ + or ln.to_s =~@md.lv6) + if not dob.obj =~/~#|-#/ ocnh+=1 - if ln==1 \ - or ln=~@md.lv1; ocnh1+=1 #heading + end + if ln==1 \ + or ln=~@md.lv1 + if not dob.obj =~/~#|-#/ + ocn_flag=true + ocnh1+=1 #heading node1="1:#{ocnh1};#{ocn}" - document_structure_check_info(node1,node0) - @collapsed_lv1=1 - collapsed_level=@collapsed_lv1 - node,ocn_sp,parent=node1,"h#{ocnh}",node0 #FIX - elsif ln==2 \ - or ln=~@md.lv2; ocnh2+=1 + else + ocn_flag=false + node1="1:0;0" + end + document_structure_check_info(node1,node0) + @collapsed_lv1=1 + collapsed_level=@collapsed_lv1 + node,ocn_sp,parent=node1,"h#{ocnh}",node0 #FIX + elsif ln==2 \ + or ln=~@md.lv2 + if not dob.obj =~/~#|-#/ + ocn_flag=true + ocnh2+=1 node2="2:#{ocnh2};#{ocn}" - parent=if node1 - document_structure_check_info(node2,node1) - @collapsed_lv2=@collapsed_lv1+1 - node1 - else - document_structure_check_info(node2,node0,:error) - node0 - end - collapsed_level=@collapsed_lv2 - node,ocn_sp=node2,"h#{ocnh}" - elsif ln==3 \ - or ln=~@md.lv3; ocnh3+=1 + else + ocn_flag=false + node2="2:0;0" + end + parent=if node1 + document_structure_check_info(node2,node1) + @collapsed_lv2=@collapsed_lv1+1 + node1 + else + document_structure_check_info(node2,node0,:error) + node0 + end + collapsed_level=@collapsed_lv2 + node,ocn_sp=node2,"h#{ocnh}" + elsif ln==3 \ + or ln=~@md.lv3 + if not dob.obj =~/~#|-#/ + ocn_flag=true + ocnh3+=1 node3="3:#{ocnh3};#{ocn}" - parent=if node2 - document_structure_check_info(node3,node2) - @collapsed_lv3=@collapsed_lv2+1 - node2 - elsif node1 - warning_incorrect_parent_level_or_level(dob.obj) - puts %{parent is :A~ & this level #{dob.lv} + else + ocn_flag=false + node3="3:0;0" + end + parent=if node2 + document_structure_check_info(node3,node2) + @collapsed_lv3=@collapsed_lv2+1 + node2 + elsif node1 + warning_incorrect_parent_level_or_level(dob.obj) + puts %{parent is :A~ & this level #{dob.lv} either parent should be level :B~ or this level should be level :B~ rather than #{dob.lv}} - document_structure_check_info(node3,node1,:error) - @collapsed_lv3=@collapsed_lv1+1 - node1 - else - document_structure_check_info(node3,node0,:error) - warning_incorrect_parent_level_or_level(dob.obj) - node0 - end - collapsed_level=@collapsed_lv3 - node,ocn_sp=node3,"h#{ocnh}" - elsif ln==4 \ - or ln=~@md.lv4; ocnh4+=1 + document_structure_check_info(node3,node1,:error) + @collapsed_lv3=@collapsed_lv1+1 + node1 + else + document_structure_check_info(node3,node0,:error) + warning_incorrect_parent_level_or_level(dob.obj) + node0 + end + collapsed_level=@collapsed_lv3 + node,ocn_sp=node3,"h#{ocnh}" + elsif ln==4 \ + or ln=~@md.lv4 + if not dob.obj =~/~#|-#/ + ocn_flag=true + ocnh4+=1 node4="4:#{ocnh4};#{ocn}" - parent=if node3 - document_structure_check_info(node4,node3) - @collapsed_lv4=@collapsed_lv3+1 - node3 - elsif node2 - document_structure_check_info(node4,node2) - @collapsed_lv4=@collapsed_lv2+1 - node2 - elsif node1 - document_structure_check_info(node4,node1) - @collapsed_lv4=@collapsed_lv1+1 - node1 - else - warning_incorrect_parent_level_or_level(dob.obj) - document_structure_check_info(node4,node0,:error) - node0 - end - collapsed_level=@collapsed_lv4 - node,ocn_sp=node4,"h#{ocnh}" - elsif ln==5 \ - or ln=~@md.lv5; ocnh5+=1 + else + ocn_flag=false + node4="4:0;0" + end + parent=if node3 + document_structure_check_info(node4,node3) + @collapsed_lv4=@collapsed_lv3+1 + node3 + elsif node2 + document_structure_check_info(node4,node2) + @collapsed_lv4=@collapsed_lv2+1 + node2 + elsif node1 + document_structure_check_info(node4,node1) + @collapsed_lv4=@collapsed_lv1+1 + node1 + else + warning_incorrect_parent_level_or_level(dob.obj) + document_structure_check_info(node4,node0,:error) + node0 + end + collapsed_level=@collapsed_lv4 + node,ocn_sp=node4,"h#{ocnh}" + elsif ln==5 \ + or ln=~@md.lv5 + if not dob.obj =~/~#|-#/ + ocn_flag=true + ocnh5+=1 node5="5:#{ocnh5};#{ocn}" - parent=if node4 - document_structure_check_info(node5,node4) - @collapsed_lv5=@collapsed_lv4+1 - node4 - elsif node3 - warning_incorrect_parent_level_or_level(dob.obj) - document_structure_check_info(node5,node3,:error) - @collapsed_lv5=@collapsed_lv3+1 - node3 - elsif node2 - warning_incorrect_parent_level_or_level(dob.obj) - document_structure_check_info(node5,node2,:error) - @collapsed_lv5=@collapsed_lv2+1 - node2 - elsif node1 - warning_incorrect_parent_level_or_level(dob.obj) - document_structure_check_info(node5,node1,:error) - @collapsed_lv5=@collapsed_lv1+1 - node1 - else - document_structure_check_info(node5,node0,:error) - node0 - end - collapsed_level=@collapsed_lv5 - node,ocn_sp=node5,"h#{ocnh}" - elsif ln==6 \ - or ln=~@md.lv6; ocnh6+=1 + else + ocn_flag=false + node5="5:0;0" + end + parent=if node4 + document_structure_check_info(node5,node4) + @collapsed_lv5=@collapsed_lv4+1 + node4 + elsif node3 + warning_incorrect_parent_level_or_level(dob.obj) + document_structure_check_info(node5,node3,:error) + @collapsed_lv5=@collapsed_lv3+1 + node3 + elsif node2 + warning_incorrect_parent_level_or_level(dob.obj) + document_structure_check_info(node5,node2,:error) + @collapsed_lv5=@collapsed_lv2+1 + node2 + elsif node1 + warning_incorrect_parent_level_or_level(dob.obj) + document_structure_check_info(node5,node1,:error) + @collapsed_lv5=@collapsed_lv1+1 + node1 + else + document_structure_check_info(node5,node0,:error) + node0 + end + collapsed_level=@collapsed_lv5 + node,ocn_sp=node5,"h#{ocnh}" + elsif ln==6 \ + or ln=~@md.lv6 + if not dob.obj =~/~#|-#/ + ocn_flag=true + ocnh6+=1 node6="6:#{ocnh6};#{ocn}" - parent=if node5 - document_structure_check_info(node6,node5) - @collapsed_lv6=@collapsed_lv5+1 - node5 - elsif node4 - warning_incorrect_parent_level_or_level(dob.obj) - puts "parent is level 4~ & this level #{dob.lv} + else + ocn_flag=false + node6="6:0;0" + end + parent=if node5 + document_structure_check_info(node6,node5) + @collapsed_lv6=@collapsed_lv5+1 + node5 + elsif node4 + warning_incorrect_parent_level_or_level(dob.obj) + puts "parent is level 4~ & this level #{dob.lv} either parent should be level 5~ or this level should be 5~ rather #{dob.lv}" #level 6 - document_structure_check_info(node6,node4,:error) - @collapsed_lv6=@collapsed_lv4+1 - node4 - elsif node3 - warning_incorrect_parent_level_or_level(dob.obj) - document_structure_check_info(node6,node3,:error) - @collapsed_lv6=@collapsed_lv3+1 - node3 - elsif node2 - warning_incorrect_parent_level_or_level(dob.obj) - document_structure_check_info(node6,node2,:error) - @collapsed_lv6=@collapsed_lv2+1 - node2 - elsif node1 - warning_incorrect_parent_level_or_level(dob.obj) - document_structure_check_info(node6,node1,:error) - @collapsed_lv6=@collapsed_lv1+1 - node1 - else - document_structure_check_info(node6,node0,:error) - node0 - end - collapsed_level=@collapsed_lv6 - node,ocn_sp=node6,"h#{ocnh}" + document_structure_check_info(node6,node4,:error) + @collapsed_lv6=@collapsed_lv4+1 + node4 + elsif node3 + warning_incorrect_parent_level_or_level(dob.obj) + document_structure_check_info(node6,node3,:error) + @collapsed_lv6=@collapsed_lv3+1 + node3 + elsif node2 + warning_incorrect_parent_level_or_level(dob.obj) + document_structure_check_info(node6,node2,:error) + @collapsed_lv6=@collapsed_lv2+1 + node2 + elsif node1 + warning_incorrect_parent_level_or_level(dob.obj) + document_structure_check_info(node6,node1,:error) + @collapsed_lv6=@collapsed_lv1+1 + node1 + else + document_structure_check_info(node6,node0,:error) + node0 end + collapsed_level=@collapsed_lv6 + node,ocn_sp=node6,"h#{ocnh}" + end + else + if not dob.obj =~/~#|-#/ + ocn_flag=true else - ocno+=1 - if dob.is==:table - ocnt+=1 - ocn_sp,parent="t#{ocnt}",node - elsif dob.is==:code - ocnc+=1 - ocn_sp,parent="c#{ocnc}",node - elsif dob.is==:group \ - || dob.is==:block \ - || dob.is==:alt \ - || dob.is==:verse - ocng+=1 #group, poem - ocn_sp,parent="g#{ocng}",node - elsif dob.is==:image #check - ocni+=1 - ocn_sp,parent="i#{ocni}",node - else ocnp+=1 #paragraph - ocn_sp,parent="p#{ocnp}",node - end + ocn_flag=false end - if dob.is==:heading - dob.ln,dob.node,dob.ocn,dob.odv,dob.osp,dob.parent,dob.lc=ln,node,ocn,ocn_dv,ocn_sp,parent,collapsed_level + ocno+=1 + if dob.is==:table + ocnt+=1 + ocn_sp,parent="t#{ocnt}",node + elsif dob.is==:code + ocnc+=1 + ocn_sp,parent="c#{ocnc}",node + elsif dob.is==:group \ + || dob.is==:block \ + || dob.is==:alt \ + || dob.is==:verse + ocng+=1 #group, poem + ocn_sp,parent="g#{ocng}",node + elsif dob.is==:image #check + ocni+=1 + ocn_sp,parent="i#{ocni}",node + else ocnp+=1 #paragraph + ocn_sp,parent="p#{ocnp}",node + end + end + if dob.is==:heading + if ocn_flag==true + dob.ln,dob.node,dob.ocn,dob.ocn_,dob.odv,dob.osp,dob.parent,dob.lc=ln,node,ocn,ocn_flag,ocn_dv,ocn_sp,parent,collapsed_level else - if dob.of !=:meta \ - && dob.of !=:comment \ - && dob.of !=:layout - dob.ocn,dob.odv,dob.osp,dob.parent=ocn,ocn_dv,ocn_sp,parent + ocnu+=1 + dob.obj=dob.obj.gsub(/#{Mx[:fa_o]}[~-]##{Mx[:fa_c]}/,'') if dob.obj + ocn_dv,ocn_sp="u#{ocnu}","u#{ocnu}" + dob.ln,dob.node,dob.ocn,dob.ocn_,dob.odv,dob.osp,dob.parent,dob.lc=ln,node,nil,ocn_flag,ocn_dv,ocn_sp,parent,collapsed_level + end + else + if dob.of !=:meta \ + && dob.of !=:comment \ + && dob.of !=:layout + if ocn_flag == true + dob.ocn,dob.ocn_,dob.odv,dob.osp,dob.parent=ocn,ocn_flag,ocn_dv,ocn_sp,parent + else + ocnu+=1 + dob.obj=dob.obj.gsub(/#{Mx[:fa_o]}[~-]##{Mx[:fa_c]}/,'') if dob.obj + ocn_dv,ocn_sp="u#{ocnu}","u#{ocnu}" + dob.ocn,dob.ocn_,dob.odv,dob.osp,dob.parent=nil,ocn_flag,ocn_dv,ocn_sp,parent end end - else ocnu+=1 - dob.obj=dob.obj.gsub(/#{Mx[:fa_o]}~##{Mx[:fa_c]}/,'') if dob.obj - ocn_dv,ocn_sp="u#{ocnu}","u#{ocnu}" - dob.ocn,dob.odv,dob.osp=ocn,ocn_dv,ocn_sp end h elsif dob.obj=~/#{Mx[:pa_non_object_no_heading]}/ -- cgit v1.2.3 From e130be57eb46a8ff2e40445e1bb9fcc489737125 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Mon, 2 Dec 2013 23:11:05 -0500 Subject: v5: dal_endnotes, removed a space that should no longer be necessary * testing required --- lib/sisu/v5/dal_endnotes.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/sisu/v5/dal_endnotes.rb b/lib/sisu/v5/dal_endnotes.rb index 407dc1ff..839691da 100644 --- a/lib/sisu/v5/dal_endnotes.rb +++ b/lib/sisu/v5/dal_endnotes.rb @@ -82,7 +82,7 @@ module SiSU_DAL_Endnotes && dob.is !=:code case dob.obj # auto-numbered endnotes --> when /#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}[*+]\s+.+?#{Mx[:en_b_c]}/ - dob.obj=dob.obj.gsub(/\s*(#{Mx[:en_a_c]}|#{Mx[:en_b_c]})/,' \1') # required 2003w31 + dob.obj=dob.obj.gsub(/\s*(#{Mx[:en_a_c]}|#{Mx[:en_b_c]})/,'\1') word_mode=dob.obj.scan(/\S+/m) word_mode=endnote_call_number(word_mode) dob.obj=word_mode.join(' ') -- cgit v1.2.3 From 85ec6bab386b1e9b1ccbcab1fd97e6529b020032 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Mon, 2 Dec 2013 23:16:24 -0500 Subject: v5: minor code related to line-breaks --- lib/sisu/v5/manpage.rb | 22 +++++++++++---------- lib/sisu/v5/odf.rb | 21 +++++++++++--------- lib/sisu/v5/odf_format.rb | 32 +++++++++++++++++------------- lib/sisu/v5/plaintext.rb | 50 ++++++++++++++++++++++++----------------------- lib/sisu/v5/shared_txt.rb | 6 ++++-- 5 files changed, 72 insertions(+), 59 deletions(-) (limited to 'lib') diff --git a/lib/sisu/v5/manpage.rb b/lib/sisu/v5/manpage.rb index 3e430b55..44180819 100644 --- a/lib/sisu/v5/manpage.rb +++ b/lib/sisu/v5/manpage.rb @@ -120,7 +120,6 @@ module SiSU_Manpage @brace_url=SiSU_Viz::Defaults.new.url_decoration @vz=SiSU_Viz::Defaults.new @tab="\t" - @br="\n" @@notes=:end @manpage={ body: [], open: [], close: [], head: [], metadata: [], tail: [], endnotes: [] } end @@ -128,6 +127,9 @@ module SiSU_Manpage manpage=markup(@data) publish(manpage) end + def break_line + "\n" + end # Used for extraction of endnotes from paragraphs def extract_endnotes(dob='') para=dob.obj.gsub(/#{Mx[:br_line]}/,"\n") @@ -176,7 +178,7 @@ GSUB end def manpage_tail @manpage[:tail] <<< 78 @manpage[:body] << case lv - when 1; '.SH ' << wrapped.upcase << @br << @br - when 2..3; '.SH ' << wrapped.upcase << @br << @br - when 4; '.SH ' << wrapped.upcase << @br << @br - when 5..6; '.SH ' << wrapped.upcase << @br << @br + when 1; '.SH ' << wrapped.upcase << break_line << break_line + when 2..3; '.SH ' << wrapped.upcase << break_line << break_line + when 4; '.SH ' << wrapped.upcase << break_line << break_line + when 5..6; '.SH ' << wrapped.upcase << break_line << break_line end else @manpage[:body] << if wrapped =~/^\.BI\s/ # main text, contents, body KEEP - '.TP' << @br << wrapped.gsub(/(^\.B)I\s/,'\1 ') # sleight ... simpler output (check gsub!) + '.TP' << break_line << wrapped.gsub(/(^\.B)I\s/,'\1 ') # sleight ... simpler output (check gsub!) else - @br + '.BR' + @br << wrapped + break_line + '.BR' + break_line << wrapped end end if @@endnotes[:para] \ and @@notes==:foot #edit out to switch off endnotes following paragraph to which they belong - @@endnotes[:para].each { |e| @manpage[:body] << e << @br } + @@endnotes[:para].each { |e| @manpage[:body] << e << break_line } elsif @@endnotes[:para] \ and @@notes==:end end @@ -349,7 +351,7 @@ WOK manpage_structure(dob) else if dob.obj =~/#{table_message}/ - @manpage[:body] << dob.obj << @br + @manpage[:body] << dob.obj << break_line end end if (dob.obj =~// \ diff --git a/lib/sisu/v5/odf.rb b/lib/sisu/v5/odf.rb index 5e277992..2bc7de01 100644 --- a/lib/sisu/v5/odf.rb +++ b/lib/sisu/v5/odf.rb @@ -121,7 +121,6 @@ module SiSU_ODF @brace_url=SiSU_Viz::Defaults.new.url_decoration @br=(@md.opt.act[:maintenance][:set]==:on) \ ? '' : '' - #@br=(@md.opt.cmd =~/M/) ? "\n" : '' end def songsheet begin @@ -139,6 +138,10 @@ module SiSU_ODF end end end + def break_line + (@md.opt.act[:maintenance][:set]==:on) \ + ? "\n" : '' + end # Used for extraction of endnotes from paragraphs def extract_endnotes(dob='') notes=dob.obj.scan(/#{Mx[:en_a_o]}(\d+\s+.+?)#{Mx[:en_a_c]}/)[1] #FIX @@ -556,26 +559,26 @@ module SiSU_ODF end end if dob.is==:heading - @@odf[:body] << heading(dob,p_num).obj << @br*2 + @@odf[:body] << heading(dob,p_num).obj << break_line*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 + @@odf[:body] << poem(dob,p_num).obj << break_line*2 elsif dob.is==:group - @@odf[:body] << group(dob,p_num).obj << @br*2 + @@odf[:body] << group(dob,p_num).obj << break_line*2 elsif dob.is==:block - @@odf[:body] << block(dob,p_num).obj << @br*2 + @@odf[:body] << block(dob,p_num).obj << break_line*2 elsif dob.is==:code - @@odf[:body] << code(dob,p_num).obj << @br*2 + @@odf[:body] << code(dob,p_num).obj << break_line*2 elsif dob.is==:table #elsif dob.obj =~ /#{@p_num[:set_ref]}#{tag}#{@br}} + - %{#{@br}} + %{#{@p_num[:set_ref]}#{tag}#{break_line}} + + %{#{break_line}} end def table_close(tablefoot='') '' \ @@ -206,16 +210,16 @@ module SiSU_ODF_Format else 'P_table_cell' end str=str.gsub(/^~$/,'') # tilde / empty cell - %{#{@br}} + - %{#{@br}} + + %{#{break_line}} + + %{#{break_line}} + %{#{str}} + - %{#{@br}} + - %{#{@br}} + %{#{break_line}} + + %{#{break_line}} end def table_tag_row(str,i) - %{#{@br}} + + %{#{break_line}} + %{#{str}} + - %{#{@br}} + %{#{break_line}} end def table_tag_row_dump(str,i) txt_name_row=if i==0 \ @@ -223,13 +227,13 @@ module SiSU_ODF_Format 'Table_Heading' else 'P_table_cell' end - %{#{@br}} + - %{#{@br}} + - %{#{@br}} + + %{#{break_line}} + + %{#{break_line}} + + %{#{break_line}} + %{#{str}} + - %{#{@br}} + - %{#{@br}} + - %{#{@br}} + %{#{break_line}} + + %{#{break_line}} + + %{#{break_line}} end def table_row(row,i) row='' if row =~/^ @wrap_width @plaintext[:body] << case lv - when 1; wrapped.upcase << @br << decorate.heading_underscore.l1*times + p_num << @br*2 - when 2; wrapped.upcase << @br << decorate.heading_underscore.l2*times + p_num << @br*2 - when 3; wrapped.upcase << @br << decorate.heading_underscore.l3*times + p_num << @br*2 - when 4; wrapped.upcase << @br << decorate.heading_underscore.l4*times + p_num << @br*2 - when 5; wrapped.upcase << @br << decorate.heading_underscore.l5*times + p_num << @br*2 - when 6; wrapped.upcase << @br << decorate.heading_underscore.l6*times + p_num << @br*2 + when 1; wrapped.upcase << break_line << decorate.heading_underscore.l1*times + p_num << break_line*2 + when 2; wrapped.upcase << break_line << decorate.heading_underscore.l2*times + p_num << break_line*2 + when 3; wrapped.upcase << break_line << decorate.heading_underscore.l3*times + p_num << break_line*2 + when 4; wrapped.upcase << break_line << decorate.heading_underscore.l4*times + p_num << break_line*2 + when 5; wrapped.upcase << break_line << decorate.heading_underscore.l5*times + p_num << break_line*2 + when 6; wrapped.upcase << break_line << decorate.heading_underscore.l6*times + p_num << break_line*2 end else - @plaintext[:body] << wrapped + p_num << @br # main text, contents, body KEEP + @plaintext[:body] << wrapped + p_num << break_line # main text, contents, body KEEP end if @@endnotes[:para] \ and not @@endnotes_ - @@endnotes[:para].each {|e| @plaintext[:body] << e << @br} + @@endnotes[:para].each {|e| @plaintext[:body] << e << break_line} elsif @@endnotes[:para] \ and @@endnotes_ end @@ -403,7 +405,7 @@ WOK plaintext_metadata table_message='[table omitted, see other document formats]' data.each do |dob| - dob.obj=dob.obj.gsub(/#{Mx[:gr_o]}Th?#{Mx[:tc_p]}.+/um,"#{@br}#{table_message}"). #fix + dob.obj=dob.obj.gsub(/#{Mx[:gr_o]}Th?#{Mx[:tc_p]}.+/um,"#{break_line}#{table_message}"). #fix gsub(/.+?#{Mx[:gl_o]}-##{Mx[:gl_c]}/,''). # remove dummy headings (used by html) #check also [~-]# gsub(/#{Mx[:fa_bold_o]}(.+?)#{Mx[:fa_bold_c]}/, "#{decorate.bold.open}\\1#{decorate.bold.close}"). @@ -449,8 +451,8 @@ WOK end dob.obj=if dob.of==:block # watch dob.obj.gsub(/#{Mx[:gl_o]}●#{Mx[:gl_c]}/m,"* "). - gsub(/\n?#{Mx[:br_line]}\n?|\n?#{Mx[:br_nl]}\n?/m,@br) - else dob.obj.gsub(/\n?#{Mx[:br_line]}\n?|\n?#{Mx[:br_nl]}\n?/m,@br*2) + gsub(/\n?#{Mx[:br_line]}\n?|\n?#{Mx[:br_nl]}\n?/m,break_line) + else dob.obj.gsub(/\n?#{Mx[:br_line]}\n?|\n?#{Mx[:br_nl]}\n?/m,break_line*2) end if dob.is==:code dob.obj=dob.obj.gsub(/(^|[^}])_([<>])/m,'\1\2'). # _> _< @@ -479,17 +481,17 @@ WOK or dob.is==:verse \ or dob.is==:code \ or dob.is==:table - @plaintext[:body] << dob.obj + p_num << @br + @plaintext[:body] << dob.obj + p_num << break_line elsif dob.is==:break sp=' ' ln='-' @plaintext[:body] <<=if dob.obj==Mx[:br_page] \ or dob.obj==Mx[:br_page_new] \ or dob.obj==Mx[:br_page_line] - "#{@br}#{ln*40}#{@br*2}" + "#{break_line}#{ln*40}#{break_line*2}" elsif dob.obj ==Mx[:br_obj] - "#{@br}#{sp*20}* * *#{@br*2}" - end # following empty line (@br) missing, fix + "#{break_line}#{sp*20}* * *#{break_line*2}" + end # following empty line (break_line) missing, fix end dob='' if (dob.obj =~// \ and dob.obj =~/^(-\{{2}~\d+|)/) # -endnote @@ -508,9 +510,9 @@ WOK content << plaintext[:head] content << plaintext[:body] content << @@endnotes[:end] if @@endnotes_ - content << "#{@br}#{divider*@wrap_width}#{@br}" + content << "#{break_line}#{divider*@wrap_width}#{break_line}" content << plaintext[:metadata] - content << "#{@br}#{divider*@wrap_width}#{@br}" if @md.stmp =~/\w+/ #not used? + content << "#{break_line}#{divider*@wrap_width}#{break_line}" if @md.stmp =~/\w+/ #not used? content << plaintext[:tail] Output.new(content,@md).plaintext @@endnotes={ para: [], end: [] } diff --git a/lib/sisu/v5/shared_txt.rb b/lib/sisu/v5/shared_txt.rb index 8e8e7edb..0e3b6018 100644 --- a/lib/sisu/v5/shared_txt.rb +++ b/lib/sisu/v5/shared_txt.rb @@ -64,12 +64,14 @@ module SiSU_TextUtils def initialize(para='',n_char_max=76,n_indent=0,n_hang=nil) @para,@n_char_max,@n_indent=para,n_char_max,n_indent @n_char_max_extend = n_char_max - @br="\n" @n_hang=n_hang ? n_hang : @n_indent end + def break_line + "\n" + end def line_wrap space=' ' - spaces_indent,spaces_hang="#{@br}#{space*@n_indent}",space*@n_hang + spaces_indent,spaces_hang="#{break_line}#{space*@n_indent}",space*@n_hang line=0 out=[] out[line]='' -- cgit v1.2.3 From f0869d130a0f04abc8320f951da6cecafd08e052 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Mon, 2 Dec 2013 23:18:44 -0500 Subject: v5: xml sax rename file --- lib/sisu/v5/hub.rb | 2 +- lib/sisu/v5/xml.rb | 485 ------------------------------------------------- lib/sisu/v5/xml_sax.rb | 485 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 486 insertions(+), 486 deletions(-) delete mode 100644 lib/sisu/v5/xml.rb create mode 100644 lib/sisu/v5/xml_sax.rb (limited to 'lib') diff --git a/lib/sisu/v5/hub.rb b/lib/sisu/v5/hub.rb index 2e9092ff..256210df 100644 --- a/lib/sisu/v5/hub.rb +++ b/lib/sisu/v5/hub.rb @@ -340,7 +340,7 @@ module SiSU SiSU_XML_Scaffold_Structure_Collapse::Source.new(@opt).read end if @opt.act[:xml_sax][:set]==:on #% --xml-sax, -x xml sax type - require_relative 'xml' # xml.rb + require_relative 'xml_sax' # xml_sax.rb SiSU_XML_SAX::Source.new(@opt).read end if @opt.act[:xml_dom][:set]==:on #% --xml-dom, -X xml dom type diff --git a/lib/sisu/v5/xml.rb b/lib/sisu/v5/xml.rb deleted file mode 100644 index f9741ec1..00000000 --- a/lib/sisu/v5/xml.rb +++ /dev/null @@ -1,485 +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: xml output (sax style) processing - -=end -module SiSU_XML_SAX - require_relative 'defaults' # defaults.rb - include SiSU_Viz - require_relative 'particulars' # particulars.rb - include SiSU_Particulars - require_relative 'sysenv' # sysenv.rb - include SiSU_Env - require_relative 'shared_xml' # shared_xml.rb - include SiSU_XML_Munge - require_relative 'xml_format' # xml_format.rb - include SiSU_XML_Format - require_relative 'rexml' # rexml.rb - include SiSU_Rexml - require_relative 'shared_metadata' # shared_metadata.rb - @@alt_id_count,@@tablehead,@@number_of_cols=0,0,0 - @@tablefoot='' - class Source - def initialize(opt) - @opt=opt - @particulars=SiSU_Particulars::CombinedSingleton.instance.get_all(opt) - end - def read - begin - @env,@md,@dal_array=@particulars.env,@particulars.md,@particulars.dal_array - unless @opt.act[:quiet][:set]==:on - tool=if (@opt.act[:verbose_plus][:set]==:on \ - || @opt.act[:maintenance][:set]==:on) - "#{@env.program.web_browser} file://#{@md.file.output_path.xml_sax.dir}/#{@md.file.base_filename.xml_sax}\n\t#{@env.program.xml_viewer} file://#{@md.file.output_path.xml_sax.dir}/#{@md.file.base_filename.xml_sax}" - elsif @opt.act[:verbose][:set]==:on - "#{@env.program.web_browser} file://#{@md.file.output_path.xml_sax.dir}/#{@md.file.base_filename.xml_sax}" - else "[#{@opt.f_pth[:lng_is]}] #{@opt.fno}" - end - (@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],'XML SAX',tool).green_hi_blue - : SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'XML SAX',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.xml_sax.dir}/#{@md.file.base_filename.xml_sax}").flow - end - end - SiSU_XML_SAX::Source::Songsheet.new(@particulars).song - rescue - SiSU_Errors::Rescued.new($!,$@,@opt.cmd,@opt.fns).location do - __LINE__.to_s + ':' + __FILE__ - end - ensure - #file closed in songsheet - SiSU_Env::CreateSite.new(@opt.cmd).cp_css - end - end - private - class Songsheet - def initialize(particulars) - @env,@md,@dal_array,@particulars=particulars.env,particulars.md,particulars.dal_array,particulars - @file=SiSU_Env::FileOp.new(@md) - end - def song - begin - SiSU_XML_SAX::Source::Scroll.new(@particulars).songsheet - if (@md.opt.act[:verbose][:set]==:on \ - || @md.opt.act[:verbose_plus][:set]==:on \ - || @md.opt.act[:maintenance][:set]==:on) - SiSU_XML_SAX::Source::Tidy.new(@md,@file.place_file.xml_sax.dir).xml # test wellformedness, comment out when not in use - end - SiSU_Rexml::Rexml.new(@md,@file.place_file.xml_sax.dir).xml if @md.opt.act[:maintenance][:set]==:on # test rexml parsing, comment out when not in use #debug - rescue - SiSU_Errors::Rescued.new($!,$@,@md.opt.cmd,@md.fns).location do - __LINE__.to_s + ':' + __FILE__ - end - ensure - end - end - end - class Scroll - require_relative 'shared_txt' # shared_txt.rb - include SiSU_TextUtils - require_relative 'css' # css.rb - require_relative 'shared_xhtml' # decide use, whether xml rather than xhtml - @@xml={ body: [], open: [], close: [], head: [] } - def initialize(particulars) - @env,@md,@dal_array=particulars.env,particulars.md,particulars.dal_array - @vz=SiSU_Viz::Defaults.new - @trans=SiSU_XML_Munge::Trans.new(@md) - @sys=SiSU_Env::SystemCall.new - end - def songsheet - pre - @data=markup(@dal_array) - post - publish - end - protected - def embedded_endnotes(dob='') - dob.obj=dob.obj.gsub(/#{Mx[:en_a_o]}(\d+)\s+(.+?)#{Mx[:en_a_c]}/, - '\1\2 '). - gsub(/#{Mx[:en_b_o]}([*+]\d+)\s+(.+?)#{Mx[:en_b_c]}/, - '\1\2 '). - gsub(/#{Mx[:en_a_o]}([*+]+)\s+(.+?)#{Mx[:en_a_c]}/, - '\1\2 ') - end - def extract_endnotes(dob='') - notes=dob.obj.scan(/(?:#{Mx[:en_a_o]}|#{Mx[:en_b_o]})([\d*+]+\s+.+?)(?:#{Mx[:en_a_c]}|#{Mx[:en_b_c]})/) - notes.flatten.each do |e| - s=e.to_s - util=SiSU_TextUtils::Wrap.new(s,70) - wrap=util.line_wrap - wrap=wrap.gsub(/^(\d+)\s+(.+?)\s*\Z/m, < -#{Ax[:tab]*2}\\1 -#{Ax[:tab]*2} -#{Ax[:tab]*3}\\2 -#{Ax[:tab]*2} -#{Ax[:tab]*1} -WOK -). - gsub(/^([*+]\d+)\s+(.+?)\s*\Z/m, < -#{Ax[:tab]*2}\\1 -#{Ax[:tab]*2} -#{Ax[:tab]*3}\\2 -#{Ax[:tab]*2} -#{Ax[:tab]*1} -WOK -). - gsub(/^([*+]+)\s+(.+?)\s*\Z/m, < -#{Ax[:tab]*2}\\1 -#{Ax[:tab]*2} -#{Ax[:tab]*3}\\2 -#{Ax[:tab]*2} -#{Ax[:tab]*1} -WOK -) - @endnotes << wrap - end - end - def xml_head - metadata=SiSU_Metadata::Summary.new(@md).xml_sax.metadata - @@xml[:head] << metadata - end - def xml_sc(md='') - sc=if @md.sc_info - < - filename: - - #{@md.sc_filename} -
- version number: - - #{@md.sc_number} -
- version date: - - #{@md.sc_date} -
- -WOK - else '' - end - @@xml[:sc]=sc - end - def xml_structure(dob,type='norm') - if dob.is==:heading - lv=dob.ln - dob.ln + 2 - else lv=nil - end - extract_endnotes(dob) - dob.obj=dob.obj.gsub(/#{Mx[:en_a_o]}([\d*+]+)\s+(?:.+?)#{Mx[:en_a_c]}/,'\1'). #footnote/endnote clean - gsub(/#{Mx[:en_b_o]}([\d*+]+)\s+(?:.+?)#{Mx[:en_b_c]}/,'\1') #footnote/endnote clean - #if defined? dob.obj - #t_ograph="#{dob.obj}" - util=SiSU_TextUtils::Wrap.new(dob.obj,70) - wrapped=util.line_wrap - #end - @@xml[:body] << if defined? dob.ocn; %{#{Ax[:tab]*0}} - else "#{Ax[:tab]*0}" - end - @@xml[:body] << "#{Ax[:tab]*1}#{dob.ocn}" if defined? dob.ocn - @@xml[:body] << if lv; %{#{Ax[:tab]*1}\n#{Ax[:tab]*2}#{wrapped}\n#{Ax[:tab]*1}} - else %{#{Ax[:tab]*1}\n#{Ax[:tab]*2}#{wrapped}\n#{Ax[:tab]*1}} # main text, contents, body KEEP - end - @@xml[:body] << @endnotes if @endnotes - ##@@xml[:body] << "#{Ax[:tab]*1}#{dob[@regx,2]}" if dob[@regx,2] # old unwrapped main text, contents, body KEEP - @@xml[:body] << "#{Ax[:tab]*0}" - @endnotes=[] - end - def block_structure(dob='') - extract_endnotes(dob) - dob.obj=dob.obj.gsub(/#{Mx[:en_a_o]}([\d*+]+)\s+(?:.+?)#{Mx[:en_a_c]}/,'\1'). #footnote/endnote clean - gsub(/#{Mx[:en_b_o]}([\d*+]+)\s+(?:.+?)#{Mx[:en_b_c]}/,'\1') #footnote/endnote clean - dob=@trans.markup_block(dob) - dob.obj=dob.obj.strip - @@xml[:body] << %{#{Ax[:tab]*0}} - @@xml[:body] << %{#{Ax[:tab]*1}#{dob.ocn}} - @@xml[:body] << %{#{Ax[:tab]*1}#{Ax[:tab]*1}} - @@xml[:body] << %{#{Ax[:tab]*2}#{dob.obj}#{Ax[:tab]*1}} - @@xml[:body] << %{#{Ax[:tab]*1}} - @@xml[:body] << "#{Ax[:tab]*0}" - @@xml[:body] << @endnotes if @endnotes - @endnotes=[] - end - def group_structure(dob='') - extract_endnotes(dob) - dob.obj=dob.obj.gsub(/#{Mx[:en_a_o]}([\d*+]+)\s+(?:.+?)#{Mx[:en_a_c]}/,'\1'). #footnote/endnote clean - gsub(/#{Mx[:en_b_o]}([\d*+]+)\s+(?:.+?)#{Mx[:en_b_c]}/,'\1') #footnote/endnote clean - dob=@trans.markup_group(dob) - dob.obj=dob.obj.strip - @@xml[:body] << %{#{Ax[:tab]*0}} - @@xml[:body] << %{#{Ax[:tab]*1}#{dob.ocn}} - @@xml[:body] << %{#{Ax[:tab]*1}#{Ax[:tab]*1}} - @@xml[:body] << %{#{Ax[:tab]*2}#{dob.obj}#{Ax[:tab]*1}} - @@xml[:body] << %{#{Ax[:tab]*1}} - @@xml[:body] << "#{Ax[:tab]*0}" - @@xml[:body] << @endnotes if @endnotes - @endnotes=[] - end - def poem_structure(dob='') - dob=@trans.markup_group(dob) - #dob.obj.gsub(/\s\s/,'  ') - dob.obj=dob.obj.strip - @@xml[:body] << %{#{Ax[:tab]*0}} - @@xml[:body] << %{#{Ax[:tab]*1}#{dob.ocn}} - @@xml[:body] << %{#{Ax[:tab]*1}#{Ax[:tab]*1}} - @@xml[:body] << %{#{Ax[:tab]*2}#{dob.obj}#{Ax[:tab]*1}} - @@xml[:body] << %{#{Ax[:tab]*1}} - @@xml[:body] << "#{Ax[:tab]*0}" - end - def code_structure(dob='') - dob=@trans.markup_group(dob) - dob.obj=dob.obj.gsub(/\s\s/,'  ').strip - @@xml[:body] << %{#{Ax[:tab]*0}} - @@xml[:body] << %{#{Ax[:tab]*1}#{dob.ocn}} - @@xml[:body] << %{#{Ax[:tab]*1}#{Ax[:tab]*1}} - @@xml[:body] << %{#{Ax[:tab]*2}#{dob.obj}#{Ax[:tab]*1}} - @@xml[:body] << %{#{Ax[:tab]*1}} - @@xml[:body] << "#{Ax[:tab]*0}" - end - def table_structure(dob) - table=SiSU_XHTML_Shared::TableXHTML.new(dob) - @@xml[:body] << %{#{Ax[:tab]*0}} - @@xml[:body] << %{#{Ax[:tab]*1}#{dob.ocn}} - @@xml[:body] << %{#{Ax[:tab]*1}#{Ax[:tab]*1}} - @@xml[:body] << %{#{Ax[:tab]*2}#{table.table.obj}} - @@xml[:body] << %{#{Ax[:tab]*1}} - #@@xml[:body] << %{#{tab*1}} - @@xml[:body] << "#{Ax[:tab]*0}" - #@@xml[:body] << %{#{Ax[:tab]*0}} - #@@xml[:body] << %{#{Ax[:tab]*1}#{table}\n#{Ax[:tab]*1}} # unless lv # main text, contents, body KEEP - #@@xml[:body] << "#{Ax[:tab]*0}" - #@endnotes=[] - end - def markup(data) - xml_sc(@md) - @endnotes,@level,@cont,@copen,@xml_contents_close=[],[],[],[],[] - @rcdc=false - xml_head - (0..6).each { |x| @cont[x]=@level[x]=false } - (4..6).each { |x| @xml_contents_close[x]='' } - data.each do |dob| - @trans.char_enc.utf8(dob) if @sys.locale =~/utf-?8/i #% utf8 - dob=@trans.markup(dob) - if @rcdc==false \ - and (dob.is ==:meta \ - and dob.obj =~/Document Information/) - @rcdc=true - end - if dob.obj !~/(^#{Rx[:meta]}|#{Mx[:br_eof]}|#{Mx[:br_endnotes]})/ - if defined? dob.ocn #look to move to format section - ocn=((dob.ocn.to_s =~/\d+/) ? dob.ocn : nil) - @p_num=SiSU_XML_Format::ParagraphNumber.new(@md,ocn) - end - if not @rcdc - if defined? dob.ocn \ - and dob.ocn.to_s =~/\d+/ - x=SiSU_XML_Format::FormatSeg.new(@md,dob) - if dob.is==:heading - xml_structure(dob) - dob.obj=case dob.ln - when 1; x.heading_body1 - when 2; x.heading_body2 - when 3; x.heading_body3 - when 4; x.heading_body4 - when 5; x.heading_body5 - when 6; x.heading_body6 - end - else - if dob.is==:verse - poem_structure(dob) - elsif dob.is==:group - group_structure(dob) - elsif dob.is==:block - block_structure(dob) - elsif dob.is==:code - code_structure(dob) - elsif dob.is==:table # FIX, check css, will need to modify - table_structure(dob) - elsif dob.is ==:para \ - and dob.indent.to_s =~/[1-9]/ \ - and dob.bullet_==true - xml_structure(dob,"indent_bullet#{dob.indent}") - elsif dob.is ==:para \ - and dob.indent.to_s =~/[1-9]/ \ - and dob.indent == dob.hang - xml_structure(dob,"indent#{dob.indent}") - elsif dob.is ==:para \ - and dob.hang.to_s =~/[0-9]/ \ - and dob.indent != dob.hang - xml_structure(dob,"hang#{dob.hang.to_s}_indent#{dob.indent.to_s}") - else xml_structure(dob) - end - end - elsif dob.obj =~/(#{Mx[:br_eof]}|#{Mx[:br_endnotes]})/ - elsif dob.obj =~/MetaData/ - txt_obj={ txt: '
MetaData' } - format_scroll=FormatScroll.new(@md,txt_obj) - dob.obj=format_scroll.bold_para - elsif dob.obj =~/(Owner Details)/ -# txt_obj={ txt: '
Owner Details' } -# format_scroll=FormatScroll.new(@md,txt_obj) -# @@xml[:owner_details]=format_scroll.bold_para - dob.obj='' - end - if dob.obj =~// \ - and dob.obj =~/^(-\{{2}~\d+|)/ # -endnote - dob.obj='' - end - if dob.obj =~/.*<:#>.*$/ #investigate removal - dob.obj=if dob.obj =~ /#{Mx[:pa_o]}:i[1-9]#{Mx[:pa_c]}/ - txt_obj={ txt: dob } - format_text=FormatTextObject.new(@md,txt_obj) - format_text.scr_inden_ocn_e_no_paranum - end - end - else # - end - dob.obj=dob.obj.gsub(/#{Mx[:pa_o]}:\S+#{Mx[:pa_c]}/,'') if dob.obj - end - end - 6.downto(4) do |x| - y=x - 1; v=x - 3 - @@xml[:body] << "#{Ax[:tab]*5}\n#{Ax[:tab]*y}" if @level[x]==true - end - 3.downto(1) do |x| - y=x - 1 - @@xml[:body] << "#{Ax[:tab]*y}" if @level[x]==true - end - #6.downto(1) { |x| y=x - 1; @@xml[:body] << "#{Ax[:tab]*y}" if @level[x]==true } - end - def pre - rdf=SiSU_XML_Tags::RDF.new(@md) - @@xml[:head],@@xml[:body]=[],[] - stylesheet=SiSU_Style::CSS_HeadInfo.new(@md,'xml_sax').stylesheet - encoding=if @sys.locale =~/utf-?8/i; '' - else '' - end - @@xml[:open] =< -WOK - @@xml[:head] << '' - @@xml[:body] << '' - end - def post - @@xml[:head] << @@xml[:sc] - @@xml[:head] << '' - @@xml[:body] << '' - @@xml[:close] = '' - end - def publish - content=[] - content << @@xml[:open] << @@xml[:head] << @@xml[:body] << @@xml[:metadata] - content << @@xml[:owner_details] if @md.stmp =~/\w\w/ - content << @@xml[:tail] << @@xml[:close] - content=content.flatten.compact - Output.new(content,@md).xml - @@xml={} - end - end - class Output - def initialize(data,md) - @data,@md=data,md - @file=SiSU_Env::FileOp.new(@md) - end - def xml - SiSU_Env::FileOp.new(@md).mkdir - filename_xml=@file.write_file.xml_sax - @data.each do |str| - str=str.gsub(/\A\s+\Z/m,'') - filename_xml.puts str unless str.empty? - end - filename_xml.close - end - end - class Tidy - def initialize(md,file) - @md,@file=md,file - @prog=SiSU_Env::InfoProgram.new - end - def xml - if @prog.tidy !=false #note values can be other than true - if (@md.opt.act[:verbose_plus][:set]==:on \ - || @md.opt.act[:maintenance][:set]==:on) - unless @md.opt.act[:quiet][:set]==:on - SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set],'invert','Using XML Tidy','check document structure').colorize - tell=SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set],'invert','','') - tell.grey_open - end - tidyfile='/dev/null' #don't want one or screen output, check for alternative flags - tidy=SiSU_Env::SystemCall.new(@file,tidyfile) - tidy.well_formed? - tell.p_off unless @md.opt.act[:quiet][:set]==:on - end - end - end - end - end -end -__END__ diff --git a/lib/sisu/v5/xml_sax.rb b/lib/sisu/v5/xml_sax.rb new file mode 100644 index 00000000..f9741ec1 --- /dev/null +++ b/lib/sisu/v5/xml_sax.rb @@ -0,0 +1,485 @@ +# 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: xml output (sax style) processing + +=end +module SiSU_XML_SAX + require_relative 'defaults' # defaults.rb + include SiSU_Viz + require_relative 'particulars' # particulars.rb + include SiSU_Particulars + require_relative 'sysenv' # sysenv.rb + include SiSU_Env + require_relative 'shared_xml' # shared_xml.rb + include SiSU_XML_Munge + require_relative 'xml_format' # xml_format.rb + include SiSU_XML_Format + require_relative 'rexml' # rexml.rb + include SiSU_Rexml + require_relative 'shared_metadata' # shared_metadata.rb + @@alt_id_count,@@tablehead,@@number_of_cols=0,0,0 + @@tablefoot='' + class Source + def initialize(opt) + @opt=opt + @particulars=SiSU_Particulars::CombinedSingleton.instance.get_all(opt) + end + def read + begin + @env,@md,@dal_array=@particulars.env,@particulars.md,@particulars.dal_array + unless @opt.act[:quiet][:set]==:on + tool=if (@opt.act[:verbose_plus][:set]==:on \ + || @opt.act[:maintenance][:set]==:on) + "#{@env.program.web_browser} file://#{@md.file.output_path.xml_sax.dir}/#{@md.file.base_filename.xml_sax}\n\t#{@env.program.xml_viewer} file://#{@md.file.output_path.xml_sax.dir}/#{@md.file.base_filename.xml_sax}" + elsif @opt.act[:verbose][:set]==:on + "#{@env.program.web_browser} file://#{@md.file.output_path.xml_sax.dir}/#{@md.file.base_filename.xml_sax}" + else "[#{@opt.f_pth[:lng_is]}] #{@opt.fno}" + end + (@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],'XML SAX',tool).green_hi_blue + : SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'XML SAX',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.xml_sax.dir}/#{@md.file.base_filename.xml_sax}").flow + end + end + SiSU_XML_SAX::Source::Songsheet.new(@particulars).song + rescue + SiSU_Errors::Rescued.new($!,$@,@opt.cmd,@opt.fns).location do + __LINE__.to_s + ':' + __FILE__ + end + ensure + #file closed in songsheet + SiSU_Env::CreateSite.new(@opt.cmd).cp_css + end + end + private + class Songsheet + def initialize(particulars) + @env,@md,@dal_array,@particulars=particulars.env,particulars.md,particulars.dal_array,particulars + @file=SiSU_Env::FileOp.new(@md) + end + def song + begin + SiSU_XML_SAX::Source::Scroll.new(@particulars).songsheet + if (@md.opt.act[:verbose][:set]==:on \ + || @md.opt.act[:verbose_plus][:set]==:on \ + || @md.opt.act[:maintenance][:set]==:on) + SiSU_XML_SAX::Source::Tidy.new(@md,@file.place_file.xml_sax.dir).xml # test wellformedness, comment out when not in use + end + SiSU_Rexml::Rexml.new(@md,@file.place_file.xml_sax.dir).xml if @md.opt.act[:maintenance][:set]==:on # test rexml parsing, comment out when not in use #debug + rescue + SiSU_Errors::Rescued.new($!,$@,@md.opt.cmd,@md.fns).location do + __LINE__.to_s + ':' + __FILE__ + end + ensure + end + end + end + class Scroll + require_relative 'shared_txt' # shared_txt.rb + include SiSU_TextUtils + require_relative 'css' # css.rb + require_relative 'shared_xhtml' # decide use, whether xml rather than xhtml + @@xml={ body: [], open: [], close: [], head: [] } + def initialize(particulars) + @env,@md,@dal_array=particulars.env,particulars.md,particulars.dal_array + @vz=SiSU_Viz::Defaults.new + @trans=SiSU_XML_Munge::Trans.new(@md) + @sys=SiSU_Env::SystemCall.new + end + def songsheet + pre + @data=markup(@dal_array) + post + publish + end + protected + def embedded_endnotes(dob='') + dob.obj=dob.obj.gsub(/#{Mx[:en_a_o]}(\d+)\s+(.+?)#{Mx[:en_a_c]}/, + '\1\2 '). + gsub(/#{Mx[:en_b_o]}([*+]\d+)\s+(.+?)#{Mx[:en_b_c]}/, + '\1\2 '). + gsub(/#{Mx[:en_a_o]}([*+]+)\s+(.+?)#{Mx[:en_a_c]}/, + '\1\2 ') + end + def extract_endnotes(dob='') + notes=dob.obj.scan(/(?:#{Mx[:en_a_o]}|#{Mx[:en_b_o]})([\d*+]+\s+.+?)(?:#{Mx[:en_a_c]}|#{Mx[:en_b_c]})/) + notes.flatten.each do |e| + s=e.to_s + util=SiSU_TextUtils::Wrap.new(s,70) + wrap=util.line_wrap + wrap=wrap.gsub(/^(\d+)\s+(.+?)\s*\Z/m, < +#{Ax[:tab]*2}\\1 +#{Ax[:tab]*2} +#{Ax[:tab]*3}\\2 +#{Ax[:tab]*2} +#{Ax[:tab]*1} +WOK +). + gsub(/^([*+]\d+)\s+(.+?)\s*\Z/m, < +#{Ax[:tab]*2}\\1 +#{Ax[:tab]*2} +#{Ax[:tab]*3}\\2 +#{Ax[:tab]*2} +#{Ax[:tab]*1} +WOK +). + gsub(/^([*+]+)\s+(.+?)\s*\Z/m, < +#{Ax[:tab]*2}\\1 +#{Ax[:tab]*2} +#{Ax[:tab]*3}\\2 +#{Ax[:tab]*2} +#{Ax[:tab]*1} +WOK +) + @endnotes << wrap + end + end + def xml_head + metadata=SiSU_Metadata::Summary.new(@md).xml_sax.metadata + @@xml[:head] << metadata + end + def xml_sc(md='') + sc=if @md.sc_info + < + filename: + + #{@md.sc_filename} +
+ version number: + + #{@md.sc_number} +
+ version date: + + #{@md.sc_date} +
+ +WOK + else '' + end + @@xml[:sc]=sc + end + def xml_structure(dob,type='norm') + if dob.is==:heading + lv=dob.ln + dob.ln + 2 + else lv=nil + end + extract_endnotes(dob) + dob.obj=dob.obj.gsub(/#{Mx[:en_a_o]}([\d*+]+)\s+(?:.+?)#{Mx[:en_a_c]}/,'\1'). #footnote/endnote clean + gsub(/#{Mx[:en_b_o]}([\d*+]+)\s+(?:.+?)#{Mx[:en_b_c]}/,'\1') #footnote/endnote clean + #if defined? dob.obj + #t_ograph="#{dob.obj}" + util=SiSU_TextUtils::Wrap.new(dob.obj,70) + wrapped=util.line_wrap + #end + @@xml[:body] << if defined? dob.ocn; %{#{Ax[:tab]*0}} + else "#{Ax[:tab]*0}" + end + @@xml[:body] << "#{Ax[:tab]*1}#{dob.ocn}" if defined? dob.ocn + @@xml[:body] << if lv; %{#{Ax[:tab]*1}\n#{Ax[:tab]*2}#{wrapped}\n#{Ax[:tab]*1}} + else %{#{Ax[:tab]*1}\n#{Ax[:tab]*2}#{wrapped}\n#{Ax[:tab]*1}} # main text, contents, body KEEP + end + @@xml[:body] << @endnotes if @endnotes + ##@@xml[:body] << "#{Ax[:tab]*1}#{dob[@regx,2]}" if dob[@regx,2] # old unwrapped main text, contents, body KEEP + @@xml[:body] << "#{Ax[:tab]*0}" + @endnotes=[] + end + def block_structure(dob='') + extract_endnotes(dob) + dob.obj=dob.obj.gsub(/#{Mx[:en_a_o]}([\d*+]+)\s+(?:.+?)#{Mx[:en_a_c]}/,'\1'). #footnote/endnote clean + gsub(/#{Mx[:en_b_o]}([\d*+]+)\s+(?:.+?)#{Mx[:en_b_c]}/,'\1') #footnote/endnote clean + dob=@trans.markup_block(dob) + dob.obj=dob.obj.strip + @@xml[:body] << %{#{Ax[:tab]*0}} + @@xml[:body] << %{#{Ax[:tab]*1}#{dob.ocn}} + @@xml[:body] << %{#{Ax[:tab]*1}#{Ax[:tab]*1}} + @@xml[:body] << %{#{Ax[:tab]*2}#{dob.obj}#{Ax[:tab]*1}} + @@xml[:body] << %{#{Ax[:tab]*1}} + @@xml[:body] << "#{Ax[:tab]*0}" + @@xml[:body] << @endnotes if @endnotes + @endnotes=[] + end + def group_structure(dob='') + extract_endnotes(dob) + dob.obj=dob.obj.gsub(/#{Mx[:en_a_o]}([\d*+]+)\s+(?:.+?)#{Mx[:en_a_c]}/,'\1'). #footnote/endnote clean + gsub(/#{Mx[:en_b_o]}([\d*+]+)\s+(?:.+?)#{Mx[:en_b_c]}/,'\1') #footnote/endnote clean + dob=@trans.markup_group(dob) + dob.obj=dob.obj.strip + @@xml[:body] << %{#{Ax[:tab]*0}} + @@xml[:body] << %{#{Ax[:tab]*1}#{dob.ocn}} + @@xml[:body] << %{#{Ax[:tab]*1}#{Ax[:tab]*1}} + @@xml[:body] << %{#{Ax[:tab]*2}#{dob.obj}#{Ax[:tab]*1}} + @@xml[:body] << %{#{Ax[:tab]*1}} + @@xml[:body] << "#{Ax[:tab]*0}" + @@xml[:body] << @endnotes if @endnotes + @endnotes=[] + end + def poem_structure(dob='') + dob=@trans.markup_group(dob) + #dob.obj.gsub(/\s\s/,'  ') + dob.obj=dob.obj.strip + @@xml[:body] << %{#{Ax[:tab]*0}} + @@xml[:body] << %{#{Ax[:tab]*1}#{dob.ocn}} + @@xml[:body] << %{#{Ax[:tab]*1}#{Ax[:tab]*1}} + @@xml[:body] << %{#{Ax[:tab]*2}#{dob.obj}#{Ax[:tab]*1}} + @@xml[:body] << %{#{Ax[:tab]*1}} + @@xml[:body] << "#{Ax[:tab]*0}" + end + def code_structure(dob='') + dob=@trans.markup_group(dob) + dob.obj=dob.obj.gsub(/\s\s/,'  ').strip + @@xml[:body] << %{#{Ax[:tab]*0}} + @@xml[:body] << %{#{Ax[:tab]*1}#{dob.ocn}} + @@xml[:body] << %{#{Ax[:tab]*1}#{Ax[:tab]*1}} + @@xml[:body] << %{#{Ax[:tab]*2}#{dob.obj}#{Ax[:tab]*1}} + @@xml[:body] << %{#{Ax[:tab]*1}} + @@xml[:body] << "#{Ax[:tab]*0}" + end + def table_structure(dob) + table=SiSU_XHTML_Shared::TableXHTML.new(dob) + @@xml[:body] << %{#{Ax[:tab]*0}} + @@xml[:body] << %{#{Ax[:tab]*1}#{dob.ocn}} + @@xml[:body] << %{#{Ax[:tab]*1}#{Ax[:tab]*1}} + @@xml[:body] << %{#{Ax[:tab]*2}#{table.table.obj}} + @@xml[:body] << %{#{Ax[:tab]*1}} + #@@xml[:body] << %{#{tab*1}} + @@xml[:body] << "#{Ax[:tab]*0}" + #@@xml[:body] << %{#{Ax[:tab]*0}} + #@@xml[:body] << %{#{Ax[:tab]*1}#{table}\n#{Ax[:tab]*1}} # unless lv # main text, contents, body KEEP + #@@xml[:body] << "#{Ax[:tab]*0}" + #@endnotes=[] + end + def markup(data) + xml_sc(@md) + @endnotes,@level,@cont,@copen,@xml_contents_close=[],[],[],[],[] + @rcdc=false + xml_head + (0..6).each { |x| @cont[x]=@level[x]=false } + (4..6).each { |x| @xml_contents_close[x]='' } + data.each do |dob| + @trans.char_enc.utf8(dob) if @sys.locale =~/utf-?8/i #% utf8 + dob=@trans.markup(dob) + if @rcdc==false \ + and (dob.is ==:meta \ + and dob.obj =~/Document Information/) + @rcdc=true + end + if dob.obj !~/(^#{Rx[:meta]}|#{Mx[:br_eof]}|#{Mx[:br_endnotes]})/ + if defined? dob.ocn #look to move to format section + ocn=((dob.ocn.to_s =~/\d+/) ? dob.ocn : nil) + @p_num=SiSU_XML_Format::ParagraphNumber.new(@md,ocn) + end + if not @rcdc + if defined? dob.ocn \ + and dob.ocn.to_s =~/\d+/ + x=SiSU_XML_Format::FormatSeg.new(@md,dob) + if dob.is==:heading + xml_structure(dob) + dob.obj=case dob.ln + when 1; x.heading_body1 + when 2; x.heading_body2 + when 3; x.heading_body3 + when 4; x.heading_body4 + when 5; x.heading_body5 + when 6; x.heading_body6 + end + else + if dob.is==:verse + poem_structure(dob) + elsif dob.is==:group + group_structure(dob) + elsif dob.is==:block + block_structure(dob) + elsif dob.is==:code + code_structure(dob) + elsif dob.is==:table # FIX, check css, will need to modify + table_structure(dob) + elsif dob.is ==:para \ + and dob.indent.to_s =~/[1-9]/ \ + and dob.bullet_==true + xml_structure(dob,"indent_bullet#{dob.indent}") + elsif dob.is ==:para \ + and dob.indent.to_s =~/[1-9]/ \ + and dob.indent == dob.hang + xml_structure(dob,"indent#{dob.indent}") + elsif dob.is ==:para \ + and dob.hang.to_s =~/[0-9]/ \ + and dob.indent != dob.hang + xml_structure(dob,"hang#{dob.hang.to_s}_indent#{dob.indent.to_s}") + else xml_structure(dob) + end + end + elsif dob.obj =~/(#{Mx[:br_eof]}|#{Mx[:br_endnotes]})/ + elsif dob.obj =~/MetaData/ + txt_obj={ txt: '
MetaData' } + format_scroll=FormatScroll.new(@md,txt_obj) + dob.obj=format_scroll.bold_para + elsif dob.obj =~/(Owner Details)/ +# txt_obj={ txt: '
Owner Details' } +# format_scroll=FormatScroll.new(@md,txt_obj) +# @@xml[:owner_details]=format_scroll.bold_para + dob.obj='' + end + if dob.obj =~// \ + and dob.obj =~/^(-\{{2}~\d+|)/ # -endnote + dob.obj='' + end + if dob.obj =~/.*<:#>.*$/ #investigate removal + dob.obj=if dob.obj =~ /#{Mx[:pa_o]}:i[1-9]#{Mx[:pa_c]}/ + txt_obj={ txt: dob } + format_text=FormatTextObject.new(@md,txt_obj) + format_text.scr_inden_ocn_e_no_paranum + end + end + else # + end + dob.obj=dob.obj.gsub(/#{Mx[:pa_o]}:\S+#{Mx[:pa_c]}/,'') if dob.obj + end + end + 6.downto(4) do |x| + y=x - 1; v=x - 3 + @@xml[:body] << "#{Ax[:tab]*5}\n#{Ax[:tab]*y}" if @level[x]==true + end + 3.downto(1) do |x| + y=x - 1 + @@xml[:body] << "#{Ax[:tab]*y}" if @level[x]==true + end + #6.downto(1) { |x| y=x - 1; @@xml[:body] << "#{Ax[:tab]*y}" if @level[x]==true } + end + def pre + rdf=SiSU_XML_Tags::RDF.new(@md) + @@xml[:head],@@xml[:body]=[],[] + stylesheet=SiSU_Style::CSS_HeadInfo.new(@md,'xml_sax').stylesheet + encoding=if @sys.locale =~/utf-?8/i; '' + else '' + end + @@xml[:open] =< +WOK + @@xml[:head] << '' + @@xml[:body] << '' + end + def post + @@xml[:head] << @@xml[:sc] + @@xml[:head] << '' + @@xml[:body] << '' + @@xml[:close] = '' + end + def publish + content=[] + content << @@xml[:open] << @@xml[:head] << @@xml[:body] << @@xml[:metadata] + content << @@xml[:owner_details] if @md.stmp =~/\w\w/ + content << @@xml[:tail] << @@xml[:close] + content=content.flatten.compact + Output.new(content,@md).xml + @@xml={} + end + end + class Output + def initialize(data,md) + @data,@md=data,md + @file=SiSU_Env::FileOp.new(@md) + end + def xml + SiSU_Env::FileOp.new(@md).mkdir + filename_xml=@file.write_file.xml_sax + @data.each do |str| + str=str.gsub(/\A\s+\Z/m,'') + filename_xml.puts str unless str.empty? + end + filename_xml.close + end + end + class Tidy + def initialize(md,file) + @md,@file=md,file + @prog=SiSU_Env::InfoProgram.new + end + def xml + if @prog.tidy !=false #note values can be other than true + if (@md.opt.act[:verbose_plus][:set]==:on \ + || @md.opt.act[:maintenance][:set]==:on) + unless @md.opt.act[:quiet][:set]==:on + SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set],'invert','Using XML Tidy','check document structure').colorize + tell=SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set],'invert','','') + tell.grey_open + end + tidyfile='/dev/null' #don't want one or screen output, check for alternative flags + tidy=SiSU_Env::SystemCall.new(@file,tidyfile) + tidy.well_formed? + tell.p_off unless @md.opt.act[:quiet][:set]==:on + end + end + end + end + end +end +__END__ -- cgit v1.2.3 From 6e2061aa6dfe53a930825ab0d6b7f6194d0c04e6 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Mon, 2 Dec 2013 23:24:39 -0500 Subject: v5: xmlns xlink using xl --- lib/sisu/v5/epub.rb | 4 ++-- lib/sisu/v5/odf.rb | 44 ++++++++++++++++++------------------- lib/sisu/v5/odf_format.rb | 6 ++--- lib/sisu/v5/relaxng.rb | 50 +++++++++++++++++++++--------------------- lib/sisu/v5/shared_metadata.rb | 10 ++++----- lib/sisu/v5/shared_xml.rb | 24 ++++++++++---------- 6 files changed, 69 insertions(+), 69 deletions(-) (limited to 'lib') diff --git a/lib/sisu/v5/epub.rb b/lib/sisu/v5/epub.rb index 37ab535b..969debe2 100644 --- a/lib/sisu/v5/epub.rb +++ b/lib/sisu/v5/epub.rb @@ -728,8 +728,8 @@ module SiSU_EPUB
- - + +
diff --git a/lib/sisu/v5/odf.rb b/lib/sisu/v5/odf.rb index 2bc7de01..3e83e1cf 100644 --- a/lib/sisu/v5/odf.rb +++ b/lib/sisu/v5/odf.rb @@ -176,8 +176,8 @@ module SiSU_ODF end def odf_tail 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] << %{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) @@ -266,7 +266,7 @@ module SiSU_ODF and h.to_s =~/\d/ \ and w.to_s =~/\d/ @@img_count +=1 - %{#{c}} #anchor-type: as-char or paragraph or char or ... + %{#{c}} #anchor-type: as-char or paragraph or char or ... else %{[image omitted]} end end @@ -296,13 +296,13 @@ module SiSU_ODF map_nametags=SiSU_Particulars::CombinedSingleton.instance.get_map_nametags(@md).nametags_map t=case url when /^https?:/ - %{#{txt.strip}#{trail}} + %{#{txt.strip}#{trail}} when /^:/ # site same document collection html link url=url.gsub(/^:/,"#{@env.url.root}/") - %{#{txt.strip}#{trail}} + %{#{txt.strip}#{trail}} when /^\.\.\// # site same document collection html link url=url.gsub(/^\.\.\//,"#{@env.url.root}/") - %{#{txt.strip}#{trail}} + %{#{txt.strip}#{trail}} else # document internal link if map_nametags[url] \ and map_nametags[url][:segname] @@ -310,7 +310,7 @@ module SiSU_ODF end t=map_nametags[url] \ && map_nametags[url][:segname] \ - ? %{#{txt.strip}#{trail}} + ? %{#{txt.strip}#{trail}} : %{#{txt.strip}#{trail}} end t @@ -365,11 +365,11 @@ module SiSU_ODF 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 + '\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}}). + %{#{@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 + %{#{@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 @@ -386,7 +386,7 @@ module SiSU_ODF end def footnote_urls(str) str=str.gsub(/#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/, - %{#{@brace_url.xml_open}\\1#{@brace_url.xml_close}}) + %{#{@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 @@ -455,15 +455,15 @@ module SiSU_ODF 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 + '\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}}). + %{#{@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 + %{#{@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,''). + 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>'). @@ -479,15 +479,15 @@ module SiSU_ODF 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 + '\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}}). + %{#{@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 + %{#{@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,''). + 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>'). @@ -509,7 +509,7 @@ module SiSU_ODF parablock=group_clean(parablock) parablock=parablock.gsub(/^\s*$/,'
'). gsub(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/, - '\1') #http ftp matches escaped, no decoration + '\1') #http ftp matches escaped, no decoration parray << %{#{set_ref}#{parablock}} if parablock =~/\S+/ end dob.obj=parray.join \ @@ -642,7 +642,7 @@ module SiSU_ODF gsub(/#{Mx[:mk_o]}[~-]##{Mx[:mk_c]}/,'') if dob.is==:para \ and dob.bullet_ - dob.obj=' ' + + dob.obj=' ' + dob.obj end dob.obj=dob.obj.gsub(/#{Mx[:br_line]}/,'
'). @@ -731,7 +731,7 @@ WOK end x=< - + #{table} diff --git a/lib/sisu/v5/odf_format.rb b/lib/sisu/v5/odf_format.rb index 3d40f943..587c9fd0 100644 --- a/lib/sisu/v5/odf_format.rb +++ b/lib/sisu/v5/odf_format.rb @@ -322,7 +322,7 @@ WOK def meta_xml x=< - + #{@generator} #{@md.generated} @@ -338,7 +338,7 @@ WOK def settings_xml x=< - + 0 @@ -441,7 +441,7 @@ WOK def styles_xml x=< - + diff --git a/lib/sisu/v5/relaxng.rb b/lib/sisu/v5/relaxng.rb index 39d6bde9..f6426f54 100644 --- a/lib/sisu/v5/relaxng.rb +++ b/lib/sisu/v5/relaxng.rb @@ -500,7 +500,7 @@ RELAXNG @relaxng =<\1
'). #http ftp matches escaped, no decoration + '\1'). #http ftp matches escaped, no decoration gsub(/(#{Mx[:lnk_c]})#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/, - '\1\2') #special case \{ e.g. \}http://url + '\1\2') #special case \{ e.g. \}http://url @inf=if @inf =~/#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/ @inf.gsub(/#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/, - %{#{url_brace.xml_open}\\1#{url_brace.xml_close}}) #http ftp matches with decoration + %{#{url_brace.xml_open}\\1#{url_brace.xml_close}}) #http ftp matches with decoration else @inf.gsub(/(https?:\/\/[^<>()'"\s]+)/, - %{#{url_brace.xml_open}\\1#{url_brace.xml_close}}) #http ftp matches with decoration + %{#{url_brace.xml_open}\\1#{url_brace.xml_close}}) #http ftp matches with decoration end @inf=@inf.gsub(/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+)/, - %{#{url_brace.xml_open}\\1#{url_brace.xml_close}}) if @inf !~/http:\/\// # improve upon, document crash where url contains '@' symbol + %{#{url_brace.xml_open}\\1#{url_brace.xml_close}}) if @inf !~/http:\/\// # improve upon, document crash where url contains '@' symbol end <#{@tag.capitalize}: #{@inf} diff --git a/lib/sisu/v5/shared_xml.rb b/lib/sisu/v5/shared_xml.rb index af9b0992..76b5374b 100644 --- a/lib/sisu/v5/shared_xml.rb +++ b/lib/sisu/v5/shared_xml.rb @@ -381,25 +381,25 @@ module SiSU_XML_Munge gsub(/<[-~]#>/,''). gsub(/href="#{Xx[:segment]}/m,'href="'). gsub(/#{Mx[:lnk_o]}([^#{Mx[:lnk_o]}#{Mx[:lnk_c]}#{Mx[:rel_o]}#{Mx[:rel_c]}]+?)#{Mx[:lnk_c]}#{Mx[:rel_o]}(\.\.\/\S+?)#{Mx[:rel_c]}/, - '\1'). + '\1'). gsub(/#{Mx[:lnk_o]}([^#{Mx[:lnk_o]}#{Mx[:lnk_c]}#{Mx[:rel_o]}#{Mx[:rel_c]}]+?)#{Mx[:lnk_c]}#{Mx[:rel_o]}:(\S+?)#{Mx[:rel_c]}/, - '\1'). + '\1'). gsub(/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:rel_o]}(\S+?)#{Mx[:rel_c]}/, - '\1'). + '\1'). gsub(/(?:^|[^_\\])#{Mx[:lnk_o]}[ ]*(\S+?\.(?:jpg|png|gif))[ ]+(\d+)x(\d+)(\s+[^}]+)?#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/, - %{[\\1] \\4}). + %{[\\1] \\4}). gsub(/(?:^|[^_\\])#{Mx[:lnk_o]}[ ]*(\S+?\.(?:jpg|png|gif))([ ]+[^}]+)?#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/, - %{\\1}). + %{\\1}). gsub(/(?:^|[^_\\])#{Mx[:lnk_o]}[ ]*(\S+?\.(?:jpg|png|gif))[ ]+(\d+)x(\d+)(\s+[^}]+)?#{Mx[:lnk_c]}image/, - %{[\\1] \\4}). + %{[\\1] \\4}). gsub(/(?:^|[^_\\])#{Mx[:lnk_o]}[ ]*(\S+?\.(?:jpg|png|gif))([ ]+[^}]+)?#{Mx[:lnk_c]}image/, - %{\\1}). + %{\\1}). gsub(/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/, - '\1'). #watch, compare html_tune + '\1'). #watch, compare html_tune gsub(/#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/, - %{#{@brace_url.xml_open}\\1#{@brace_url.xml_close}}). + %{#{@brace_url.xml_open}\\1#{@brace_url.xml_close}}). gsub(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/, - '\1') #escaped urls not linked, deal with later + '\1') #escaped urls not linked, deal with later else dob.obj=dob.obj.gsub(//m,'>') end @@ -455,7 +455,7 @@ module SiSU_XML_Munge def markup_group(dob='') dob.obj=dob.obj.gsub(//,'>'). gsub(/<:?br(?:\s+\/)?>/,'
'). - gsub(/<(link xmlns:xlink=".+?")>/,'<\1>'). + gsub(/<(link xmlns:xl=".+?")>/,'<\1>'). gsub(/<(\/link)>/,'<\1>'). gsub(/<(\/?en)>/,'<\1>') dob @@ -463,7 +463,7 @@ module SiSU_XML_Munge def markup_block(dob='') dob.obj=dob.obj.gsub(//,'>'). gsub(/<:?br(?:\s+\/)?>/,'
'). - gsub(/<(link xmlns:xlink=".+?")>/,'<\1>'). + gsub(/<(link xmlns:xl=".+?")>/,'<\1>'). gsub(/<(\/link)>/,'<\1>'). gsub(/<(\/?en)>/,'<\1>') dob -- cgit v1.2.3 From da5e7ffe9b6b76f965d3ec01b4bef0c99b7f1955 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Mon, 2 Dec 2013 23:30:51 -0500 Subject: v4 v5: rake create build & install sisu gemspec; bin/sisugem (add .gitignore) * rake gemcbi #(create build install sisu gem) * rake gemspecscreate && \ rake gembuild && \ sudo rake geminstall * rake gemspecscreate && \ gem build sisu5.gemspec && \ sudo gem install --no-rdoc --no-ri \ sisu-5.1.0.gem * bin/sisu updated (modified to take account of gems) * bin/sisugem added * .gitignore sisu-*.gem sisu*.gemspec consider inclusion (& tracking) of rake created sisu4.gemspec sisu5.gemspec (as this makes their availability more obvious) * once gem is installed: "sisu _5.1.0_ -vM" (to see version, commands otherwise as usual) if paths are such that sisu is not available "sisugem _5.1.0_ -vM" should work (as it is installed by gemspec, but not other sisu installers) --- lib/sisu/v4/hub.rb | 4 +++- lib/sisu/v4/screen_text_color.rb | 3 +++ lib/sisu/v5/hub.rb | 5 +++++ lib/sisu/v5/screen_text_color.rb | 3 +++ 4 files changed, 14 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/sisu/v4/hub.rb b/lib/sisu/v4/hub.rb index ebe9ccf4..5965994f 100644 --- a/lib/sisu/v4/hub.rb +++ b/lib/sisu/v4/hub.rb @@ -388,7 +388,6 @@ module SiSU SiSU_Source::SiSUpodSource.new(@opt).read end if @opt.act[:share_source][:set]==:on -#REDO require_relative 'share_src' # -s share_src.rb begin ensure @@ -516,6 +515,9 @@ module SiSU SiSU_Env::InfoProcessingFlag.new if @opt.act[:version_info][:set]==:on #% version information SiSU_Env::InfoAbout.new(@opt).sisu_version + if @opt.cmd =~/[vVM]/ + SiSU_Screen::Ansi.new(@opt.cmd,' ' + File.dirname(__FILE__)).grey + end end if @opt.act[:dal][:set]==:on \ or @opt.act[:maintenance][:set]==:on #% --maintenance, -m for -C diff --git a/lib/sisu/v4/screen_text_color.rb b/lib/sisu/v4/screen_text_color.rb index ea9ae24d..5e395133 100644 --- a/lib/sisu/v4/screen_text_color.rb +++ b/lib/sisu/v4/screen_text_color.rb @@ -253,6 +253,9 @@ module SiSU_Screen %{#{@cX.off} } + %{#{@cX.cyan}nav only: #{@txt[4]}#{@cX.off}.} end + def grey + puts "#{@cX.grey}#{@txt[0]}#{@cX.off} #{@cX.cyan}#{@txt[1]}#{@cX.off}" + end def txt_white puts "\t#{@cX.white}#{@txt[0]}#{@cX.off} #{@cX.white}#{@txt[1]}#{@cX.off}" end diff --git a/lib/sisu/v5/hub.rb b/lib/sisu/v5/hub.rb index 256210df..c158f214 100644 --- a/lib/sisu/v5/hub.rb +++ b/lib/sisu/v5/hub.rb @@ -523,6 +523,11 @@ module SiSU SiSU_Env::InfoProcessingFlag.new if @opt.act[:version_info][:set]==:on #% version information SiSU_Env::InfoAbout.new(@opt).sisu_version + if (@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],' ' + File.dirname(__FILE__)).grey + end end if @opt.act[:dal][:set]==:on \ or @opt.act[:maintenance][:set]==:on #% --maintenance, -m for -C diff --git a/lib/sisu/v5/screen_text_color.rb b/lib/sisu/v5/screen_text_color.rb index 4e4a319f..1d9de72c 100644 --- a/lib/sisu/v5/screen_text_color.rb +++ b/lib/sisu/v5/screen_text_color.rb @@ -244,6 +244,9 @@ module SiSU_Screen %{#{@cX.off} } + %{#{@cX.cyan}nav only: #{@txt[4]}#{@cX.off}.} end + def grey + puts "#{@cX.grey}#{@txt[0]}#{@cX.off} #{@cX.cyan}#{@txt[1]}#{@cX.off}" + end def txt_white puts "\t#{@cX.white}#{@txt[0]}#{@cX.off} #{@cX.white}#{@txt[1]}#{@cX.off}" end -- cgit v1.2.3 From 9b51aed57ab048b76cf322c8c56e6b83d68f50d0 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Mon, 2 Dec 2013 23:43:22 -0500 Subject: v5: renaming files & modules ao & AO (from dal & DAL) * ao (abstract objects) shorter, also easily searched, higher sort location abstract as representation of & extraction of document objects (dal (document abstraction layer)) --- lib/sisu/v5/ao.rb | 537 +++++++++ lib/sisu/v5/ao_character_check.rb | 107 ++ lib/sisu/v5/ao_doc_objects.rb | 481 ++++++++ lib/sisu/v5/ao_doc_str.rb | 1427 +++++++++++++++++++++++ lib/sisu/v5/ao_endnotes.rb | 128 ++ lib/sisu/v5/ao_expand_insertions.rb | 450 +++++++ lib/sisu/v5/ao_hash_digest.rb | 157 +++ lib/sisu/v5/ao_idx.rb | 326 ++++++ lib/sisu/v5/ao_images.rb | 165 +++ lib/sisu/v5/ao_metadata.rb | 82 ++ lib/sisu/v5/ao_misc_arrange.rb | 157 +++ lib/sisu/v5/ao_numbering.rb | 486 ++++++++ lib/sisu/v5/ao_syntax.rb | 631 ++++++++++ lib/sisu/v5/dal.rb | 537 --------- lib/sisu/v5/dal_character_check.rb | 107 -- lib/sisu/v5/dal_doc_objects.rb | 481 -------- lib/sisu/v5/dal_doc_str.rb | 1427 ----------------------- lib/sisu/v5/dal_endnotes.rb | 128 -- lib/sisu/v5/dal_expand_insertions.rb | 450 ------- lib/sisu/v5/dal_hash_digest.rb | 157 --- lib/sisu/v5/dal_idx.rb | 326 ------ lib/sisu/v5/dal_images.rb | 165 --- lib/sisu/v5/dal_metadata.rb | 82 -- lib/sisu/v5/dal_misc_arrange.rb | 157 --- lib/sisu/v5/dal_numbering.rb | 486 -------- lib/sisu/v5/dal_syntax.rb | 631 ---------- lib/sisu/v5/db_import.rb | 4 +- lib/sisu/v5/git.rb | 6 +- lib/sisu/v5/html_format.rb | 2 +- lib/sisu/v5/hub.rb | 4 +- lib/sisu/v5/manpage.rb | 4 +- lib/sisu/v5/odf.rb | 2 +- lib/sisu/v5/particulars.rb | 16 +- lib/sisu/v5/plaintext.rb | 4 +- lib/sisu/v5/po4a.rb | 10 +- lib/sisu/v5/sst_do_inline_footnotes.rb | 4 +- lib/sisu/v5/sst_to_s_xml_sax.rb | 4 +- lib/sisu/v5/sysenv.rb | 4 +- lib/sisu/v5/texpdf.rb | 8 +- lib/sisu/v5/wikispeak.rb | 4 +- lib/sisu/v5/xml_dom.rb | 2 +- lib/sisu/v5/xml_scaffold_structure_collapsed.rb | 2 +- lib/sisu/v5/xml_scaffold_structure_sisu.rb | 2 +- 43 files changed, 5175 insertions(+), 5175 deletions(-) create mode 100644 lib/sisu/v5/ao.rb create mode 100644 lib/sisu/v5/ao_character_check.rb create mode 100644 lib/sisu/v5/ao_doc_objects.rb create mode 100644 lib/sisu/v5/ao_doc_str.rb create mode 100644 lib/sisu/v5/ao_endnotes.rb create mode 100644 lib/sisu/v5/ao_expand_insertions.rb create mode 100644 lib/sisu/v5/ao_hash_digest.rb create mode 100644 lib/sisu/v5/ao_idx.rb create mode 100644 lib/sisu/v5/ao_images.rb create mode 100644 lib/sisu/v5/ao_metadata.rb create mode 100644 lib/sisu/v5/ao_misc_arrange.rb create mode 100644 lib/sisu/v5/ao_numbering.rb create mode 100644 lib/sisu/v5/ao_syntax.rb delete mode 100644 lib/sisu/v5/dal.rb delete mode 100644 lib/sisu/v5/dal_character_check.rb delete mode 100644 lib/sisu/v5/dal_doc_objects.rb delete mode 100644 lib/sisu/v5/dal_doc_str.rb delete mode 100644 lib/sisu/v5/dal_endnotes.rb delete mode 100644 lib/sisu/v5/dal_expand_insertions.rb delete mode 100644 lib/sisu/v5/dal_hash_digest.rb delete mode 100644 lib/sisu/v5/dal_idx.rb delete mode 100644 lib/sisu/v5/dal_images.rb delete mode 100644 lib/sisu/v5/dal_metadata.rb delete mode 100644 lib/sisu/v5/dal_misc_arrange.rb delete mode 100644 lib/sisu/v5/dal_numbering.rb delete mode 100644 lib/sisu/v5/dal_syntax.rb (limited to 'lib') diff --git a/lib/sisu/v5/ao.rb b/lib/sisu/v5/ao.rb new file mode 100644 index 00000000..00484ff9 --- /dev/null +++ b/lib/sisu/v5/ao.rb @@ -0,0 +1,537 @@ +# 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: preprocessing, (document abstraction), data abstraction used + in subsequent processing + +=end +module SiSU_AO + require_relative 'defaults' # defaults.rb + include SiSU_Viz + require_relative 'sysenv' # sysenv.rb + include SiSU_Env + require_relative 'param' # param.rb + include SiSU_Param + require_relative 'ao_doc_objects' # ao.rb + require_relative 'ao_syntax' # ao_syntax.rb + include SiSU_AO_Syntax + require_relative 'ao_doc_str' # ao_doc_str.rb + require_relative 'ao_idx' # ao_idx.rb + require_relative 'ao_numbering' # ao_numbering.rb + require_relative 'ao_hash_digest' # ao_hash_digest.rb + require_relative 'ao_endnotes' # ao_endnotes.rb + require_relative 'ao_images' # ao_images.rb + require_relative 'ao_metadata' # ao_metadata.rb + require_relative 'ao_character_check' # ao_character_check.rb + require_relative 'ao_misc_arrange' # ao_misc_arrange.rb + require_relative 'ao_expand_insertions' # ao_expand_insertions.rb + require_relative 'prog_text_translation' # prog_text_translation.rb + require_relative 'shared_sem' # shared_sem.rb + class Instantiate < SiSU_Param::Parameters::Instructions + def initialize + @@flag_vocab=0 + @@line_mode='' + end + end + class Source #{cf.meta}").txt_grey + end + end + dal.each {|s| dal_array << s} + if @opt.act[:maintenance][:set]==:on + dal_array.each do |obj| + if defined? obj.parent + if defined? obj.ln + if defined? obj.node + puts %{#{obj.ln}: #{obj.ocn} : #{obj.parent} : #{obj.node} - #{obj.lc}} + else + puts %{#{obj.ln}: #{obj.ocn} : #{obj.parent}} + end + else + if defined? obj.node + puts %{ #{obj.ocn} : #{obj.parent} : #{obj.node} - #{obj.lc}} + else + puts %{ #{obj.ocn} : #{obj.parent}} + end + end + end + end + end + dal_array + end + def read_fnm + dal=[] + dal=(FileTest.file?(@fnm)) \ + ? (File.open(@fnm,'r:utf-8'){ |f| dal=Marshal.load(f)}) + : SiSU_AO::Source.new(@opt).create_dal + end + def read_fnc + dal=[] + dal=(FileTest.file?(@fnc)) \ + ? (File.open(@fnc,'r:utf-8'){ |f| dal=Marshal.load(f)}) + : SiSU_AO::Source.new(@opt).create_dal + end + def read_idx_sst + m=[] + m=(FileTest.file?(@idx_sst)) \ + ? (File.open(@idx_sst,'r:utf-8'){ |f| m=Marshal.load(f)}) + : nil + end + def read_idx_raw + m=[] + m=(FileTest.file?(@idx_raw)) \ + ? (File.open(@idx_raw,'r:utf-8'){ |f| m=Marshal.load(f)}) + : nil + end + def read_idx_html + m=[] + m=(FileTest.file?(@idx_html)) \ + ? (File.open(@idx_html,'r:utf-8'){ |f| m=Marshal.load(f)}) + : nil + end + def read_idx_xhtml + m=[] + m=(FileTest.file?(@idx_xhtml)) \ + ? (File.open(@idx_xhtml,'r:utf-8'){ |f| m=Marshal.load(f)}) + : nil + end + def read_map_nametags + m=[] + m=(FileTest.file?(@map_nametags)) \ + ? (File.open(@map_nametags,'r:utf-8'){ |f| m=Marshal.load(f)}) + : nil + end + def read_map_ocn_htmlseg + m=[] + m=(FileTest.file?(@map_ocn_htmlseg)) \ + ? (File.open(@map_ocn_htmlseg,'r:utf-8'){ |f| m=Marshal.load(f)}) + : nil + end + end + class Output + def initialize(fn,md,data) + @fn,@md,@data=fn,md,data + @cf=SiSU_Env::CreateFile.new(@fn) + @make=SiSU_Env::InfoFile.new(@fn) + @dir=SiSU_Env::InfoEnv.new(@fn) + end + def screen_dump(o) + if defined? o.of + print %{OF: #{o.of}; } + end + if defined? o.is + print %{IS: #{o.is.to_s}; } + end + if defined? o.ocn + print %{OCN: #{o.ocn}; } + end + if defined? o.node + print %{NODE: #{o.node}; } + end + if defined? o.parent + print %{Parent: #{o.parent}; } + end + if defined? o.obj and not o.obj.empty? + puts %{\n#{o.obj}; } + else "\n" + end + end + def screen_print(t_o) + if defined? t_o + print ' ' + t_o.to_s + end + end + def screen_output(data) + data.each do |o| + print o.class + screen_print(o.ocn) + screen_print(o.obj) + puts "\n" + end + end + def hard_output + if @md.opt.act[:maintenance][:set]==:on + filename_meta=@cf.metaverse.file_meta + @data.each {|o| filename_meta.puts o.inspect.sub(/:0x[0-9a-f]{8}\s/,': ')} #to make diffing easier + filename_txt=@cf.metaverse.file_txt + @data.each do |o| + if defined? o.ocn + filename_txt.puts case o.is + when :heading + "[#{o.is.to_s} #{o.lv}~#{o.name} [#{o.ocn}]] #{o.obj}" + else "[#{o.is.to_s} [#{o.ocn}]] #{o.obj}" + end + else + filename_txt.puts case o.is + when :meta + "[m~#{o.tag}] #{o.obj}" + else "[#{o.is.to_s}] #{o.obj}" + end + end + end + filename_debug=@cf.file_debug + @data.each do |o| + if defined? o.ocn + case o.is + when :heading + filename_debug.puts "#{o.is.to_s} #{o.lv}~#{o.name} odv=#{o.odv} osp=#{o.osp} [#{o.ocn}] -->\n\t#{o.obj}" + end + end + end + else + hard="#{@dir.processing_path.dal}/#{@md.fns}.meta" + File.unlink(hard) if FileTest.file?(hard) + hard="#{@dir.processing_path.dal}/#{@md.fns}.txt" + File.unlink(hard) if FileTest.file?(hard) + hard="#{@dir.processing_path.dal}/#{@md.fns}.debug.txt" + File.unlink(hard) if FileTest.file?(hard) + end + end + def make_marshal_content + marshal_dal=@make.marshal.dal_content + File.open(marshal_dal,'w'){|f| Marshal.dump(@data,f)} if @data.is_a?(Array) + end + def make_marshal_metadata + marshal_dal=@make.marshal.dal_metadata + File.open(marshal_dal,'w'){|f| Marshal.dump(@data,f)} if @data.is_a?(Array) + end + def idx_html_hard_output + if @md.book_idx \ + and @md.opt.act[:maintenance][:set]==:on + filename_meta=@cf.file_meta_idx_html + if @data.is_a?(Array) + @data.each {|s| p s.inspect + "\n" unless s.is_a?(String)} + @data.each {|s| filename_meta.puts s.strip + "\n" unless s.strip.empty?} + end + else + hard_idx_html="#{@dir.processing_path.dal}/#{@md.fns}.idx.html" + File.unlink(hard_idx_html) if FileTest.file?(hard_idx_html) + end + end + def make_marshal_idx_sst_html_seg + marshal_dal=@make.marshal.dal_idx_sst_rel_html_seg + File.open(marshal_dal,'w'){|f| Marshal.dump(@data,f)} if @data.is_a?(Array) + end + def make_marshal_idx_sst_rel + marshal_dal=@make.marshal.dal_idx_sst_rel + File.open(marshal_dal,'w'){|f| Marshal.dump(@data,f)} if @data.is_a?(Array) + end + def make_marshal_idx_html + marshal_dal=@make.marshal.dal_idx_html + File.open(marshal_dal,'w'){|f| Marshal.dump(@data,f)} if @data.is_a?(Array) + end + def make_marshal_idx_xhtml + marshal_dal=@make.marshal.dal_idx_xhtml + File.open(marshal_dal,'w'){|f| Marshal.dump(@data,f)} if @data.is_a?(Array) + end + def make_marshal_map_nametags + marshal_dal=@make.marshal.dal_map_nametags + File.open(marshal_dal,'w'){|f| Marshal.dump(@data,f)} if @data.is_a?(Hash) + end + def make_marshal_map_name_ocn_htmlseg + marshal_dal=@make.marshal.dal_map_ocn_htmlseg + File.open(marshal_dal,'w'){|f| Marshal.dump(@data,f)} if @data.is_a?(Hash) + end + end + class Make + def initialize(fn,md,data) + @fn,@md,@data=fn,md,data + @env=SiSU_Env::InfoEnv.new(@md.fns) + end + def reset + @@flag_vocab=0 + @@line_mode='' + end + def song + reset + data=@data + data=SiSU_AO_Insertions::Insertions.new(@md,data).expand_insertions? # dal_expand_insertions.rb + data=SiSU_AO_MiscArrangeText::SI.new(@md,data).prepare_text # dal_misc_arrange.rb + data,metadata=SiSU_AO_DocumentStructureExtract::Build.new(@md,data).identify_parts # dal_doc_str.rb + data=SiSU_AO_Syntax::Markup.new(@md,data).songsheet # dal_syntax.rb + data,endnote_array=SiSU_AO_CharacterCheck::Check.new(data).character_check_and_oldstyle_endnote_array # dal_character_check.rb + data=SiSU_AO_Images::Images.new(@md,data).images # dal_images.rb + data,tags_map,ocn_html_seg_map=SiSU_AO_Numbering::Numbering.new(@md,data).numbering_song # dal_numbering.rb + data,book_index_rel,book_index_rel_html_seg,html_idx,xhtml_idx=SiSU_AO_BookIndex::BookIndex.new(@md,data,@env).indexing_song if @md.book_idx # dal_idx.rb + data=SiSU_AO_Endnotes::Endnotes.new(@md,data,endnote_array).endnotes # dal_endnotes.rb + outputdata=data + if (@md.opt.act[:dal][:set]==:on \ + || @md.opt.act[:maintenance][:set]==:on) + SiSU_AO::Output.new(@fn,@md,outputdata).hard_output + SiSU_AO::Output.new(@fn,@md,outputdata).make_marshal_content + SiSU_AO::Output.new(@fn,@md,metadata).make_marshal_metadata + SiSU_AO::Output.new(@fn,@md,html_idx).idx_html_hard_output + SiSU_AO::Output.new(@fn,@md,book_index_rel_html_seg).make_marshal_idx_sst_html_seg + SiSU_AO::Output.new(@fn,@md,book_index_rel).make_marshal_idx_sst_rel + SiSU_AO::Output.new(@fn,@md,html_idx).make_marshal_idx_html + SiSU_AO::Output.new(@fn,@md,xhtml_idx).make_marshal_idx_xhtml + SiSU_AO::Output.new(@fn,@md,tags_map).make_marshal_map_nametags + SiSU_AO::Output.new(@fn,@md,ocn_html_seg_map).make_marshal_map_name_ocn_htmlseg + end + reset + outputdata + end + protected + end +end +__END__ diff --git a/lib/sisu/v5/ao_character_check.rb b/lib/sisu/v5/ao_character_check.rb new file mode 100644 index 00000000..86f23f5b --- /dev/null +++ b/lib/sisu/v5/ao_character_check.rb @@ -0,0 +1,107 @@ +# 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: system environment, resource control and configuration details + +=end +module SiSU_AO_CharacterCheck + class Check + def initialize(data) + @data=data + @comment='%' + @endnote_array=[] + end + def character_check_and_oldstyle_endnote_array + data=@data + @tuned_file,@endnote_array=[],[] + endnote_no=1 + data.each do |dob| + unless dob.is ==:table + dob.obj=dob.obj.strip. + gsub(/^[{~}]\s*$/,''). + gsub(/~#\s*/,"#{Mx[:pa_non_object_no_heading]}"). + gsub(/-#\s*/,"#{Mx[:pa_non_object_dummy_heading]}"). + gsub(/(#{Mx[:en_a_o]})\s*\s+/,'\1 '). + gsub(/(~\{\s*)\s+/,'\1 '). + gsub(/ \/\//,"#{Mx[:br_line]}"). + gsub(/
/,"#{Mx[:br_line]}"). #needed by xml, xhtml etc. + gsub(/\t/,' '). + gsub(/\342\200\231/u,"'"). #if dob =~/’/ #Avoid #‘ ’ #“ ” + gsub(/\\copy(?:right)?\b/,'©'). + gsub(/\\trademark\b|\\tm\b/,'®') + dob.obj=dob.obj + "\n" + unless dob.is ==:code + case dob.obj + when /\^~/ #% Note must do this first (earlier loop) and then enter gathered data into ~^\d+ + sub_dob=dob.obj.dup + @endnote_array << sub_dob.gsub(/\n/,''). + gsub(/\^~\s+(.+)\s*/,%{#{Mx[:en_a_o]}#{endnote_no} \\1 #{Mx[:en_a_c]}}). + strip + endnote_no+=1 + dob=nil if dob.obj =~/\^~ .+/ #watch, removes 'binary' endnote now in endnote array for later insertion + end + end + end + @tuned_file << dob if dob.is_a?(Object) + end + @tuned_file=@tuned_file.flatten.compact + [@tuned_file,@endnote_array] + end + end +end +__END__ diff --git a/lib/sisu/v5/ao_doc_objects.rb b/lib/sisu/v5/ao_doc_objects.rb new file mode 100644 index 00000000..556304d4 --- /dev/null +++ b/lib/sisu/v5/ao_doc_objects.rb @@ -0,0 +1,481 @@ +# 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: document abstraction + +=end +module SiSU_AO_DocumentStructure + class Extract + def extract(h,o) + h ? h : o + end + end + class ObjectMetadata + attr_accessor :is,:of,:tags,:obj,:digest + def initialize + @tags={} + @is=@tmp=@digest=nil + @of=:meta + end + def metadata(tags) + of= @of #String, classification - group + is= :meta #String, classification - specific type + tags= tags || ((defined? o.tags) ? o.tags : {}) #String, metadata type/tag + obj= nil + @of,@is,@tags,@obj=of,is,tags,obj + self + end + end + class ObjectMeta + attr_accessor :obj,:is,:of,:tag,:digest,:tmp + def initialize + @is=@obj=@tag=@digest=@digest=@tmp=nil + @of=:meta + end + def metadata(h,o=nil) + of= @of #String, classification - group + is= :meta #String, classification - specific type + tag= h[:tag] || ((defined? o.tag) ? o.tag : nil) #String, metadata type/tag + obj= h[:obj] || ((defined? o.obj) ? o.obj : nil) #String, text content + tmp= h[:tmp] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use + digest= h[:digest] || ((defined? o.digest) ? o.digest : nil) #hash digests, either sha256 or md5 + @of,@is,@tag,@obj,@digest,@tmp=of,is,tag,obj,digest,tmp + self + end + end + class ObjectHeading + attr_accessor :obj,:is,:tags,:of,:lv,:ln,:lc,:toc_,:name,:idx,:ocn,:odv,:osp,:node,:parent,:ocn_,:note_,:autonum_,:digest,:tmp + def initialize + @of=:para + @is=@obj=@lv=@ln=@lc=@toc_=@name=@idx=@size=@ocn=@odv=@osp=@node=@parent=@ocn_=@note_=@autonum_=@digest=@tmp=nil + @tags=[] + end + def heading_ln(lv) + case lv + when /A/; 1 + when /B/; 2 + when /C/; 3 + when /1/; 4 + when /2/; 5 + when /3/; 6 + when /4/; 7 + when /5/; 8 + when /6/; 9 + end + end + def heading_lv(ln) + case ln.to_s + when /1/; 'A' + when /2/; 'B' + when /3/; 'C' + when /4/; '1' + when /5/; '2' + when /6/; '3' + when /7/; '4' + when /8/; '5' + when /9/; '6' + end + end + def heading(h,o=nil) + if not h[:ln] \ + and (h[:lv] and h[:lv]=~/[1-6A-C]/) + h[:ln]=heading_ln(h[:lv]) + elsif not h[:lv] \ + and (h[:ln] and h[:ln].to_s=~/[1-9]/) + h[:lv]=heading_lv(h[:ln]) + end + of= @of #String, classification - group + is= :heading #String, classification - specific type + name= h[:name] || ((defined? o.name) ? o.name : nil) #String, named object? + tags= h[:tags] || ((defined? o.tags) ? o.tags : []) #Array, associated object tags, names if any + obj= h[:obj] || ((defined? o.obj) ? o.obj : nil) #String, text content + idx= h[:idx] || ((defined? o.idx) ? o.idx : nil) #String, book index provided? + ocn= h[:ocn] || ((defined? o.ocn) ? o.ocn : nil) #Integer, sequential on substantive-content objects + odv= h[:odv] || ((defined? o.odv) ? o.odv : nil) + osp= h[:osp] || ((defined? o.osp) ? o.osp : nil) + node= h[:node] || ((defined? o.node) ? o.node : nil) #[Node relationship doc structure info] + parent= h[:parent] || ((defined? o.parent) ? o.parent : nil) #[Node parent] + lv= h[:lv] || ((defined? o.lv) ? o.lv : nil) #Alpha-numeric, document structure as used in markup, A-C then 1-6 + ln= h[:ln] || ((defined? o.ln) ? o.ln : nil) #Integer, document structure level, for convenience in processing 1-9 + lc= h[:lc] || ((defined? o.lc) ? o.lc : nil) #Integer, document structure collapsed level, convenience (collapse sisu's dual level document structure for markup with simple linear structure) + toc_= h[:toc_] || ((defined? o.toc_) ? o.toc_ : false) #Bool, do not include in toc, (relevant to headings) + ocn_=if h[:ocn_].nil? then ((defined? o.ocn_) ? o.ocn_ : true) #Bool? no ocn, non-substantive content, do not include in toc #consider + else h[:ocn_] + end + autonum_= if h[:autonum_].nil? then ((defined? o.autonum_) ? o.autonum_ : true) #Bool? auto-numbering if requested default on, false suppresses + else h[:autonum_] + end + note_= h[:note_] || ((defined? o.note_) ? o.note_ : false) #Bool, endnotes/footnotes? (processing optimization) + digest= h[:digest] || ((defined? o.digest) ? o.digest : nil) #hash digests, either sha256 or md5 + tmp= h[:tmp] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use + @of,@is,@lv,@ln,@lc,@name,@tags,@obj,@idx,@ocn,@odv,@osp,@node,@parent,@toc_,@ocn_,@note_,@autonum_,@digest,@tmp=of,is,lv,ln,lc,name,tags,obj,idx,ocn,odv,osp,node,parent,toc_,ocn_,note_,autonum_,digest,tmp + self + end + def heading_insert(h,o=nil) + heading(h,o=nil) + @is= :heading_insert #String, classification - specific type + self + end + end + class ObjectPara + attr_accessor :obj,:is,:tags,:of,:name,:idx,:bullet_,:indent,:hang,:ocn,:odv,:osp,:parent,:note_,:image_,:ocn_,:digest,:tmp + def initialize + @of=:para + @is=@obj=@name=@idx=@bullet_=@indent=@hang=@size=@ocn=@odv=@osp=@parent=@note_=@image_=@ocn_=@digest=@tmp=nil + @tags=[] + end + def paragraph(h,o=nil) + of= @of #String, classification - group + is= :para #String, classification - specific type + name= h[:name] || ((defined? o.name) ? o.name : nil) #String, named object? + tags= h[:tags] || ((defined? o.tags) ? o.tags : []) #Array, associated object tags, names if any + obj= h[:obj] || ((defined? o.obj) ? o.obj : nil) #String, text content + idx= h[:idx] || ((defined? o.idx) ? o.idx : nil) #String, book index provided? + ocn= h[:ocn] || ((defined? o.ocn) ? o.ocn : nil) #Integer, sequential on substantive-content objects + odv= h[:odv] || ((defined? o.odv) ? o.odv : nil) + osp= h[:osp] || ((defined? o.osp) ? o.osp : nil) + parent= h[:parent] || ((defined? o.parent) ? o.parent : nil) #[Node parent] + indent= h[:indent].to_s || ((defined? o.indent) ? o.indent.to_s : nil) #Integer, indent level + hang= h[:hang].to_s || ((defined? o.hang) ? o.hang.to_s : nil) #Integer, hanging indent level + bullet_=h[:bullet_] || ((defined? o.bullet_) ? o.bullet_ : false) #Bool, bulleted? + note_= h[:note_] || ((defined? o.note_) ? o.note_ : false) #Bool, endnotes/footnotes? (processing optimization) + image_= h[:image_] || ((defined? o.image_) ? o.image_ : false) #Bool, images? (processing optimization) + ocn_=if h[:ocn_].nil? then ((defined? o.ocn_) ? o.ocn_ : true) #Bool? no ocn, non-substantive content, do not include in toc #consider + else h[:ocn_] + end + digest= h[:digest] || ((defined? o.digest) ? o.digest : nil) #hash digests, either sha256 or md5 + tmp= h[:tmp] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use + @of,@is,@name,@tags,@obj,@indent,@hang,@bullet_,@idx,@ocn,@odv,@osp,@parent,@image_,@note_,@ocn_,@digest,@tmp=of,is,name,tags,obj,indent,hang,bullet_,idx,ocn,odv,osp,parent,image_,note_,ocn_,digest,tmp + self + end + def docinfo(h,o=nil) + of= @of #String, classification - group + is= :docinfo #String, classification - specific type + name= h[:name] || ((defined? o.name) ? o.name : nil) #String, named object? + tags= h[:tags] || ((defined? o.tags) ? o.tags : nil) #Array, associated object tags, names if any + obj= h[:obj] || ((defined? o.obj) ? o.obj : nil) #String, text content + idx= nil #String, book index provided? + ocn= nil #Integer, sequential on substantive-content objects + odv= h[:odv] || ((defined? o.odv) ? o.odv : nil) + osp= h[:osp] || ((defined? o.osp) ? o.osp : nil) + parent= h[:parent] || ((defined? o.parent) ? o.parent : nil) #[Node parent] + indent= nil #Integer, indent level + hang= nil #Integer, indent level + bullet_=false #Bool, bulleted? + note_= false #Bool, endnotes/footnotes? (processing optimization) + image_= h[:image_] || ((defined? o.image_) ? o.image_ : false) #Bool, images? (processing optimization) + ocn_=if h[:ocn_].nil? then ((defined? o.ocn_) ? o.ocn_ : true) #Bool? no ocn, non-substantive content, do not include in toc #consider + else h[:ocn_] + end + digest= h[:digest] || ((defined? o.digest) ? o.digest : nil) #hash digests, either sha256 or md5 + tmp= h[:tmp] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use + @of,@is,@name,@tags,@obj,@indent,@hang,@bullet_,@idx,@ocn,@odv,@osp,@parent,@image_,@note_,@ocn_,@digest,@tmp=of,is,name,tags,obj,indent,hang,bullet_,idx,ocn,odv,osp,parent,image_,note_,ocn_,digest,tmp + self + end + end + class ObjectBlockTxt + attr_accessor :obj,:is,:of,:tags,:idx,:ocn,:odv,:osp,:parent,:note_,:number_,:ocn_,:digest,:tmp + def initialize + @of=:block + @is=@obj=@idx=@ocn=@odv=@osp=@parent=@note_=@number_=@ocn_=@digest=@tmp=nil + @tags=[] + end + def code(h,o=nil) + of= @of #String, classification - group #alt 'code' + is= :code #String, classification - specific type + tags= h[:tags] || ((defined? o.tags) ? o.tags : []) #Array, associated object tags, names if any + obj= h[:obj] || ((defined? o.obj) ? o.obj : nil) #String, text content + idx= h[:idx] || ((defined? o.idx) ? o.idx : nil) #String, book index provided? + ocn= h[:ocn] || ((defined? o.ocn) ? o.ocn : nil) #Integer, sequential on substantive-content objects + odv= h[:odv] || ((defined? o.odv) ? o.odv : nil) + osp= h[:osp] || ((defined? o.osp) ? o.osp : nil) + parent= h[:parent] || ((defined? o.parent) ? o.parent : nil) #[Node parent] + number_= h[:number_] || ((defined? o.number_) ? o.number_ : false) #Bool, numbered or not? + note_= h[:note_] || ((defined? o.note_) ? o.note_ : false) #Bool, endnotes/footnotes? (processing optimization) + ocn_= if h[:ocn_].nil? then ((defined? o.ocn_) ? o.ocn_ : true) #Bool? no ocn, non-substantive content, do not include in toc #consider + else h[:ocn_] + end + digest= h[:digest] || ((defined? o.digest) ? o.digest : nil) #hash digests, either sha256 or md5 + tmp= h[:tmp] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use + @of,@is,@tags,@obj,@idx,@ocn,@odv,@osp,@parent,@number_,@note_,@ocn_,@digest,@tmp=of,is,tags,obj,idx,ocn,odv,osp,parent,number_,note_,ocn_,digest,tmp + self + end + def block(h,o=nil) + of= @of #String, classification - group + is= :block #String, classification - specific type + tags= h[:tags] || ((defined? o.tags) ? o.tags : []) #Array, associated object tags, names if any + obj= h[:obj] || ((defined? o.obj) ? o.obj : nil) #String, text content + idx= h[:idx] || ((defined? o.idx) ? o.idx : nil) #String, book index provided? + ocn= h[:ocn] || ((defined? o.ocn) ? o.ocn : nil) #Integer, sequential on substantive-content objects + odv= h[:odv] || ((defined? o.odv) ? o.odv : nil) + osp= h[:osp] || ((defined? o.osp) ? o.osp : nil) + parent= h[:parent] || ((defined? o.parent) ? o.parent : nil) #[Node parent] + note_= h[:note_] || ((defined? o.note_) ? o.note_ : false) #Bool, endnotes/footnotes? (processing optimization) + ocn_= if h[:ocn_].nil? then ((defined? o.ocn_) ? o.ocn_ : true) #Bool? no ocn, non-substantive content, do not include in toc #consider + else h[:ocn_] + end + digest= h[:digest] || ((defined? o.digest) ? o.digest : nil) #hash digests, either sha256 or md5 + tmp= h[:tmp] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use + @of,@is,@tags,@obj,@idx,@ocn,@odv,@osp,@parent,@note_,@ocn_,@digest,@tmp=of,is,tags,obj,idx,ocn,odv,osp,parent,note_,ocn_,digest,tmp + self + end + def group(h,o=nil) + of= @of #String, classification - group + is= :group #String, classification - specific type + tags= h[:tags] || ((defined? o.tags) ? o.tags : []) #Array, associated object tags, names if any + obj= h[:obj] || ((defined? o.obj) ? o.obj : nil) #String, text content + idx= h[:idx] || ((defined? o.idx) ? o.idx : nil) #String, book index provided? + ocn= h[:ocn] || ((defined? o.ocn) ? o.ocn : nil) #Integer, sequential on substantive-content objects + odv= h[:odv] || ((defined? o.odv) ? o.odv : nil) + osp= h[:osp] || ((defined? o.osp) ? o.osp : nil) + parent= h[:parent] || ((defined? o.parent) ? o.parent : nil) #[Node parent] + note_= h[:note_] || ((defined? o.note_) ? o.note_ : false) #Bool, endnotes/footnotes? (processing optimization) + ocn_= if h[:ocn_].nil? then ((defined? o.ocn_) ? o.ocn_ : true) #Bool? no ocn, non-substantive content, do not include in toc #consider + else h[:ocn_] + end + digest= h[:digest] || ((defined? o.digest) ? o.digest : nil) #hash digests, either sha256 or md5 + tmp= h[:tmp] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use + @of,@is,@tags,@obj,@idx,@ocn,@odv,@osp,@parent,@note_,@ocn_,@digest,@tmp=of,is,tags,obj,idx,ocn,odv,osp,parent,note_,ocn_,digest,tmp + self + end + def alt(h,o=nil) #see block + of= @of #String, classification - group + is= :alt #String, classification - specific type + tags= h[:tags] || ((defined? o.tags) ? o.tags : []) #Array, associated object tags, names if any + obj= h[:obj] || ((defined? o.obj) ? o.obj : nil) #String, text content + idx= h[:idx] || ((defined? o.idx) ? o.idx : nil) #String, book index provided? + ocn= h[:ocn] || ((defined? o.ocn) ? o.ocn : nil) #Integer, sequential on substantive-content objects + odv= h[:odv] || ((defined? o.odv) ? o.odv : nil) + osp= h[:osp] || ((defined? o.osp) ? o.osp : nil) + parent= h[:parent] || ((defined? o.parent) ? o.parent : nil) #[Node parent] + note_= h[:note_] || ((defined? o.note_) ? o.note_ : false) #Bool, endnotes/footnotes? (processing optimization) + ocn_= if h[:ocn_].nil? then ((defined? o.ocn_) ? o.ocn_ : true) #Bool? no ocn, non-substantive content, do not include in toc #consider + else h[:ocn_] + end + digest= h[:digest] || ((defined? o.digest) ? o.digest : nil) #hash digests, either sha256 or md5 + tmp= h[:tmp] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use + @of,@is,@tags,@obj,@idx,@ocn,@odv,@osp,@parent,@note_,@ocn_,@digest,@tmp=of,is,tags,obj,idx,ocn,odv,osp,parent,note_,ocn_,digest,tmp + self + end + def verse(h,o=nil) #part of poem decide how you deal with this + of= @of #String, classification - group + is= :verse #String, classification - specific type + tags= h[:tags] || ((defined? o.tags) ? o.tags : []) #Array, associated object tags, names if any + obj= h[:obj] || ((defined? o.obj) ? o.obj : nil) #String, text content + idx= h[:idx] || ((defined? o.idx) ? o.idx : nil) #String, book index provided? + ocn= h[:ocn] || ((defined? o.ocn) ? o.ocn : nil) #Integer, sequential on substantive-content objects + odv= h[:odv] || ((defined? o.odv) ? o.odv : nil) + osp= h[:osp] || ((defined? o.osp) ? o.osp : nil) + parent= h[:parent] || ((defined? o.parent) ? o.parent : nil) #[Node parent] + ocn_= if h[:ocn_].nil? then ((defined? o.ocn_) ? o.ocn_ : true) #Bool? no ocn, non-substantive content, do not include in toc #consider + else h[:ocn_] + end + digest= h[:digest] || ((defined? o.digest) ? o.digest : nil) #hash digests, either sha256 or md5 + tmp= h[:tmp] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use + @of,@is,@tags,@obj,@idx,@ocn,@odv,@osp,@parent,@note_,@ocn_,@digest,@tmp=of,is,tags,obj,idx,ocn,odv,osp,parent,note_,ocn_,digest,tmp + @h=nil + self + end + end + class ObjectTable + attr_accessor :obj,:is,:of,:lv,:tags,:name,:idx,:indent,:hang,:size,:ocn,:number,:head_,:cols,:widths,:odv,:osp,:parent,:note_,:ocn_,:digest,:tmp + def initialize + @of=:block + @is=@obj=@lv=@name=@idx=@indent=@hang=@size=@ocn,@number,@head_,@cols,@widths=@odv=@osp=@parent=@note_=@ocn_=@digest=@tmp=nil + @tags=[] + end + def table(h,o=nil) + of= @of #String, classification - group + is= :table #String, classification - specific type + tags= h[:tags] || ((defined? o.tags) ? o.tags : []) #Array, associated object tags, names if any + cols= h[:cols] || ((defined? o.cols) ? o.cols : nil) + widths= h[:widths] || ((defined? o.widths) ? o.widths : nil) + obj= h[:obj] || ((defined? o.obj) ? o.obj : nil) #String, text content + idx= h[:idx] || ((defined? o.idx) ? o.idx : nil) #String, book index provided? + ocn= h[:ocn] || ((defined? o.ocn) ? o.ocn : nil) #Integer, sequential on substantive-content objects + odv= h[:odv] || ((defined? o.odv) ? o.odv : nil) + osp= h[:osp] || ((defined? o.osp) ? o.osp : nil) + parent= h[:parent] || ((defined? o.parent) ? o.parent : nil) #[Node parent] + head_= h[:head_] || ((defined? o.head_) ? o.head_ : false) + note_= h[:note_] || ((defined? o.note_) ? o.note_ : false) #Bool, endnotes/footnotes? (processing optimization) + ocn_=if h[:ocn_].nil? then ((defined? o.ocn_) ? o.ocn_ : true) #Bool? no ocn, non-substantive content, do not include in toc #consider + else h[:ocn_] + end + digest= h[:digest] || ((defined? o.digest) ? o.digest : nil) #hash digests, either sha256 or md5 + tmp= h[:tmp] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use + @of,@is,@tags,@cols,@widths,@obj,@idx,@ocn,@odv,@osp,@parent,@head_,@note_,@ocn_,@digest,@tmp=of,is,tags,cols,widths,obj,idx,ocn,odv,osp,parent,head_,note_,ocn_,digest,tmp + self + end + end + class ObjectImage + attr_accessor :obj,:is,:of,:lv,:idx,:size,:ocn,:parent,:note_,:ocn_,:digest,:tmp + def initialize + @of=:image + @is=@obj=@lv=@idx=@size=@ocn=@parent=@note_=@ocn_=@tmp=@digest=nil + @tags=[] + end + def image(h,o=nil) #not yet used, and what of a paragraph containing several images, consider + of= @of #String, classification - group + is= :image #String, classification - specific type + tags= h[:tags] || ((defined? o.tags) ? o.tags : []) #Array, associated object tags, names if any + obj= h[:obj] || ((defined? o.obj) ? o.obj : nil) #String, text content + size= h[:size] || ((defined? o.size) ? o.size : nil) + idx= h[:idx] || ((defined? o.idx) ? o.idx : nil) #String, book index provided? + ocn= h[:ocn] || ((defined? o.ocn) ? o.ocn : nil) #Integer, sequential on substantive-content objects + odv= h[:odv] || ((defined? o.odv) ? o.odv : nil) + osp= h[:osp] || ((defined? o.osp) ? o.osp : nil) + parent= h[:parent] || ((defined? o.parent) ? o.parent : nil) #[Node parent] + note_= h[:note_] || ((defined? o.note_) ? o.note_ : false) #Bool, endnotes/footnotes? (processing optimization) + ocn_=if h[:ocn_].nil? then ((defined? o.ocn_) ? o.ocn_ : true) #Bool? no ocn, non-substantive content, do not include in toc #consider + else h[:ocn_] + end + digest= h[:digest] || ((defined? o.digest) ? o.digest : nil) #hash digests, either sha256 or md5 + tmp= h[:tmp] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use + @of,@is,@tags,@obj,@size,@idx,@ocn,@odv,@osp,@parent,@note_,@ocn_,@digest,@tmp=of,is,tags,obj,size,idx,ocn,odv,osp,parent,note_,ocn_,digest,tmp + self + end + end + class ObjectStructure + attr_accessor :obj,:tag,:node,:lv,:ln,:lc,:status,:is,:of,:tmp + def initialize + @of=:structure + @is=@obj=@node=@lv=@ln=@lc=@status=@tmp=nil + end + def xml_dom(h,o=nil) + of= @of #String, classification - group + is= :xml_dom #String, classification - specific type + obj= h[:obj] || ((defined? o.obj) ? o.obj : '') #String, text content + lv= h[:lv] || ((defined? o.lv) ? o.lv : nil) #Alpha-numeric, document structure as used in markup, A-C then 1-6 + ln= h[:ln] || ((defined? o.ln) ? o.ln : nil) #Integer, document structure level, for convenience in processing 1-9 + lc= h[:lc] || ((defined? o.lc) ? o.lc : nil) #Integer, document structure collapsed level, convenience (collapse sisu's dual level document structure for markup with simple linear structure) + node= h[:node] || ((defined? o.node) ? o.node : nil) #[Node relationship doc structure info] + status= h[:status] || ((defined? o.status) ? o.status : nil) #tag status open or close + tmp= h[:tmp] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use + @of,@is,@obj,@status,@node,@lv,@ln,@lc,@tmp=of,is,obj,status,node,lv,ln,lc,tmp + self + end + end + class ObjectComment + attr_accessor :obj,:is,:of,:tmp + def initialize + @of=:comment + @is=@obj=@tmp=nil + end + def comment(h,o=nil) + of= @of #String, classification - group + is= :comment #String, classification - specific type + obj= h[:obj] || ((defined? o.obj) ? o.obj : nil) #String, text content + tmp= h[:tmp] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use + @of,@is,@obj,@tmp=of,is,obj,tmp + self + end + end + class ObjectFlag + attr_accessor :obj,:is,:of,:flag,:mod,:tmp + def initialize + @of=:flag + @is=@obj=@flag=@mod=@tmp=nil + end + def flag(h,o=nil) + of= @of #String, classification - group + is= :flag #String, classification - specific type + obj= nil #String, text content + flag= h[:flag] || ((defined? o.flag) ? o.flag : nil) #String, text content + mod= h[:mod] || ((defined? o.mod) ? o.mod : nil) #String, text content + tmp= h[:flag] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use + @of,@is,@obj,@flag,@mod,@tmp=of,is,obj,flag,mod,tmp + self + end + def flag_ocn(h,o=nil) + of= @of #String, classification - group + is= :flag_ocn #String, classification - specific type + obj= nil #String, text content + flag= h[:flag] || ((defined? o.flag) ? o.flag : nil) #String, text content + mod= h[:mod] || ((defined? o.mod) ? o.mod : nil) #String, text content + tmp= h[:flag] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use + @of,@is,@obj,@flag,@mod,@tmp=of,is,obj,flag,mod,tmp + self + end + end + class ObjectLayout + attr_accessor :obj,:is,:of,:from,:tmp + def initialize + @of=:layout + @is=@obj=@from=@tmp=nil + end + def break(h,f=nil) #decide how to deal with + of= @of #String, classification - group + is= :break #String, classification - specific type + obj= h[:obj] #String, text content + from= f + tmp= h[:tmp] #available for processing, empty after use + @of,@is,@obj,@from,@tmp=of,is,obj,from,tmp + self + end + def insert(h,o=nil) #decide how to deal with, could mimic paragraph? + of= @of #String, classification - group + is= :insert #String, classification - specific type + obj= h[:obj] || ((defined? o.obj) ? o.obj : nil) #String, text content + tmp= h[:tmp] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use + @of,@is,@obj,@tmp=of,is,obj,tmp + self + end + end +end +__END__ +# ~# |-# no paragraph number # -# not included in toc diff --git a/lib/sisu/v5/ao_doc_str.rb b/lib/sisu/v5/ao_doc_str.rb new file mode 100644 index 00000000..465a5666 --- /dev/null +++ b/lib/sisu/v5/ao_doc_str.rb @@ -0,0 +1,1427 @@ +# 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: document abstraction + +=end +module SiSU_AO_DocumentStructureExtract + class Instantiate < SiSU_Param::Parameters::Instructions + @@flag={ + ocn: :on, + code: :off, + poem: :off, + block: :off, + group: :off, + alt: :off, + table: :off, + table_to: :off, + } + def initialize + @@counter=@@column=@@columns=0 + @@line_mode='' + end + end + class Build + @@flag={ + ocn: :on, + code: :off, + poem: :off, + block: :off, + group: :off, + alt: :off, + table: :off, + table_to: :off, + } + def initialize(md,data) + @md,@data=md,data + SiSU_AO_DocumentStructureExtract::Instantiate.new + @pb=SiSU_AO_DocumentStructure::ObjectLayout.new.break(Hx[:br_page]) + @pbn=SiSU_AO_DocumentStructure::ObjectLayout.new.break(Hx[:br_page_new]) + @pbl=SiSU_AO_DocumentStructure::ObjectLayout.new.break(Hx[:br_page_line]) + end + def ln_get(lv) + case lv + when /A/; 1 + when /B/; 2 + when /C/; 3 + when /1/; 4 + when /2/; 5 + when /3/; 6 + when /4/; 7 + when /5/; 8 + when /6/; 9 + end + end + def image_test(str) + str=~/\{\s*\S+?\.png.+?\}https?:\/\/\S+/ \ + ? true + : false + end + def bullet_test(str) + (str=~/\*/) \ + ? true + : false + end + def hang_and_indent_test(str) + hang_indent=if str=~/^_([1-9])[^_]/ + [$1,$1] + elsif str=~/^__([1-9])/ + [0,$1] + elsif str=~/^_([0-9])_([0-9])/ + [$1,$2] + else + [0,0] + end + hang,indent=hang_indent[0],hang_indent[1] + [hang,indent] + end + def hang_and_indent_def_test(str1,str2) + hang_indent=if str1=~/^_([1-9])[^_]/ + [$1,$1] + elsif str1=~/^__([1-9])/ + [0,$1] + elsif str1=~/^_([0-9])_([0-9])/ + [$1,$2] + else + [0,0] + end + obj=if str2 =~/^(.+?)\s+\\\\(?:\s+|\n)/ + str2.gsub(/^(.+?)(\s+\\\\(?:\s+|\n))/,"#{Mx[:fa_bold_o]}\\1#{Mx[:fa_bold_c]}\\2") + else + str2.gsub(/^(.+?)\n/,"#{Mx[:fa_bold_o]}\\1#{Mx[:fa_bold_c]}\n") + end + hang,indent=hang_indent[0],hang_indent[1] + [hang,indent,obj] + end + def endnote_test?(str) + (str=~/~\{.+?\}~|~\[.+?\]~/) \ + ? true + : false + end + def extract_tags(str,nametag=nil) + tags=[] + if str.nil? + else + if str =~/(?:^|[ ])\*~([a-z0-9._-]+)(?=[ #{Mx[:br_nl]}]|$)/ + str=str.gsub(/(^|[ ])\*~([a-z0-9._-]+)(?=[ #{Mx[:br_nl]}]|$)/i, + "\\1#{Mx[:tag_o]}\\2#{Mx[:tag_c]}"). + gsub(/ [ ]+/i,' ') + tags=str.scan(/#{Mx[:tag_o]}(\S+?)#{Mx[:tag_c]}/).flatten + str=str.gsub(/[ ]?#{Mx[:tag_o]}\S+?#{Mx[:tag_c]}[ ]?/,' ') #may be issues with spaces would leave one, but "code" blocks? + end + tags=nametag ? (tags << nametag) : tags + end + [str,tags] + end + def rgx_idx_ocn_seg + @rgx_idx_ocn_seg=/(.+?)\s*[+](\d+)/ + end + def construct_idx_array_and_hash(idxraw) + idx_array_raw=idxraw.scan(/[^;]+/) + idx_hash,idx_array,idx_lst={},[],[] + idx_array_raw.each do |idx| + idx_lst=case idx + when /\S+?\s*:/ + idx_couplet_tmp=[] + idx_couplet=idx.scan(/\s*[^:]+\s*/) + if idx_couplet[1] =~/[|]/ + idx_couplet_tmp << idx_couplet[0] << idx_couplet[1].scan(/\s*[^|]+\s*/) + else + idx_couplet_tmp << idx_couplet[0] << [idx_couplet[1]] + end + idx_couplet=idx_couplet_tmp + else [idx] + end + term_nodes=[] + idx_lst.each do |term_node| + case term_node + when String + term_node=term_node[0].chr.capitalize + term_node[1,term_node.length] + term_node=(term_node =~/.+?[+]\d+/) \ + ? term_node + : (term_node + '+0') + term_nodes << term_node + use,plus=rgx_idx_ocn_seg.match(term_node)[1,2] + @use=use.strip + idx_hash[@use]={ sub: [], plus: plus } unless idx_hash[@use] and defined? idx_hash[@use] + when Array + subterm_nodes=[] + term_node.each do |subterm_node| + subterm_node=(subterm_node =~/.+?[+]\d+/) \ + ? subterm_node + : (subterm_node + '+0') + subterm_nodes << subterm_node + sub,sub_plus=rgx_idx_ocn_seg.match(subterm_node)[1,2] + idx_hash[@use]={ sub: [], plus: 0 } unless idx_hash[@use] and defined? idx_hash[@use] + idx_hash[@use][:sub] << {sub.strip => { plus: sub_plus }} + end + term_nodes << subterm_nodes + end + end + idx_array << term_nodes + end + { hash: idx_hash, array: idx_array } + end + def identify_parts + tuned_file=[] + @tuned_block,@tuned_code=[],[] + @@counter,@verse_count=0,0 + @metadata={} + @data.each do |t_o| + if t_o =~/^--([+~-])[#]$/ + h=case $1 + when /[+]/ + @@flag[:ocn]=:on + {flag: :ocn_on} + when /[~]/ + @@flag[:ocn]=:off_headings_substantive + {flag: :ocn_off, mod: :headings_substantive} + when /[-]/ + @@flag[:ocn]=:off_headings_exclude + {flag: :ocn_off, mod: :headings_exclude} + else + @@flag[:ocn]=:on + {flag: :ocn_on} + end + t_o=SiSU_AO_DocumentStructure::ObjectFlag.new.flag_ocn(h) + next + end + t_o=t_o.gsub(/(?:\n\s*\n)+/m,"\n") if @@flag[:code]==:off + if t_o !~/^(?:code|poem|alt|group|block)\{|^\}(?:code|poem|alt|group|block)|^(?:table\{|\{table)[ ~]/ \ + and t_o !~/^[`]{3}\s+(?:code|poem|alt|group|block|table)|^[`]{3}(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/ \ + and @@flag[:code]==:off \ + and @@flag[:poem]==:off \ + and @@flag[:group]==:off \ + and @@flag[:block]==:off \ + and @@flag[:alt]==:off \ + and @@flag[:table]==:off + unless t_o =~/^(?:@\S+?:|%+)\s/ # extract book index for paragraph if any + idx=if t_o=~/^=\{(.+)\}\s*$\Z/m; m=$1 + m=m.split(/\n/).join(' '). + gsub(/\s+([|:;])\s+/,'\1'). + gsub(/\s+([+]\d+)\s+/,'\1') + t_o=t_o.gsub(/\n=\{.+\}\s*$\Z/m,'') + idx_array_and_hash=construct_idx_array_and_hash(m) + idx_array_and_hash[:hash] + else nil + end + end + t_o=case t_o + when /^#{Mx[:meta_o]}\S+?#{Mx[:meta_c]}/ #metadata, header + if t_o=~/^#{Mx[:meta_o]}(\S+?)#{Mx[:meta_c]}\s*(.+)/m + tag,obj=$1,$2 + @metadata[tag]=obj + end + t_o=nil + when /^%+\s/ #comment + t_o=if t_o=~/^%+\s+(.+)/ + h={obj: $1} + SiSU_AO_DocumentStructure::ObjectComment.new.comment(h) + else nil + end + when /^:?([A-C1-6])\~/ #heading / lv + lv=$1 + ln=ln_get(lv) + t_o=if t_o=~/^:?[A-C1-6]\~\s+(.+)/m + obj=$1 + note=endnote_test?(obj) + obj,tags=extract_tags(obj) + if @@flag[:ocn]==:off_headings_exclude \ + or @@flag[:ocn]==:off_headings_substantive + unless obj =~ /[~-][#]\s*$/ + if @@flag[:ocn]==:off_headings_exclude + obj << ' -#' + elsif @@flag[:ocn]==:off_headings_substantive + obj << ' ~#' + end + end + end + h={ lv: lv, ln: ln, obj: obj, idx: idx, tags: tags } + SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h) + elsif t_o=~/^:?[A-C1-6]\~(\S+?)-\s+(.+)/m + name,obj=$1,$2 + note=endnote_test?(obj) + obj,tags=extract_tags(obj) + if @@flag[:ocn]==:off_headings_exclude \ + or @@flag[:ocn]==:off_headings_substantive + unless obj =~ /[~-][#]\s*$/ + if @@flag[:ocn]==:off_headings_exclude + obj << ' -#' + elsif @@flag[:ocn]==:off_headings_substantive + obj << ' ~#' + end + end + end + h={ lv: lv, name: name, obj: obj, idx: idx, autonum_: false, tags: tags} + SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h) + elsif t_o=~/^:?[A-C1-6]\~(\S+)\s+(.+)/m + name,obj=$1,$2 + note=endnote_test?(obj) + obj,tags=extract_tags(obj,name) + if @@flag[:ocn]==:off_headings_exclude \ + or @@flag[:ocn]==:off_headings_substantive + unless obj =~ /[~-][#]\s*$/ + if @@flag[:ocn]==:off_headings_exclude + obj << ' -#' + elsif @@flag[:ocn]==:off_headings_substantive + obj << ' ~#' + end + end + end + h={ lv: lv, name: name, obj: obj, idx: idx, tags: tags } + SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h) + else nil + end + when /^_(?:[1-9]!?|[1-9]?\*)\s+/ #indented and/or bullet paragraph + t_o=if t_o=~/^(_(?:[1-9]?\*|[1-9]!?)\s+)(.+)/m + tst,obj=$1,$2 + if t_o=~/^_[1-9]!\s+.+/m + hang,indent,obj=hang_and_indent_def_test(tst,obj) + else + hang,indent=hang_and_indent_test(tst) + end + bullet=bullet_test(tst) + image=image_test(obj) + note=endnote_test?(obj) + obj,tags=extract_tags(obj) + unless obj=~/\A\s*\Z/m + if @@flag[:ocn]==:off_headings_exclude \ + or @@flag[:ocn]==:off_headings_substantive + unless obj =~ /[~-][#]\s*$/ + obj << ' ~#' + end + end + h={ bullet_: bullet, hang: hang, indent: indent, obj: obj, idx: idx, note_: note, image_: image, tags: tags } + SiSU_AO_DocumentStructure::ObjectPara.new.paragraph(h) + end + else nil + end + when /^_[0-9]?_[0-9]!?\s+/ #hanging indent paragraph + t_o=if t_o=~/^(_[0-9]?_[0-9]!?\s+)(.+)/m + tst,obj=$1,$2 + if t_o=~/^_[0-9]?_[0-9]!\s+.+/m + hang,indent,obj=hang_and_indent_def_test(tst,obj) + else + hang,indent=hang_and_indent_test(tst) + end + image=image_test(obj) + note=endnote_test?(obj) + obj,tags=extract_tags(obj) + unless obj=~/\A\s*\Z/m + if @@flag[:ocn]==:off_headings_exclude \ + or @@flag[:ocn]==:off_headings_substantive + unless obj =~ /[~-][#]\s*$/ + obj << ' ~#' + end + end + h={ hang: hang, indent: indent, obj: obj, idx: idx, note_: note, image_: image, tags: tags } + SiSU_AO_DocumentStructure::ObjectPara.new.paragraph(h) + end + else nil + end + when /^<(?:br)?:(?:pa?r|o(?:bj|---)?)>\s*$/ #[br:par] #[br:obj] + SiSU_AO_DocumentStructure::ObjectLayout.new.break(Hx[:br_obj]) + when /^(?:-\\\\-|<:pb>)\s*$/ #[br:pg] + SiSU_AO_DocumentStructure::ObjectLayout.new.break(Hx[:br_page],:markup) + when /^(?:=\\\\=|<:pn>)\s*$/ #[br:pgn] + SiSU_AO_DocumentStructure::ObjectLayout.new.break(Hx[:br_page_new],:markup) + when /^-\.\.-\s*$/ #[br:pgl] + SiSU_AO_DocumentStructure::ObjectLayout.new.break(Hx[:br_page_line],:markup) + else #paragraph + image=image_test(t_o) + note=endnote_test?(t_o) + obj,tags=extract_tags(t_o) + if @@flag[:ocn]==:off_headings_exclude \ + or @@flag[:ocn]==:off_headings_substantive + unless obj =~ /[~-][#]\s*$/ + obj << ' ~#' + end + end + unless obj=~/\A\s*\Z/m + h={ bullet_: false, indent: 0, hang: 0, obj: obj, idx: idx, note_: note, image_: image, tags: tags } + SiSU_AO_DocumentStructure::ObjectPara.new.paragraph(h) + end + end + elsif @@flag[:code]==:off + if t_o =~/^(?:code\{|[`]{3}\s+code)/ + @@flag[:code]=case t_o + when /^code\{/; :curls + when /^[`]{3}\s+code/; :tics + else @@flag[:code] #error + end + @@counter=1 + @codeblock_numbered=(t_o =~/^(?:code\{#|[`]{3}\s+code\s[#])/) ? true : false + h={ obj: 'code block start' } #introduce a counter + t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h) + elsif t_o =~/^(?:poem\{|[`]{3}\s+poem)/ + @@flag[:poem]=case t_o + when /^poem\{/; :curls + when /^[`]{3}\s+poem/; :tics + else @@flag[:poem] #error + end + h={ obj: 'poem start' } #introduce a counter + t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h) + tuned_file << t_o + elsif t_o =~/^(?:group\{|[`]{3}\s+group)/ + @@flag[:group]=case t_o + when /^group\{/; :curls + when /^[`]{3}\s+group/; :tics + else @@flag[:group] #error + end + h={ obj: 'group text start' } #introduce a counter + t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h) + tuned_file << t_o + elsif t_o =~/^(?:block\{|[`]{3}\s+block)/ + @@flag[:block]=case t_o + when /^block\{/; :curls + when /^[`]{3}\s+block/; :tics + else @@flag[:block] #error + end + h={ obj: 'block text start' } #introduce a counter + t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h) + tuned_file << t_o + elsif t_o =~/^(?:alt\{|[`]{3}\s+alt)/ + @@flag[:alt]=case t_o + when /^alt\{/; :curls + when /^[`]{3}\s+alt/; :tics + else @@flag[:alt] #error + end + h={ obj: 'alt text start' } #introduce a counter + t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h) + tuned_file << t_o + elsif t_o =~/^(?:table\{|[`]{3}\s+table|\{table)[ ~]/ + h={ obj: 'table start' } #introduce a counter + ins=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h) + tuned_file << ins + if t_o=~/^table\{(?:~h)?\s+/ + @@flag[:table]=:curls + @rows='' + case t_o + when /table\{~h\s+c(\d+);\s+(.+)/ + cols=$1 + col=$2.scan(/\d+/) + heading=true + when /table\{\s+c(\d+);\s+(.+)/ + cols=$1 + col=$2.scan(/\d+/) + heading=false + end + @h={ head_: heading, cols: cols, widths: col, idx: idx } + elsif t_o=~/^[`]{3}\s+table(?:~h)?\s+c\d+/ + @@flag[:table]=:tics + @rows='' + case t_o + when /^[`]{3}\s+table~h\s+c(\d+);\s+(.+)/ + cols=$1 + col=$2.scan(/\d+/) + heading=true + when /^[`]{3}\s+table\s+c(\d+);\s+(.+)/ + cols=$1 + col=$2.scan(/\d+/) + heading=false + end + @h={ head_: heading, cols: cols, widths: col, idx: idx } + elsif t_o=~/^\{table(?:~h)?(?:\s+\d+;?)?\}\n.+\Z/m + m1,m2,hd=nil,nil,nil + tbl=/^\{table(?:~h)?(?:\s+\d+;?)?\}\n(.+)\Z/m.match(t_o)[1] + hd=((t_o =~/^\{table~h/) ? true : false) + tbl,tags=extract_tags(tbl) + rws=tbl.split(/\n/) + rows='' + cols=nil + rws.each do |r| + cols=(cols ? cols : (r.scan('|').length) +1) + r=r.gsub(/\s*\|\s*/m,"#{Mx[:tc_p]}") #r.gsub!(/\|/m,"#{Mx[:tc_p]}") + rows += r + Mx[:tc_c] + end + col=[] + if t_o =~/^\{table(?:~h)?\s+(\d+);?\}/ #width of col 1 given as %, usually when wider than rest that are even + c1=$1.to_i + width=(100 - c1)/(cols - 1) + col=[ c1 ] + (cols - 1).times { col << width } + else #all columns of equal width + width=100.00/cols + cols.times { col << width } + end + h={ head_: hd, cols: cols, widths: col, obj: rows, idx: idx, tags: tags } + t_o=SiSU_AO_DocumentStructure::ObjectTable.new.table(h) unless h.nil? + tuned_file << t_o + h={ obj: 'table end' } #introduce a counter + t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h) + t_o + elsif t_o=~/^[`]{3}\s+table(?:~h)?\s+/ + m1,m2,hd=nil,nil,nil + h=case t_o + when /^[`]{3}\s+table~h\s+(.+?)\n(.+)\Z/m #two table representations should be consolidated as one + m1,tbl,hd=$1,$2,true + when /^[`]{3}\s+table\s+(.+?)\n(.+)\Z/m #two table representations should be consolidated as one + m1,tbl,hd=$1,$2,false + else nil + end + tbl,tags=extract_tags(tbl) + col=m1.scan(/\d+/) + rws=tbl.split(/\n/) + rows='' + rws.each do |r| + r=r.gsub(/\s*\|\s*/m,"#{Mx[:tc_p]}") #r.gsub!(/\|/m,"#{Mx[:tc_p]}") + rows += r + Mx[:tc_c] + end + h={ head_: hd, cols: col.length, widths: col, obj: rows, idx: idx, tags: tags } + t_o=SiSU_AO_DocumentStructure::ObjectTable.new.table(h) unless h.nil? + tuned_file << t_o + h={ obj: 'table end' } #introduce a counter + t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h) + t_o + elsif t_o=~/^\{table(?:~h)?\s+/ + m1,m2,hd=nil,nil,nil + h=case t_o + when /\{table~h\s+(.+?)\}\n(.+)\Z/m #two table representations should be consolidated as one + m1,tbl,hd=$1,$2,true + when /\{table\s+(.+?)\}\n(.+)\Z/m #two table representations should be consolidated as one + m1,tbl,hd=$1,$2,false + else nil + end + tbl,tags=extract_tags(tbl) + col=m1.scan(/\d+/) + rws=tbl.split(/\n/) + rows='' + rws.each do |r| + r=r.gsub(/\s*\|\s*/m,"#{Mx[:tc_p]}") #r.gsub!(/\|/m,"#{Mx[:tc_p]}") + rows += r + Mx[:tc_c] + end + h={ head_: hd, cols: col.length, widths: col, obj: rows, idx: idx, tags: tags } + t_o=SiSU_AO_DocumentStructure::ObjectTable.new.table(h) unless h.nil? + tuned_file << t_o + h={ obj: 'table end' } #introduce a counter + t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h) + t_o + end + end + t_o + end + if @@flag[:table]==:curls or @@flag[:table]==:tics + if (@@flag[:table]==:curls \ + and t_o =~/^\}table/) \ + or (@@flag[:table]==:tics \ + and t_o =~/^[`]{3}(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/) + @@flag[:table]=:off + headings,columns,widths,idx=@h[:head_],@h[:cols],@h[:widths],@h[:idx] + @h={ head_: headings, cols: columns, widths: widths, idx: idx, obj: @rows } + t_o=SiSU_AO_DocumentStructure::ObjectTable.new.table(@h) + tuned_file << t_o + @h,@rows=nil,'' + h={ obj: 'table end' } #introduce a counter + t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h) + t_o + else + if t_o.is_a?(String) \ + and t_o !~/^(?:table\{|[`]{3}\s+table)/ + t_o=t_o.gsub(/^\n+/m,''). #check added for ruby 1.9.2 not needed in 1.8 series (tested in v2) + gsub(/\n+/m,"#{Mx[:tc_p]}") + @rows += t_o + Mx[:tc_c] + end + t_o=nil + end + end + if @@flag[:code]==:curls or @@flag[:code]==:tics + if (@@flag[:code]==:curls and t_o =~/^\}code/) \ + or (@@flag[:code]==:tics and t_o =~/^[`]{3}(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/) + @@flag[:code]=:off + obj=@tuned_code.join("\n") + tags=[] + h={ obj: obj, tags: tags, number_: @codeblock_numbered } + t_o=SiSU_AO_DocumentStructure::ObjectBlockTxt.new.code(h) + @tuned_code=[] + tuned_file << t_o + h={ obj: 'code block end' } #introduce a counter + t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h) + end + if (@@flag[:code]==:curls or @@flag[:code]==:tics) \ + and t_o.is_a?(String) + sub_array=t_o.dup + "#{Mx[:br_nl]}" + @line_mode=[] + sub_array.scan(/.+/) {|w| @line_mode << w if w =~/[\S]+/} + t_o=SiSU_AO_DocumentStructureExtract::Build.new(@md,@line_mode).build_lines(:code).join + @tuned_code << t_o + t_o=nil + end + elsif (@@flag[:poem]==:curls or @@flag[:poem]==:tics) \ + or (@@flag[:group]==:curls or @@flag[:group]==:tics) \ + or (@@flag[:block]==:curls or @@flag[:block]==:tics) \ + or (@@flag[:alt]==:curls or @@flag[:alt]==:tics) + if (@@flag[:poem]==:curls and t_o =~/^\}poem/) \ + or (@@flag[:poem]==:tics and t_o =~/^[`]{3}(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/) + @@flag[:poem]=:off + h={ obj: 'poem end' } #introduce a counter + t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h) + elsif (@@flag[:group]==:curls and t_o =~/^\}group/) \ + or (@@flag[:group]==:tics and t_o =~/^[`]{3}(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/) + @@flag[:group]=:off + obj,tags=extract_tags(@tuned_block.join("\n")) + h={ obj: obj, tags: tags } + @tuned_block=[] + t_o=SiSU_AO_DocumentStructure::ObjectBlockTxt.new.group(h) + tuned_file << t_o + h={ obj: 'group text end' } #introduce a counter + t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h) + elsif (@@flag[:block]==:curls and t_o =~/^\}block/) \ + or (@@flag[:block]==:tics and t_o =~/^[`]{3}(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/) + @@flag[:block]=:off + obj,tags=extract_tags(@tuned_block.join("\n")) + h={ obj: obj, tags: tags } + @tuned_block=[] + t_o=SiSU_AO_DocumentStructure::ObjectBlockTxt.new.block(h) + tuned_file << t_o + h={ obj: 'block text end' } #introduce a counter + t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h) + elsif (@@flag[:alt]==:curls and t_o =~/^\}alt/) \ + or (@@flag[:alt]==:tics and t_o =~/^[`]{3}(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/) + @@flag[:alt]=:off + obj,tags=extract_tags(@tuned_block.join("\n")) + h={ obj: obj, tags: tags } + t_o=SiSU_AO_DocumentStructure::ObjectBlockTxt.new.alt(h) + @tuned_block=[] + tuned_file << t_o + h={ obj: 'alt text end' } #introduce a counter + t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h) + end + if (@@flag[:poem]==:curls or @@flag[:poem]==:tics \ + or @@flag[:group]==:curls or @@flag[:group]==:tics \ + or @@flag[:alt]==:curls or @@flag[:alt]==:tics) \ + and t_o =~/\S/ \ + and t_o !~/^(?:\}(?:verse|code|alt|group|block)|(?:verse|code|alt|group|block)\{)/ \ + and t_o !~/^[`]{3}\s+(?:code|poem|alt|group|block)|^[`]{3}(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/ # fix logic + sub_array=t_o.dup + @line_mode=sub_array.scan(/.+/) + type=if @@flag[:poem]==:curls or @@flag[:poem]==:tics + t_o=SiSU_AO_DocumentStructureExtract::Build.new(@md,@line_mode).build_lines(type).join + poem=t_o.split(/\n\n/) + poem.each do |v| + v=v.gsub(/\n/m,"#{Mx[:br_nl]}\n") + obj,tags=extract_tags(v) + h={ obj: obj, tags: tags } + t_o=SiSU_AO_DocumentStructure::ObjectBlockTxt.new.verse(h) + tuned_file << t_o + end + :poem + else :group + end + end + @verse_count+=1 if @@flag[:poem]==:curls or @@flag[:poem]==:tics + end + if @@flag[:code]==:off + if @@flag[:poem]==:curls or @@flag[:poem]==:tics \ + or @@flag[:group]==:curls or @@flag[:group]==:tics \ + or @@flag[:alt]==:curls or @@flag[:alt]==:tics + if t_o.is_a?(String) + t_o=t_o.gsub(/\n/m,"#{Mx[:br_nl]}"). + gsub(/[ ][ ]/m,"#{Mx[:nbsp]*2}"). + gsub(/#{Mx[:nbsp]}\s/,"#{Mx[:nbsp]*2}") + t_o=t_o + Mx[:br_nl] if t_o =~/\S+/ + elsif t_o.is==:group \ + || t_o.is==:block \ + || t_o.is==:alt \ + || t_o.is==:verse + t_o.obj=t_o.obj.gsub(/\n/m,"#{Mx[:br_nl]}"). + gsub(/[ ][ ]/m,"#{Mx[:nbsp]*2}"). + gsub(/#{Mx[:nbsp]}\s/,"#{Mx[:nbsp]*2}") + end + @tuned_block << t_o if t_o =~/\S+/ + else tuned_file << t_o + end + else tuned_file << t_o + end + end + if @md.flag_endnotes + tuned_file << @pb + h={ ln: 2, lc: 2, obj: 'Endnotes', autonum_: false } + tuned_file << SiSU_AO_DocumentStructure::ObjectHeading.new.heading_insert(h) + h={ ln: 4, lc: 3, obj: 'Endnotes', name: 'endnotes', autonum_: false } + tuned_file << SiSU_AO_DocumentStructure::ObjectHeading.new.heading_insert(h) + h={ obj: 'Endnotes' } + end + if @md.book_idx + tuned_file << @pb + h={ ln: 2, lc: 2, obj: 'Index', autonum_: false } + tuned_file << SiSU_AO_DocumentStructure::ObjectHeading.new.heading_insert(h) + h={ ln: 4, lc: 3, obj: 'Index', name: 'book_index', autonum_: false } + tuned_file << SiSU_AO_DocumentStructure::ObjectHeading.new.heading_insert(h) + h={ obj: 'Index' } + end + tuned_file << @pb + h={ ln: 2, lc: 2, obj: 'Metadata', autonum_: false, ocn_: false } + tuned_file << SiSU_AO_DocumentStructure::ObjectHeading.new.heading_insert(h) + h={ ln: 4, lc: 3, obj: 'SiSU Metadata, document information', name: 'metadata', autonum_: false, ocn_: false } + tuned_file << SiSU_AO_DocumentStructure::ObjectHeading.new.heading_insert(h) + h={ obj: 'eof' } + meta=SiSU_AO_DocumentStructure::ObjectMetadata.new.metadata(@metadata) + [tuned_file,meta] + end + def table_rows_and_columns_array(table_str) + table=[] + table_str.split(/#{Mx[:tc_c]}/).each do |table_row| + table_row_with_columns=table_row.split(/#{Mx[:tc_p]}/) + table << table_row_with_columns + end + table + end + def meta_heading(h) + h={ lv: h[:lv], ln: h[:ln], name: h[:name], obj: h[:obj], ocn: '0' } + SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h) + end + def meta_para(str) + h={ obj: str, ocn_: false } + SiSU_AO_DocumentStructure::ObjectPara.new.paragraph(h) + end + def build_lines(type=:none) + lines,lines_new=@data,[] + lines.each do |line| + line=if line =~/\S/ \ + and line !~/^(?:code\{|\}code)/ \ + and line !~/^(?:[`]{3}\s+code|[`]{3}(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$)/ \ + and not line.is_a?(Hash) #watch + @@counter+=1 if @@flag[:code]==:curls or @@flag[:code]==:tics + line=line.gsub(/\s\s/,"#{Mx[:nbsp]*2}"). + gsub(/#{Mx[:nbsp]}\s/,"#{Mx[:nbsp]*2}") + line=line.gsub(/^/,"#{Mx[:gr_o]}codeline#{Mx[:gr_c]}") if type==:code # REMOVE try sort for texpdf special case + line=if line =~/(?:https?|file|ftp):\/\/\S+$/ + line.gsub(/\s*$/," #{Mx[:br_nl]}") + else line.gsub(/\s*$/,"#{Mx[:br_nl]}") #unless type=='code' + end + elsif line =~/^\s*$/ + line.gsub(/\s*$/,"#{Mx[:br_nl]}") + else line + end + lines_new << line + end + lines_new + end + end + class Structure # this must happen early + def initialize(md,dob) + @md,@dob=md,dob + end + def structure + structure_markup + @dob + end + def structure_markup #build structure where structure provided only in meta header + @dob=if @dob.is==:para \ + && (((@dob.hang !~/[1-9]/) && (@dob.indent !~/[1-9]/)) \ + || (@dob.hang != @dob.indent)) \ + and not @dob.bullet_ + @dob=case @dob.obj + when /^#{@md.lv1}/ + h={ lv: 'A', ln: 1 } + SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h,@dob) + when /^#{@md.lv2}/ + h={ lv: 'B', ln: 2 } + SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h,@dob) + when /^#{@md.lv3}/ + h={ lv: 'C', ln: 3 } + SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h,@dob) + when /^#{@md.lv4}/ + h={ lv: '1', ln: 4 } + SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h,@dob) + when /^#{@md.lv5}/ + h={ lv: '2', ln: 5 } + SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h,@dob) + when /^#{@md.lv6}/ + h={ lv: '3', ln: 6 } + SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h,@dob) + else @dob + end + else @dob + end + @dob + end + end + class OCN + def initialize(md,data) + @md,@data=md,data + end + def structure_info + def lv + %w[0 A~ B~ C~ 1 2 3] + end + def possible_parents(child) + case child + when /A~/ + 'none' + when /B~/ + 'A~' + when /C~/ + 'B~' + when /1/ + 'A~, B~, C~' + when /2/ + '1' + when /3/ + '3' + end + end + def possible_children(parent) + case parent + when /A~/ + 'B~, 1' + when /B~/ + 'C~, 1' + when /C~/ + '1' + when /1/ + '2' + when /2/ + '3' + when /3/ + 'none' + end + end + self + end + def document_structure_check_info(node,node_parent,status=:ok) + node_ln=/^([0-6])/.match(node)[1].to_i + node_parent_ln=/^([0-6])/.match(node_parent)[1].to_i + if status==:error \ + or @md.opt.act[:maintenance][:set]==:on + puts %{node: #{node}, parent node: #{node_parent} #{status.upcase}} + if status==:error + node_ln=/^([0-6])/.match(node)[1].to_i + node_parent_ln=/^([0-6])/.match(node_parent)[1].to_i + puts %{current level: #{structure_info.lv[node_ln]} (possible parent levels: #{structure_info.possible_parents(structure_info.lv[node_ln])}) +parent level: #{structure_info.lv[node_parent_ln]} (possible child levels: #{structure_info.possible_children(structure_info.lv[node_parent_ln])}) +-- } + end + end + end + def warning_incorrect_parent_level_or_level(txt) + puts %{warning, +#{txt} +has incorrect level and/or parent level} + end + def ocn #and auto segment numbering increment + data=@data + @o_array=[] + node=ocn=ocn_dv=ocn_sp=ocnh=ocnh1=ocnh2=ocnh3=ocnh4=ocnh5=ocnh6=ocno=ocnp=ocnt=ocnc=ocng=ocni=ocnu=0 # h heading, o other, t table, g group, i image + regex_exclude_ocn_and_node = /#{Rx[:meta]}|^@\S+?:\s|^4~endnotes|^#{Mx[:lv_o]}4:endnotes#{Mx[:lv_c]}|^\^~ |<:e[:_]\d+?>|^<:\#|<:- |<[:!]!4|
+ if dob.is==:heading + ln=case dob.lv + when 'A'; 1 + when 'B'; 2 + when 'C'; 3 + when '1'; 4 + when '2'; 5 + when '3'; 6 + when '4'; 7 + when '5'; 8 + when '6'; 9 + end + end + if not dob.obj =~/~#|-#/ + ocn+=1 + end + if dob.is==:heading \ + and (ln.to_s =~/^[1-9]/ \ + or ln.to_s =~@md.lv1 \ + or ln.to_s =~@md.lv2 \ + or ln.to_s =~@md.lv3 \ + or ln.to_s =~@md.lv4 \ + or ln.to_s =~@md.lv5 \ + or ln.to_s =~@md.lv6) + if not dob.obj =~/~#|-#/ + ocnh+=1 + end + if ln==1 \ + or ln=~@md.lv1 + if not dob.obj =~/~#|-#/ + ocn_flag=true + ocnh1+=1 #heading + node1="1:#{ocnh1};#{ocn}" + else + ocn_flag=false + node1="1:0;0" + end + document_structure_check_info(node1,node0) + @collapsed_lv1=1 + collapsed_level=@collapsed_lv1 + node,ocn_sp,parent=node1,"h#{ocnh}",node0 #FIX + elsif ln==2 \ + or ln=~@md.lv2 + if not dob.obj =~/~#|-#/ + ocn_flag=true + ocnh2+=1 + node2="2:#{ocnh2};#{ocn}" + else + ocn_flag=false + node2="2:0;0" + end + parent=if node1 + document_structure_check_info(node2,node1) + @collapsed_lv2=@collapsed_lv1+1 + node1 + else + document_structure_check_info(node2,node0,:error) + node0 + end + collapsed_level=@collapsed_lv2 + node,ocn_sp=node2,"h#{ocnh}" + elsif ln==3 \ + or ln=~@md.lv3 + if not dob.obj =~/~#|-#/ + ocn_flag=true + ocnh3+=1 + node3="3:#{ocnh3};#{ocn}" + else + ocn_flag=false + node3="3:0;0" + end + parent=if node2 + document_structure_check_info(node3,node2) + @collapsed_lv3=@collapsed_lv2+1 + node2 + elsif node1 + warning_incorrect_parent_level_or_level(dob.obj) + puts %{parent is :A~ & this level #{dob.lv} +either parent should be level :B~ +or this level should be level :B~ rather than #{dob.lv}} + document_structure_check_info(node3,node1,:error) + @collapsed_lv3=@collapsed_lv1+1 + node1 + else + document_structure_check_info(node3,node0,:error) + warning_incorrect_parent_level_or_level(dob.obj) + node0 + end + collapsed_level=@collapsed_lv3 + node,ocn_sp=node3,"h#{ocnh}" + elsif ln==4 \ + or ln=~@md.lv4 + if not dob.obj =~/~#|-#/ + ocn_flag=true + ocnh4+=1 + node4="4:#{ocnh4};#{ocn}" + else + ocn_flag=false + node4="4:0;0" + end + parent=if node3 + document_structure_check_info(node4,node3) + @collapsed_lv4=@collapsed_lv3+1 + node3 + elsif node2 + document_structure_check_info(node4,node2) + @collapsed_lv4=@collapsed_lv2+1 + node2 + elsif node1 + document_structure_check_info(node4,node1) + @collapsed_lv4=@collapsed_lv1+1 + node1 + else + warning_incorrect_parent_level_or_level(dob.obj) + document_structure_check_info(node4,node0,:error) + node0 + end + collapsed_level=@collapsed_lv4 + node,ocn_sp=node4,"h#{ocnh}" + elsif ln==5 \ + or ln=~@md.lv5 + if not dob.obj =~/~#|-#/ + ocn_flag=true + ocnh5+=1 + node5="5:#{ocnh5};#{ocn}" + else + ocn_flag=false + node5="5:0;0" + end + parent=if node4 + document_structure_check_info(node5,node4) + @collapsed_lv5=@collapsed_lv4+1 + node4 + elsif node3 + warning_incorrect_parent_level_or_level(dob.obj) + document_structure_check_info(node5,node3,:error) + @collapsed_lv5=@collapsed_lv3+1 + node3 + elsif node2 + warning_incorrect_parent_level_or_level(dob.obj) + document_structure_check_info(node5,node2,:error) + @collapsed_lv5=@collapsed_lv2+1 + node2 + elsif node1 + warning_incorrect_parent_level_or_level(dob.obj) + document_structure_check_info(node5,node1,:error) + @collapsed_lv5=@collapsed_lv1+1 + node1 + else + document_structure_check_info(node5,node0,:error) + node0 + end + collapsed_level=@collapsed_lv5 + node,ocn_sp=node5,"h#{ocnh}" + elsif ln==6 \ + or ln=~@md.lv6 + if not dob.obj =~/~#|-#/ + ocn_flag=true + ocnh6+=1 + node6="6:#{ocnh6};#{ocn}" + else + ocn_flag=false + node6="6:0;0" + end + parent=if node5 + document_structure_check_info(node6,node5) + @collapsed_lv6=@collapsed_lv5+1 + node5 + elsif node4 + warning_incorrect_parent_level_or_level(dob.obj) + puts "parent is level 4~ & this level #{dob.lv} +either parent should be level 5~ +or this level should be 5~ rather #{dob.lv}" #level 6 + document_structure_check_info(node6,node4,:error) + @collapsed_lv6=@collapsed_lv4+1 + node4 + elsif node3 + warning_incorrect_parent_level_or_level(dob.obj) + document_structure_check_info(node6,node3,:error) + @collapsed_lv6=@collapsed_lv3+1 + node3 + elsif node2 + warning_incorrect_parent_level_or_level(dob.obj) + document_structure_check_info(node6,node2,:error) + @collapsed_lv6=@collapsed_lv2+1 + node2 + elsif node1 + warning_incorrect_parent_level_or_level(dob.obj) + document_structure_check_info(node6,node1,:error) + @collapsed_lv6=@collapsed_lv1+1 + node1 + else + document_structure_check_info(node6,node0,:error) + node0 + end + collapsed_level=@collapsed_lv6 + node,ocn_sp=node6,"h#{ocnh}" + end + else + if not dob.obj =~/~#|-#/ + ocn_flag=true + else + ocn_flag=false + end + ocno+=1 + if dob.is==:table + ocnt+=1 + ocn_sp,parent="t#{ocnt}",node + elsif dob.is==:code + ocnc+=1 + ocn_sp,parent="c#{ocnc}",node + elsif dob.is==:group \ + || dob.is==:block \ + || dob.is==:alt \ + || dob.is==:verse + ocng+=1 #group, poem + ocn_sp,parent="g#{ocng}",node + elsif dob.is==:image #check + ocni+=1 + ocn_sp,parent="i#{ocni}",node + else ocnp+=1 #paragraph + ocn_sp,parent="p#{ocnp}",node + end + end + if dob.is==:heading + if ocn_flag==true + dob.ln,dob.node,dob.ocn,dob.ocn_,dob.odv,dob.osp,dob.parent,dob.lc=ln,node,ocn,ocn_flag,ocn_dv,ocn_sp,parent,collapsed_level + else + ocnu+=1 + dob.obj=dob.obj.gsub(/#{Mx[:fa_o]}[~-]##{Mx[:fa_c]}/,'') if dob.obj + ocn_dv,ocn_sp="u#{ocnu}","u#{ocnu}" + dob.ln,dob.node,dob.ocn,dob.ocn_,dob.odv,dob.osp,dob.parent,dob.lc=ln,node,nil,ocn_flag,ocn_dv,ocn_sp,parent,collapsed_level + end + else + if dob.of !=:meta \ + && dob.of !=:comment \ + && dob.of !=:layout + if ocn_flag == true + dob.ocn,dob.ocn_,dob.odv,dob.osp,dob.parent=ocn,ocn_flag,ocn_dv,ocn_sp,parent + else + ocnu+=1 + dob.obj=dob.obj.gsub(/#{Mx[:fa_o]}[~-]##{Mx[:fa_c]}/,'') if dob.obj + ocn_dv,ocn_sp="u#{ocnu}","u#{ocnu}" + dob.ocn,dob.ocn_,dob.odv,dob.osp,dob.parent=nil,ocn_flag,ocn_dv,ocn_sp,parent + end + end + end + h + elsif dob.obj=~/#{Mx[:pa_non_object_no_heading]}/ + dob.obj=dob.obj.gsub(/#{Mx[:pa_non_object_no_heading]}/,'') + if dob.is==:para + h={ obj: dob.obj, ocn_: false, ocn: nil, hang: dob.hang, indent: dob.indent, bullet_: dob.bullet_, tags: dob.tags, parent: dob.parent } + dob=SiSU_AO_DocumentStructure::ObjectPara.new.paragraph(h,dob) + elsif dob.is==:heading + h={ obj: dob.obj, ocn_: false, ocn: nil, toc_: true, parent: dob.parent } + dob=SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h,dob) + end + elsif dob.obj=~/#{Mx[:pa_non_object_dummy_heading]}/ + dob.obj=dob.obj.gsub(/#{Mx[:pa_non_object_dummy_heading]}/,'') + if dob.is==:para + h={ obj: dob.obj, ocn_: false, ocn: nil, hang: dob.hang, indent: dob.indent, bullet_: dob.bullet_, tags: dob.tags, parent: dob.parent } + dob=SiSU_AO_DocumentStructure::ObjectPara.new.paragraph(h,dob) + elsif dob.is==:heading + h={ obj: dob.obj, ocn_: false, ocn: nil, toc_: false, parent: dob.parent } + dob=SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h,dob) + end + else dob + end + if dob.is==:code \ + || dob.is==:verse \ + || dob.is==:alt \ + || dob.is==:group \ + || dob.is==:block + dob.obj=dob.obj.gsub(/\n\n/,"\n") #newlines taken out + end + @o_array << dob + end + @o_array + end + end + class XML + def initialize(md,data) + @data,@md=data,md + end + def dom + @s=['0', + 'A', + 'B', + 'C', + '1', + '2', + '3' + ] + @sp=' ' + tuned_file=structure_build + tuned_file + end + def structure_build + data=@data + tuned_file=[] + hs=[0,false,false,false] + t={ lv: @s[0], status: 'open' } + tuned_file << tags(t) + if @md.opt.act[:verbose_plus][:set]==:on + puts "\nXML sisu structure outline --->\n" + puts "<#{@s[0]}>" + end + data.each_with_index do |o,i| + if o.is==:heading \ + || o.is==:heading_insert + case o.ln + when 1 + tuned_file << tag_close(o.ln,hs) + tuned_file << tag_open(o,@s) + if @md.opt.act[:verbose_plus][:set]==:on + puts_tag_close(o.ln,hs) + puts_tag_open(o,@s) + end + hs=[1,true,false,false] + when 2 + tuned_file << tag_close(o.ln,hs) + tuned_file << tag_open(o,@s) + if @md.opt.act[:verbose_plus][:set]==:on + puts_tag_close(o.ln,hs) + puts_tag_open(o,@s) + end + hs=[2,true,true,false] + when 3 + tuned_file << tag_close(o.ln,hs) + tuned_file << tag_open(o,@s) + if @md.opt.act[:verbose_plus][:set]==:on + puts_tag_close(o.ln,hs) + puts_tag_open(o,@s) + end + hs=[3,true,true,true] + when 4 + tuned_file << tag_close(o.ln,hs) + tuned_file << tag_open(o,@s) + if @md.opt.act[:verbose_plus][:set]==:on + puts_tag_close(o.ln,hs) + puts_tag_open(o,@s) + end + hs[0]=4 + when 5 + tuned_file << tag_close(o.ln,hs) + tuned_file << tag_open(o,@s) + if @md.opt.act[:verbose_plus][:set]==:on + puts_tag_close(o.ln,hs) + puts_tag_open(o,@s) + end + hs[0]=5 + when 6 + tuned_file << tag_close(o.ln,hs) + tuned_file << tag_open(o,@s) + if @md.opt.act[:verbose_plus][:set]==:on + puts_tag_close(o.ln,hs) + puts_tag_open(o,@s) + end + hs[0]=6 + end + end + tuned_file << o + end + if @md.opt.act[:verbose_plus][:set]==:on + puts_tag_close(0,hs) + end + tuned_file << tag_close(0,hs) + tuned_file=tuned_file.flatten + end + def tags(o) + tag=(o[:status]=='open') \ + ? %{<#{o[:lv]} id="#{o[:node]}">} + : "" + ln=case o[:lv] + when 'A'; 1 + when 'B'; 2 + when 'C'; 3 + when '1'; 4 + when '2'; 5 + when '3'; 6 + when '4'; 7 + when '5'; 8 + when '6'; 9 + end + h={ tag: tag, node: o[:node], lv: o[:lv], ln: ln, status: o[:status] } + SiSU_AO_DocumentStructure::ObjectStructure.new.xml_dom(h) #downstream code utilise else ignore like comments + end + def tag_open(o,tag) + t={ lv: tag[o.ln], node: o.node, status: 'open' } + t_o=tags(t) + t_o + end + def tag_close(lev,hs) + ary=[] + case hs[0] + when 1 + if (lev <= 1) and hs[1] + t={ lv: @s[1], status: 'close' } + ary << tags(t) + end + if (lev==0) + t={ lv: @s[0], status: 'close' } + ary << tags(t) + end + when 2 + if (lev <= 2) and hs[2] + t={ lv: @s[2], status: 'close' } + ary << tags(t) + end + if (lev <= 1) and hs[1] + t={ lv: @s[1], status: 'close' } + ary << tags(t) + end + if (lev==0) + t={ lv: @s[0], status: 'close' } + ary << tags(t) + end + when 3 + if (lev <= 3) and hs[3] + t={ lv: @s[3], status: 'close' } + ary << tags(t) + end + if (lev <= 2) and hs[2] + t={ lv: @s[2], status: 'close' } + ary << tags(t) + end + if (lev <= 1) and hs[1] + t={ lv: @s[1], status: 'close' } + ary << tags(t) + end + if (lev==0) + t={ lv: @s[0], status: 'close' } + ary << tags(t) + end + when 4 + if (lev <= 4) + t={ lv: @s[4], status: 'close' } + ary << tags(t) + end + if (lev <= 3) and hs[3] + t={ lv: @s[3], status: 'close' } + ary << tags(t) + end + if (lev <= 2) and hs[2] + t={ lv: @s[2], status: 'close' } + ary << tags(t) + end + if (lev <= 1) and hs[1] + t={ lv: @s[1], status: 'close' } + ary << tags(t) + end + if (lev==0) + t={ lv: @s[0], status: 'close' } + ary << tags(t) + end + when 5 + if (lev <= 5) + t={ lv: @s[5], status: 'close' } + ary << tags(t) + end + if (lev <= 4) + t={ lv: @s[4], status: 'close' } + ary << tags(t) + end + if (lev <= 3) and hs[3] + t={ lv: @s[3], status: 'close' } + ary << tags(t) + end + if (lev <= 2) and hs[2] + t={ lv: @s[2], status: 'close' } + ary << tags(t) + end + if (lev <= 1) and hs[1] + t={ lv: @s[1], status: 'close' } + ary << tags(t) + end + if (lev==0) + t={ lv: @s[0], status: 'close' } + ary << tags(t) + end + when 6 + if (lev <= 6) + t={ lv: @s[6], status: 'close' } + ary << tags(t) + end + if (lev <= 5) + t={ lv: @s[5], status: 'close' } + ary << tags(t) + end + if (lev <= 4) + t={ lv: @s[4], status: 'close' } + ary << tags(t) + end + if (lev <= 3) and hs[3] + t={ lv: @s[3], status: 'close' } + ary << tags(t) + end + if (lev <= 2) and hs[2] + t={ lv: @s[2], status: 'close' } + ary << tags(t) + end + if (lev <= 1) and hs[1] + t={ lv: @s[1], status: 'close' } + ary << tags(t) + end + if (lev==0) + t={ lv: @s[0], status: 'close' } + ary << tags(t) + end + end + ary + end + def puts_tag_open(o,tag) + puts %{#{@sp*o.ln}<#{tag[o.ln]} id="#{o.node}">} + end + def puts_tag_close(lev,hs) + case hs[0] + when 1 + puts "#{@sp*1}" if (lev <= 1) and hs[1] + puts "" if (lev==0) + when 2 + puts "#{@sp*2}" if (lev <= 2) and hs[2] + puts "#{@sp*1}" if (lev <= 1) and hs[1] + puts "" if (lev==0) + when 3 + puts "#{@sp*3}" if (lev <= 3) and hs[3] + puts "#{@sp*2}" if (lev <= 2) and hs[2] + puts "#{@sp*1}" if (lev <= 1) and hs[1] + puts "" if (lev==0) + when 4 + puts "#{@sp*4}" if (lev <= 4) + puts "#{@sp*3}" if (lev <= 3) and hs[3] + puts "#{@sp*2}" if (lev <= 2) and hs[2] + puts "#{@sp*1}" if (lev <= 1) and hs[1] + puts "" if (lev==0) + when 5 + puts "#{@sp*5}" if (lev <= 5) + puts "#{@sp*4}" if (lev <= 4) + puts "#{@sp*3}" if (lev <= 3) and hs[3] + puts "#{@sp*2}" if (lev <= 2) and hs[2] + puts "#{@sp*1}" if (lev <= 1) and hs[1] + puts "" if (lev==0) + when 6 + puts "#{@sp*6}" if (lev <= 6) + puts "#{@sp*5}" if (lev <= 5) + puts "#{@sp*4}" if (lev <= 4) + puts "#{@sp*3}" if (lev <= 3) and hs[3] + puts "#{@sp*2}" if (lev <= 2) and hs[2] + puts "#{@sp*1}" if (lev <= 1) and hs[1] + puts "" if (lev==0) + end + end + end +end +__END__ diff --git a/lib/sisu/v5/ao_endnotes.rb b/lib/sisu/v5/ao_endnotes.rb new file mode 100644 index 00000000..981c97f6 --- /dev/null +++ b/lib/sisu/v5/ao_endnotes.rb @@ -0,0 +1,128 @@ +# 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: system environment, resource control and configuration details + +=end +module SiSU_AO_Endnotes + class Endnotes + def initialize(md,data,endnote_array=nil) + @md,@data,@endnote_array=md,data,endnote_array + @endnote_counter,@endnote_counter_asterisk,@endnote_counter_dag=1,1,1 + end + def endnotes + data=@data + @tuned_file=[] + endnote_ref=1 + data.each do |dob| + # manually numbered endnotes --> + if @md.opt.mod.inspect =~/--no-asterisk|--no-annotate/ + dob.obj=dob.obj.gsub(/#{Mx[:en_b_o]}\s.+?#{Mx[:en_b_c]}/,'') + end + if @md.opt.mod.inspect =~/--no-dagger|--no-annotate/ + dob.obj=dob.obj.gsub(/#{Mx[:en_b_o]}[+]\s.+?#{Mx[:en_b_c]}/,'') + end + if (defined? dob.obj) \ + && (defined? dob.is) \ + && dob.is !=:code + case dob.obj # auto-numbered endnotes --> + when /#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}[*+]\s+.+?#{Mx[:en_b_c]}/ + dob.obj=dob.obj.gsub(/\s*(#{Mx[:en_a_c]}|#{Mx[:en_b_c]})/,'\1') + word_mode=dob.obj.scan(/\S+/m) + word_mode=endnote_call_number(word_mode) + dob.obj=word_mode.join(' ') + endnote_ref+=1 + when /~\^(?:\s|$)|<:e>/ #%note inserts endnotes previously gathered from /^(|[-~]\{{3})/ (in earlier loop) + word_mode=dob.obj.scan(/\S+/m) + word_mode=endnote_call_number(word_mode) + dob.obj=word_mode.join(' ') + endnote_ref+=1 + end + end + @tuned_file << dob + end + @endnote_counter,@endnote_counter_asterisk,@endnote_counter_dag=1,1,1 + @tuned_file=@tuned_file.flatten + end + def endnote_call_number(words) + words.each do |word| + case word + when /#{Mx[:en_a_o]}/ + unless word =~/#{Mx[:en_a_o]}[*+]+/ + word.gsub!(/#{Mx[:en_a_o]}/,"#{Mx[:en_a_o]}#{@endnote_counter} ") + @endnote_counter+=1 + end + when /#{Mx[:en_b_o]}/ + if word =~/#{Mx[:en_b_o]}[+]/ + word.gsub!(/#{Mx[:en_b_o]}[+]/,"#{Mx[:en_b_o]}\+#{@endnote_counter_dag} ") + @endnote_counter_dag+=1 + else + word.gsub!(/#{Mx[:en_b_o]}[*]?/,"#{Mx[:en_b_o]}\*#{@endnote_counter_asterisk} ") + @endnote_counter_asterisk+=1 + end + when /~\^|<:e>/ + if @endnote_array + word.gsub!(/~\^|<:e>/,"#{@endnote_array[@endnote_counter-1]}") + @endnote_counter+=1 + end + end + end + end + end +end +__END__ diff --git a/lib/sisu/v5/ao_expand_insertions.rb b/lib/sisu/v5/ao_expand_insertions.rb new file mode 100644 index 00000000..44ae1f60 --- /dev/null +++ b/lib/sisu/v5/ao_expand_insertions.rb @@ -0,0 +1,450 @@ +# 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: system environment, resource control and configuration details + +=end +module SiSU_AO_Insertions + class Insertions + def initialize(md,data) + @md,@data=md,data + end + def output_filetypes_in_cmd(cmd_shortcut,lnk=nil) #make list of file types in shortcut command (as configured), e.g. when sisu -3 is used + cf_defaults=SiSU_Env::InfoProcessingFlag.new + cmd_list=case cmd_shortcut.inspect + when /0/; cf_defaults.cf_0 + when /1/; cf_defaults.cf_1 + when /2/; cf_defaults.cf_2 + when /3/; cf_defaults.cf_3 + when /4/; cf_defaults.cf_4 + when /5/; cf_defaults.cf_5 + end + file_type_names={} + file_type_names[:gen],file_type_names[:src]=[],[] + file_type_names[:gen] <<= if cmd_list =~ /y/ then "~^ { document manifest }#{lnk[:manifest]}" + end + file_type_names[:gen] <<= if cmd_list =~ /h/ then [" { html, segmented text }#{lnk[:html_toc]}"," { html, scroll, document in one }#{lnk[:html_doc]}"] + end + file_type_names[:gen] <<= if cmd_list =~ /e/ then [" { epub }#{lnk[:epub]}"] + end + file_type_names[:gen] <<= if cmd_list =~ /p/ then [" { pdf, landscape }#{lnk[:pdf_landscape]}"," { pdf, portrait }#{lnk[:pdf_portrait]}"] + end + file_type_names[:gen] <<= if cmd_list =~ /o/ then " { odf:odt, open document text }#{lnk[:odt]}" + end + file_type_names[:gen] <<= if cmd_list =~ /b/ then " { xhtml scroll }#{lnk[:xhtml]}" + end + file_type_names[:gen] <<= if cmd_list =~ /x/ then " { xml, sax }#{lnk[:xml_sax]}" + end + file_type_names[:gen] <<= if cmd_list =~ /X/ then " { xml, dom }#{lnk[:xml_dom]}" + end + file_type_names[:gen] <<= if cmd_list =~ /a/ then " { plain text utf-8 }#{lnk[:txt]}" + end + file_type_names[:gen] <<= if cmd_list =~ /g/ then 'wiki.txt' + end + file_type_names[:gen] <<= if cmd_list =~ /w/ then " { concordance }#{lnk[:html_concordance]}" + end + file_type_names[:gen] <<= if cmd_list =~ /N/ then " { dcc, document content certificate (digests) }#{lnk[:digest]}" + end + file_type_names[:src] <<= if source and cmd_shortcut =~ /s/ then " { markup source text }#{lnk[:source]}" + end + file_type_names[:src] <<= if cmd_shortcut =~ /S/ then " { markup source (zipped) pod }#{lnk[:sisupod]}" + end + file_type_names[:gen]=file_type_names[:gen].flatten + file_type_names[:src]=file_type_names[:src].flatten + file_type_names + end + def by_language(linked_doc,lng,src=nil) + @linked_doc,@lng,@src=linked_doc,lng,src + @base_path="#{@md.file.output_path.base.url}/#{lng}" + def fnh + { + fn: @linked_doc, + } + end + def path_and_file(fn,pth) + "#{@base_path}/#{pth}/#{fn}" + end + def manifest + fn=@md.file.base_filename.manifest(fnh) + path_and_file(fn,'manifest') + end + def html_toc + fn=@md.file.base_filename.html_segtoc(fnh) + "#{@base_path}/html/#{@linked_doc}/#{fn}" + end + def html_doc + fn=@md.file.base_filename.html_scroll(fnh) + path_and_file(fn,'html') + end + def html_concordance + fn=@md.file.base_filename.html_concordance + "#{@base_path}/html/#{@linked_doc}/#{fn}" + end + def epub + fn=@md.file.base_filename.epub(fnh) + path_and_file(fn,'epub') + end + def pdf_landscape + fn=@md.file.base_filename.pdf_l_a4(fnh) + path_and_file(fn,'pdf') + end + def pdf_portrait + fn=@md.file.base_filename.pdf_p_a4(fnh) + path_and_file(fn,'pdf') + end + def odt + fn=@md.file.base_filename.odt(fnh) + path_and_file(fn,'odt') + end + def xhtml + fn=@md.file.base_filename.xhtml(fnh) + path_and_file(fn,'xhtml') + end + def xml_sax + fn=@md.file.base_filename.xml_sax(fnh) + path_and_file(fn,'xml_sax') + end + def xml_dom + fn=@md.file.base_filename.xml_dom(fnh) + path_and_file(fn,'xml_dom') + end + def txt + fn=@md.file.base_filename.txt(fnh) + path_and_file(fn,'txt') + end + def digest + fn=@md.file.base_filename.hash_digest(fnh) + path_and_file(fn,'digest') + end + def source + "#{@base_path}/src/#{@src}" + end + def sisupod + "#{@base_path}/src/#{@src}.zip" + end + self + end + def by_filetype(linked_doc,lng,src=nil) + @linked_doc,@lng,@src=linked_doc,lng,src + @lc=SiSU_Env::FilenameLanguageCodeInsert.new(@md.opt,lng).language_code_insert + @base_path="#{@md.file.output_path.base.url}" + def fnh + { + fn: @linked_doc, + lng: @lc, + } + end + def path_and_file(fn,pth) + "#{@base_path}/#{pth}/#{fn}" + end + def manifest + fn=@md.file.base_filename.manifest(fnh) + path_and_file(fn,'manifest') + end + def html_toc + fn=@md.file.base_filename.html_segtoc(fnh) + path_and_file(fn,'html') + end + def html_doc + fn=@md.file.base_filename.html_scroll(fnh) + path_and_file(fn,'html') + end + def html_concordance + fn=@md.file.base_filename.html_concordance + path_and_file(fn,'html') + end + def epub + fn=@md.file.base_filename.epub(fnh) + path_and_file(fn,'epub') + end + def pdf_landscape + fn=@md.file.base_filename.pdf_l_a4(fnh) + path_and_file(fn,'pdf') + end + def pdf_portrait + fn=@md.file.base_filename.pdf_p_a4(fnh) + path_and_file(fn,'pdf') + end + def odt + fn=@md.file.base_filename.odt(fnh) + path_and_file(fn,'odt') + end + def xhtml + fn=@md.file.base_filename.xhtml(fnh) + path_and_file(fn,'xhtml') + end + def xml_sax + fn=@md.file.base_filename.xml_sax(fnh) + path_and_file(fn,'xml_sax') + end + def xml_dom + fn=@md.file.base_filename.xml_dom(fnh) + path_and_file(fn,'xml_dom') + end + def txt + fn=@md.file.base_filename.txt(fnh) + path_and_file(fn,'txt') + end + def digest + fn=@md.file.base_filename.hash_digest(fnh) + path_and_file(fn,'digest') + end + def source + "#{@base_path}/src/#{@src}" + end + def sisupod + "#{@base_path}/src/#{@src}.zip" + end + self + end + def by_filename(linked_doc,lng,src=nil) + @linked_doc,@lng,@src=linked_doc,lng,src + @lc=SiSU_Env::FilenameLanguageCodeInsert.new(@md.opt,lng).language_code_insert + @base_path="#{@md.file.output_path.base.url}/#{@linked_doc}" + def fnh + { + fn: @linked_doc, + lng: @lc, + } + end + def path_and_file(fn,pth=nil) + (pth.nil?) \ + ? "#{@base_path}/#{fn}" + : "#{@base_path}/#{pth}/#{fn}" + end + def manifest + fn=@md.file.base_filename.manifest(fnh) + path_and_file(fn) + end + def html_toc + fn=@md.file.base_filename.html_segtoc(fnh) + path_and_file(fn) + end + def html_doc + fn=@md.file.base_filename.html_scroll(fnh) + path_and_file(fn) + end + def html_concordance + fn=@md.file.base_filename.html_concordance + path_and_file(fn) + end + def epub + fn=@md.file.base_filename.epub(fnh) + path_and_file(fn,'epub') + end + def pdf_landscape + fn=@md.file.base_filename.pdf_l_a4(fnh) + path_and_file(fn) + end + def pdf_portrait + fn=@md.file.base_filename.pdf_p_a4(fnh) + path_and_file(fn) + end + def odt + fn=@md.file.base_filename.odt(fnh) + path_and_file(fn) + end + def xhtml + fn=@md.file.base_filename.xhtml(fnh) + path_and_file(fn) + end + def xml_sax + fn=@md.file.base_filename.xml_sax(fnh) + path_and_file(fn) + end + def xml_dom + fn=@md.file.base_filename.xml_dom(fnh) + path_and_file(fn) + end + def txt + fn=@md.file.base_filename.txt(fnh) + path_and_file(fn) + end + def digest + fn=@md.file.base_filename.hash_digest(fnh) + path_and_file(fn) + end + def source + "#{@base_path}/#{@src}" + end + def sisupod + "#{@base_path}/#{@src}.zip" + end + self + end + def expand_insertions? + data=@data + tuned_file,tuned_file_tmp=[],[] + codeblock_=false + data.each do |para| + codeblock_=if para =~/^(?:code\{|[`]{3}\s+code)/ + true + elsif para =~/^(?:\}code|[`]{3}(?:\s|$))/m + false + else codeblock_ + end + if para !~/^%+\s/ \ + and not codeblock_ \ + and para =~/\{(?:~\^\s+)?(.+?)\s\[(?:\d(?:[sS]*))\]\}(?:\.\.\/\S+?\/|\S+?\.ss[tm]\b)/ + manifest=nil + @u=SiSU_Env::InfoEnv.new.url + m_cmd='' + if defined? @u.remote + if /(?.+?)\{(?.+?)\s\[(?\d[sS]*)\]\}(?(?\S+?)\.ss[tm]\b)(?.*)/m =~ para + m_pre=m_pre.strip + elsif /\{(?.+?)\s\[(?\d[sS]*)\]\}(?(?\S+?)\.ss[tm]\b)(?.*)/m =~ para + end + if m_linked_doc =~ /(\S+?)\/(\S+)/ + m_linked_doc,m_linked_doc_lang=$1,$2 + else + m_linked_doc,m_linked_doc_lang=m_linked_doc,@md.opt.lng_base + end + else + puts "error, does currently support relative paths (reltive paths were removed, as had problems for citation, and was not suited to all output types should possibly reconsider) #{__FILE__} #{__LINE__}" + if /\{(?:~\^\s+)?(?.+?)\s\[(?\d[sS]*)\]\}\.\.\/(?\S+?)\/(?\s+#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]})?/ =~ para + end + end + lnk=case @md.opt.dir_structure_by + when :language + { + manifest: by_language(m_linked_doc,m_linked_doc_lang).manifest, + html_toc: by_language(m_linked_doc,m_linked_doc_lang).html_toc, + html_doc: by_language(m_linked_doc,m_linked_doc_lang).html_doc, + epub: by_language(m_linked_doc,m_linked_doc_lang).epub, + pdf_landscape: by_language(m_linked_doc,m_linked_doc_lang).pdf_landscape, + pdf_portrait: by_language(m_linked_doc,m_linked_doc_lang).pdf_landscape, + odt: by_language(m_linked_doc,m_linked_doc_lang).odt, + xhtml: by_language(m_linked_doc,m_linked_doc_lang).xhtml, + xml_sax: by_language(m_linked_doc,m_linked_doc_lang).xml_sax, + xml_dom: by_language(m_linked_doc,m_linked_doc_lang).xml_dom, + txt: by_language(m_linked_doc,m_linked_doc_lang).txt, + html_concordance: by_language(m_linked_doc,m_linked_doc_lang).html_concordance, + digest: by_language(m_linked_doc,m_linked_doc_lang).digest, + sisupod: by_language(m_linked_doc,m_linked_doc_lang,m_source).sisupod, + source: by_language(m_linked_doc,m_linked_doc_lang,m_source).source, + } + when :filetype + { + manifest: by_filetype(m_linked_doc,m_linked_doc_lang).manifest, + html_toc: by_filetype(m_linked_doc,m_linked_doc_lang).html_toc, + html_doc: by_filetype(m_linked_doc,m_linked_doc_lang).html_doc, + epub: by_filetype(m_linked_doc,m_linked_doc_lang).epub, + pdf_landscape: by_filetype(m_linked_doc,m_linked_doc_lang).pdf_landscape, + pdf_portrait: by_filetype(m_linked_doc,m_linked_doc_lang).pdf_landscape, + odt: by_filetype(m_linked_doc,m_linked_doc_lang).odt, + xhtml: by_filetype(m_linked_doc,m_linked_doc_lang).xhtml, + xml_sax: by_filetype(m_linked_doc,m_linked_doc_lang).xml_sax, + xml_dom: by_filetype(m_linked_doc,m_linked_doc_lang).xml_dom, + txt: by_filetype(m_linked_doc,m_linked_doc_lang).txt, + html_concordance: by_filetype(m_linked_doc,m_linked_doc_lang).html_concordance, + digest: by_filetype(m_linked_doc,m_linked_doc_lang).digest, + sisupod: by_filetype(m_linked_doc,m_linked_doc_lang,m_source).sisupod, + source: by_filetype(m_linked_doc,m_linked_doc_lang,m_source).source, + } + else + { + manifest: by_filename(m_linked_doc,m_linked_doc_lang).manifest, + html_toc: by_filename(m_linked_doc,m_linked_doc_lang).html_toc, + html_doc: by_filename(m_linked_doc,m_linked_doc_lang).html_doc, + epub: by_filename(m_linked_doc,m_linked_doc_lang).epub, + pdf_landscape: by_filename(m_linked_doc,m_linked_doc_lang).pdf_landscape, + pdf_portrait: by_filename(m_linked_doc,m_linked_doc_lang).pdf_landscape, + odt: by_filename(m_linked_doc,m_linked_doc_lang).odt, + xhtml: by_filename(m_linked_doc,m_linked_doc_lang).xhtml, + xml_sax: by_filename(m_linked_doc,m_linked_doc_lang).xml_sax, + xml_dom: by_filename(m_linked_doc,m_linked_doc_lang).xml_dom, + txt: by_filename(m_linked_doc,m_linked_doc_lang).txt, + html_concordance: by_filename(m_linked_doc,m_linked_doc_lang).html_concordance, + digest: by_filename(m_linked_doc,m_linked_doc_lang).digest, + sisupod: by_filename(m_linked_doc,m_linked_doc_lang,m_source).sisupod, + source: by_filename(m_linked_doc,m_linked_doc_lang,m_source).source, + } + end + linked_title="#{m_pre}{#{m_txt} }#{lnk[:manifest]}#{m_note}\n\n" + tuned_file_tmp << linked_title + output_filetypes=output_filetypes_in_cmd(m_cmd,lnk) + output_filetypes[:gen].each do |o_f| + describe = o_f + if describe + tuned_file_tmp << if @u.remote #to double space <:br> at beginning of entry + "#{Mx[:nbsp]*4} #{describe} " + else # remove ... + "[provide document placement host location]" + end + end + end + output_filetypes[:src].each do |o_f| + describe = o_f + if describe + tuned_file_tmp << if @u.remote + "#{Mx[:nbsp]*4} #{describe} " + else + "[provide document placement host location]" + end + end + end + tuned_file << 'group{' << tuned_file_tmp.join("\n") << '}group' + tuned_file_tmp=[] + else tuned_file << para + end + end + tuned_file + end + end +end +__END__ diff --git a/lib/sisu/v5/ao_hash_digest.rb b/lib/sisu/v5/ao_hash_digest.rb new file mode 100644 index 00000000..70deee80 --- /dev/null +++ b/lib/sisu/v5/ao_hash_digest.rb @@ -0,0 +1,157 @@ +# 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: system environment, resource control and configuration details + +=end +module SiSU_AO_Hash + require_relative 'shared_markup_alt.rb' #shared_markup_alt.rb + class ObjectDigest + def initialize(md,data,env=nil) + @md,@data,@env=md,data,env + @env ||=SiSU_Env::InfoEnv.new(@md.fns) + end + def object_digest + # 1. clean/stripped text without any markup, paragraph, headings etc. without endnotes + # 2. endnotes clean/stripped text digest only (there may be several endnotes within a paragraph) + # 3. whole object, text with markup and any endnotes, (question: with or without the endnote digests??? presumption better without, [however may be easier to check with?]) + # [digests should not include other digests] + data=@data.compact + @tuned_file=[] + sha_ =(@env.digest.type=='sha256' ? true : false) + sha_ ? (require 'digest/sha2') : (require 'digest/md5') + data.each do |t_o| + unless t_o.obj.is_a?(Array) + t_o.obj=t_o.obj.strip + end + if (t_o.of !=:structure \ + && t_o.of !=:comment \ + && t_o.of !=:layout) \ + && t_o.ocn.is_a?(Fixnum) + if sha_ + for hash_class in [ Digest::SHA256 ] + @tuned_file << stamped(t_o,hash_class) + end + else + for hash_class in [ Digest::MD5 ] + @tuned_file << stamped(t_o,hash_class) + end + end + else @tuned_file << t_o unless t_o.nil? + end + end + @tuned_file=@tuned_file.flatten + #use md5 or to create hash of each dal object including ocn, & add into to each dal object + end + def endnote_digest(data) + t_o_bit=[] + data.each do |en_plus| + t_o_bit <<= case en_plus + when /#{Mx[:en_a_o]}|#{Mx[:en_b_o]}/ + if en_plus =~/#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]}/ + t_o_txt,en_open,en_txt,en_close=/(.*?)(#{Mx[:en_a_o]}|#{Mx[:en_b_o]})(.+?)(#{Mx[:en_a_c]}|#{Mx[:en_b_c]})/m.match(en_plus)[1..4] + stripped_en=SiSU_TextRepresentation::Alter.new(en_txt).strip_clean_of_markup + digest_en_strip=if @env.digest.type =~/sha256/ + Digest::SHA256.hexdigest(stripped_en) + else + Digest::MD5.hexdigest(stripped_en) + end + t_o_txt + en_open + en_txt + Mx[:id_o] + digest_en_strip + Mx[:id_c] + en_close + else STDERR.puts "Error Exception - problem encountered with:\n#{en_plus}" #arbitrary exception, tidy up + end + else en_plus + end + end + t_o_bit.join + end + def stamped(t_o,hash_class) #decide what hash information is most useful, is compromise necessary? + t_o.obj=SiSU_TextRepresentation::Alter.new(t_o).strip_clean_of_extra_spaces + #SiSU_TextRepresentation::Alter.new(t_o).strip_clean_of_markup #check + #SiSU_TextRepresentation::Alter.new(t_o).semi_revert_markup #check + #SiSU_TextRepresentation::ModifiedTextPlusHashDigest.new(@md,t_o).composite.dgst #check + unless t_o.is==:code + case t_o.obj + when /#{Mx[:en_a_o]}[\d*+]+\s+.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}[*+]\d+\s+.+?#{Mx[:en_b_c]}/m + en_and_t_o_digest=[] + t_o.obj=t_o.obj.gsub(/\s*(#{Mx[:en_a_c]}|#{Mx[:en_b_c]})/m,' \1') #watch + t_o_plus_en=t_o.obj.scan(/.*?#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|.*?#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]}/m) + t_o_tail=if t_o.obj =~/(?:.*?#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|.*?#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]})+([\s\S]+)/m + /(?:.*?#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|.*?#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]})+.*/m.match(t_o.obj)[1] + else '' + end + t_o_plus_en << t_o_tail + en_and_t_o_digest << endnote_digest(t_o_plus_en) + en_and_t_o_digest.join(' ') + else #@tuned << t_o + Mx[:id_o] + digest_strip + ':' + digest_all + Mx[:id_c] unless t_o.nil? + end + else #@tuned << t_o + Mx[:id_o] + digest_strip + ':' + digest_all + Mx[:id_c] unless t_o.nil? + end + t_o #KEEP intact + end + def strip_clean_extra_spaces(s) # dal output tuned + s=s.dup + s=s.gsub(/[ ]+([,.;:?](?:$|\s))/,'\1') unless s =~/#{Mx[:en_a_o]}|#{Mx[:en_b_o]}/ + s=s.gsub(/ [ ]+/,' '). + gsub(/^ [ ]+/,''). + gsub(/ [ ]+$/,''). + gsub(/((?:#{Mx[:fa_bold_c]}|#{Mx[:fa_italics_c]})')[ ]+(s )/,'\1\2'). + gsub(/((?:#{Mx[:fa_bold_c]}|#{Mx[:fa_italics_c]})')[ ]+(s )/,'\1\2') + end + end +end +__END__ diff --git a/lib/sisu/v5/ao_idx.rb b/lib/sisu/v5/ao_idx.rb new file mode 100644 index 00000000..94e3aff6 --- /dev/null +++ b/lib/sisu/v5/ao_idx.rb @@ -0,0 +1,326 @@ +# 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: system environment, resource control and configuration details + +=end +module SiSU_AO_BookIndex + class BookIndex + def initialize(md,data,env=nil) + @md,@data,@env=md,data,env + @rgx_idx=/#{Mx[:idx_o]}(?:.+?)#{Mx[:idx_c]}\s*/ + @rgx_idx_ocn_seg=/(.+?)~(\d+)~(\S+)/ + @rgx_idx_ocn=/(.+?)~(\d+)/ + @env ||=SiSU_Env::InfoEnv.new(@md.fns) + end + def indexing_song + data=@data + data,sisu_markup_idx_rel,sisu_markup_idx_rel_html_seg,html_idx,xhtml_idx=extract_book_index(data) + data=clean_and_insert_index(data,sisu_markup_idx_rel_html_seg) + [data,sisu_markup_idx_rel,sisu_markup_idx_rel_html_seg,html_idx,xhtml_idx] + end + def extract_book_index(data) + tuned_file=[] + idx_array=[] + data.each do |dob| + if (dob.is ==:heading \ + || dob.is ==:heading_insert) \ + && dob.ln==4 + @seg=dob.name + end + if defined? dob.idx \ + and dob.idx.is_a?(Hash) + idx_array << {idx: dob.idx, ocn: dob.ocn, seg: @seg } + end + tuned_file << dob if dob + end + if idx_array.length > 0 + the_idx=construct_book_index(idx_array) + sisu_markup_idx_rel,sisu_markup_idx_rel_html_seg,html_idx,xhtml_idx=nil,nil,nil,nil + if @md.book_idx + idx=index(the_idx) + sisu_markup_idx_rel,sisu_markup_idx_rel_html_seg,html_idx,xhtml_idx=idx[:sst_rel],idx[:sst_rel_html_seg],idx[:html],idx[:xhtml] + end + end + [tuned_file,sisu_markup_idx_rel,sisu_markup_idx_rel_html_seg,html_idx,xhtml_idx] + end + def construct_book_index(idx_array) + the_idx={} + idx_array.each do |idx| + idx[:idx].each_pair do |term,term_info| + location=(term_info[:plus].to_i > 0) \ + ? (%{#{idx[:ocn]}-#{idx[:ocn].to_i + term_info[:plus].to_i}}) + : idx[:ocn].to_s + the_idx[term]={} unless the_idx[term] and defined? the_idx[term] + the_idx[term]['node_0_terms']=[] unless the_idx[term]['node_0_terms'] and defined? the_idx[term]['node_0_terms'] + the_idx[term]['node_0_terms'] << { ocn: idx[:ocn], range: location, seg: idx[:seg] } + if term_info[:sub].is_a?(Array) \ + and term_info[:sub].length > 0 + term_info[:sub].each do |y| + y.each_pair do |subterm,subterm_info| + location=(subterm_info[:plus].to_i > 0) \ + ? (%{#{idx[:ocn]}-#{idx[:ocn].to_i + subterm_info[:plus].to_i}}) + : idx[:ocn].to_s + the_idx[term]={} unless the_idx[term] and defined? the_idx[term] + the_idx[term]['node_0_terms']=[] unless the_idx[term]['node_0_terms'] and defined? the_idx[term]['node_0_terms'] + the_idx[term]['node_1_subterms']={} unless the_idx[term]['node_1_subterms'] and defined? the_idx[term]['node_1_subterms'] + the_idx[term]['node_1_subterms'][subterm]=[] unless the_idx[term]['node_1_subterms'][subterm] and defined? the_idx[term]['node_1_subterms'][subterm] + the_idx[term]['node_1_subterms'][subterm] << { ocn: idx[:ocn], range: location, seg: idx[:seg] } + end + end + end + end + end + the_idx=the_idx.sort + the_idx + end + def clean_xml(str) + str=str.gsub(/&/,'&') + str + end + def index(the_idx) + @x=1 + idx={} + idx[:sst_rel_html_seg],idx[:sst_rel],idx[:html],idx[:xhtml]=[],[],[],[] + h={obj: Mx[:br_page]} + o=SiSU_AO_DocumentStructure::ObjectLayout.new.break(h) + idx[:sst_rel_html_seg] << o + idx[:sst_rel] << o + h={lv: '2', name: 'index', obj: "Index"} + o=SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h) + idx[:sst_rel_html_seg] << o + idx[:sst_rel] << o + h={lv: '4', name: 'idx', obj: " [Index] #{Mx[:pa_non_object_dummy_heading]}"} + o=SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h) + idx[:sst_rel_html_seg] << o + idx[:sst_rel] << o + alph=%W[9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z] + idx[:html] << '

' + idx[:xhtml] << '

' + alph.each do |x| + if x =~/[0-9]/ + idx[:html] << '' + idx[:xhtml] << '' + else + idx[:html] << %{#{x},#{$ep[:hsp]}} + idx[:xhtml] << %{#{x},#{$ep[:hsp]}} + end + end + idx[:html] << '

' + idx[:xhtml] << '

' + letter=alph.shift + idx[:html] << %{\n

} + idx[:xhtml] << %{\n

0 - 9

} + the_idx.each do |i| + i.each do |x| + if x.is_a?(String) + f=/^(\S)/.match(x)[1] + if letter < f + while letter < f + if alph.length > 0 + letter=alph.shift + idx[:html] << %{\n

#{letter}

} + idx[:xhtml] << %{\n

#{letter}

} + else break + end + end + end + idx[:sst_rel_html_seg] << %{\n\n#{Mx[:fa_bold_o]}#{x},#{Mx[:fa_bold_c]} } + idx[:sst_rel] << %{\n\n#{Mx[:fa_bold_o]}#{x},#{Mx[:fa_bold_c]} } + aname=x.gsub(/\s+/,'_') + idx[:html] << %{\n

#{x}, } + c=clean_xml(x.dup) + idx[:xhtml] << %{\n

#{c}, } + @o=idx[:sst_rel_html_seg].index(idx[:sst_rel_html_seg].last) + @t=idx[:sst_rel].index(idx[:sst_rel].last) + @q=idx[:html].index(idx[:html].last) + @r=idx[:xhtml].index(idx[:xhtml].last) + print "\n" + x + ', ' if @md.opt.act[:verbose_plus][:set]==:on + elsif x.is_a?(Array) + p 'array error? -->' + print x + elsif x.is_a?(Hash) + if x['node_0_terms'].is_a?(Array) + x['node_0_terms'].each do |a| + if a[:range] + idx[:sst_rel_html_seg][@o]=idx[:sst_rel_html_seg][@o] + %{#{Mx[:lnk_o]}#{a[:range]}#{Mx[:lnk_c]}#{Mx[:rel_o]}/#{a[:seg]}.html##{a[:ocn]}#{Mx[:rel_c]}, } + idx[:sst_rel][@t]=idx[:sst_rel][@t] + %{#{Mx[:lnk_o]}#{a[:range]}#{Mx[:lnk_c]}#{Mx[:rel_o]}#{a[:ocn]}#{Mx[:rel_c]}, } + idx[:html][@q]=idx[:html][@q] + %{#{a[:range]}, } + idx[:xhtml][@q]=idx[:xhtml][@q] + %{#{a[:range]}, } + print a[:range] + ', ' if @md.opt.act[:verbose_plus][:set]==:on + elsif a[:ocn] + idx[:sst_rel_html_seg][@o]=idx[:sst_rel_html_seg][@o] + %{#{Mx[:lnk_o]}#{a[:ocn]}#{Mx[:lnk_c]}#{Mx[:rel_o]}#{a[:seg]}.html##{a[:ocn]}#{Mx[:rel_c]}, } + idx[:sst_rel][@t]=idx[:sst_rel][@t] + %{#{Mx[:lnk_o]}#{a[:ocn]}#{Mx[:lnk_c]}#{Mx[:rel_o]}#{a[:ocn]}#{Mx[:rel_c]}, } + idx[:html][@q]=idx[:html][@q] + %{#{a[:ocn]}, } + idx[:xhtml][@q]=idx[:xhtml][@q] + %{#{a[:ocn]}, } + print a[:ocn] + ', ' if @md.opt.act[:verbose_plus][:set]==:on + else p 'error' + end + end + idx[:html][@q]=idx[:html][@q] + '

' + idx[:xhtml][@r]=idx[:xhtml][@r] + '

' + end + if x['node_1_subterms'] + x['node_1_subterms'].sort.each do |k,y| + if k !~/node_0_terms/ + idx[:sst_rel_html_seg][@o]=idx[:sst_rel_html_seg][@o] + %{#{k}, } + idx[:sst_rel][@t]=idx[:sst_rel][@t] + %{#{k}, } + idx[:html][@q]=idx[:html][@q] + %{\n

#{k}, } + c=clean_xml(k.dup) + idx[:xhtml][@r]=idx[:xhtml][@r] + %{\n

#{c}, } + print "\n\t" + k + ', ' if @md.opt.act[:verbose_plus][:set]==:on + y.each do |z| + if z[:range] + idx[:sst_rel_html_seg][@o]=idx[:sst_rel_html_seg][@o] + %{#{Mx[:lnk_o]}#{z[:range]}#{Mx[:lnk_c]}#{Mx[:rel_o]}#{z[:seg]}.html##{z[:ocn]}#{Mx[:rel_c]}, } + idx[:sst_rel][@t]=idx[:sst_rel][@t] + %{#{Mx[:lnk_o]}#{z[:range]}#{Mx[:lnk_c]}#{Mx[:rel_o]}#{z[:ocn]}#{Mx[:rel_c]}, } + idx[:html][@q]=idx[:html][@q] + %{#{z[:range]}, } + idx[:xhtml][@q]=idx[:xhtml][@q] + %{#{z[:range]}, } + print z[:range] + ', ' if @md.opt.act[:verbose_plus][:set]==:on + elsif z[:ocn] + idx[:sst_rel_html_seg][@o]=idx[:sst_rel_html_seg][@o] + %{#{Mx[:lnk_o]}#{z[:ocn]}#{Mx[:lnk_c]}#{Mx[:rel_o]}#{z[:seg]}.html##{z[:ocn]}#{Mx[:rel_c]}, } + idx[:sst_rel][@t]=idx[:sst_rel][@t] + %{#{Mx[:lnk_o]}#{z[:ocn]}#{Mx[:lnk_c]}#{Mx[:rel_o]}#{z[:ocn]}#{Mx[:rel_c]}, } + idx[:html][@q]=idx[:html][@q] + %{#{z[:ocn]}, } + idx[:xhtml][@q]=idx[:xhtml][@q] + %{#{z[:ocn]}, } + print z[:ocn] + ', ' if @md.opt.act[:verbose_plus][:set]==:on + else p 'error' + end + end + idx[:html][@q]=idx[:html][@q] + '

' + idx[:xhtml][@r]=idx[:xhtml][@r] + '

' + end + end + end + @x +=1 + end + end + end + print "\n" if @md.opt.act[:verbose_plus][:set]==:on + idx + end + def screen_print(the_idx) + the_idx.each do |i| + i.each do |x| + if x.is_a?(String) + print "\n" + x + ', ' + elsif x.is_a?(Array) + p 'array error? -->' + print x + elsif x.is_a?(Hash) + if x['node_0_terms'].is_a?(Array) + x['node_0_terms'].each do |a| + if a[:range] + print a[:range] + ', ' + elsif a[:ocn] + print a[:ocn] + ', ' + else p 'error' + end + end + end + if x['node_1_subterms'] + x['node_1_subterms'].sort.each do |k,y| + if k !~/node_0_terms/ + print "\n\t" + k + ', ' + y.each do |z| + if z[:range] + print z[:range] + ', ' + elsif z[:ocn] + print z[:ocn] + ', ' + else p 'error' + end + end + end + end + end + end + end + end + end + def output_idx(idx) + if @md.book_idx + path="#{@env.path.output}/#{@md.fnb}" + Dir.mkdir(path) unless FileTest.directory?(path) + puts "#{path}/#{@md.fn[:book_idx_html]} #{__FILE__}::#{__LINE__}" + html_index_file=File.new("#{path}/#{@md.fn[:book_idx_html]}",'w') + idx[:html].each {|x| html_index_file << x } + html_index_file.close + end + end + def clean_and_insert_index(data,sisu_markup_idx) + tuned_file=[] + data.each do |dob| + tuned_file << dob + if dob.obj =~/#{Mx[:br_endnotes]}/ \ + and sisu_markup_idx + sisu_markup_idx.each do |idx| + tuned_file << idx + end + end + end + tuned_file + end + def clean_index(data) #check on use of dob + tuned_file=[] + data.each do |para| + para=para.gsub(/\n*#{@rgx_idx}/m,'') + tuned_file << para + end + tuned_file + end + end +end +__END__ diff --git a/lib/sisu/v5/ao_images.rb b/lib/sisu/v5/ao_images.rb new file mode 100644 index 00000000..4354dfa9 --- /dev/null +++ b/lib/sisu/v5/ao_images.rb @@ -0,0 +1,165 @@ +# 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: system environment, resource control and configuration details + +=end +module SiSU_AO_Images + class Images + #require 'RMagick' + #include Magick + def initialize(md,data) + @md,@data=md,data + end + def images + data=@data + tuned_file=[] + @rmgk=false + imagemagick_=true #imagemagick_=SiSU_Env::InfoSettings.new.program?('rmagick') + if imagemagick_ + begin + @rmgk=SiSU_Env::Load.new('RMagick').prog + rescue + @rmgk=false + end + else + if (@md.opt.act[:verbose][:set]==:on \ + || @md.opt.act[:verbose_plus][:set]==:on \ + || @md.opt.act[:maintenance][:set]==:on) + SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set],'*WARN* use of RMagick is not enabled in sisurc.yml').warn + end + end + data.each do |dob| + unless dob.is ==:table + dob.obj=dob.obj.strip + if dob.obj =~/#{Mx[:lnk_o]}\s*\S+\.(?:png|jpg|gif)(?:\s*|\s+.+)?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|image)/ + if dob.obj !~/#{Mx[:lnk_o]}\s*\S+\.(?:png|jpg|gif)\s+\d+x\d+/ + m=/#{Mx[:lnk_o]}\s*(\S+\.(?:png|jpg|gif))/ + if imagemagick_ + imgs=dob.obj.scan(m).flatten + img_col=img_row=nil + images=imgs.each do |image| + dir=SiSU_Env::InfoEnv.new(@md.fns) + path_image=[dir.path.image_source_include_local,dir.path.image_source_include_remote,dir.path.image_source_include] + image_path=nil + path_image.each do |img_pth| + image_path=img_pth + break if FileTest.exist?("#{img_pth}/#{image}") + end + if FileTest.exist?("#{image_path}/#{image}") + if @rmgk + img=Magick::ImageList.new("#{image_path}/#{image}") + img_col,img_row=img.columns,img.rows + else + if (@md.opt.act[:verbose][:set]==:on \ + || @md.opt.act[:verbose_plus][:set]==:on \ + || @md.opt.act[:maintenance][:set]==:on) + SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set],'*WARN* RMagick not present, will attempt to use imagemagick (identify) directly').warn + end + imgk=SiSU_Env::SystemCall.new.imagemagick + gmgk=SiSU_Env::SystemCall.new.graphicksmagick + if imgk or gmgk + if imgk + imgsys=`identify #{image_path}/#{image}`.strip #system call + elsif gmgk + imgsys=`gm identify #{image_path}/#{image}`.strip #system call + end + img_col,img_row=/(\d+)x(\d+)/m.match(imgsys)[1,2] + img_col,img_row=img_col.to_i,img_row.to_i + end + end + row=((img && defined? img.rows) ? img.rows : img_row) + col=((img && defined? img.columns) ? img.columns : img_col) + if img_col > img_row #landscape + if img_col> 640 + img_col=640 + img_row=((1.00*img_col/col)*row).round + end + else #portrait + if img_col> 640 + img_col=640 + img_row=((1.00*img_col/col)*row).round + end + if img_row > 640 + img_row=640 + img_col=((1.00*img_row/row)*col).round + end + end + dob.obj=dob.obj.gsub(/(#{image})/,"#{image} #{img_col}x#{img_row}") + else dob.obj=dob.obj.gsub(/#{Mx[:lnk_o]}\s*(\S+)\.(png|jpg|gif).+?#{Mx[:lnk_c]}(#{Mx[:url_o]}\S+?#{Mx[:url_c]}|image)/,'[ \1 (\2 missing) ]') + end + end + else + images=dob.obj.scan(m) do |image| + SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set],'*WARN* where image dimensions have not been provided RMagick or imagemagick is required',image).warn unless @md.opt.act[:quiet][:set]==:on + end + end + end + end + if dob.obj =~/#{Mx[:lnk_o]}\s*\S+\.(?:png|jpg|gif).+?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|image)/ + dob.obj=dob.obj.gsub(/(#{Mx[:lnk_o]})\s*(\S+\.(?:png|jpg|gif))\s+/i,'\1\2 ') + end + end + tuned_file << dob unless dob.nil? + end + tuned_file + end + end +end +__END__ +imgsys=`identify #{image_path}/#{image}`.strip diff --git a/lib/sisu/v5/ao_metadata.rb b/lib/sisu/v5/ao_metadata.rb new file mode 100644 index 00000000..8d017769 --- /dev/null +++ b/lib/sisu/v5/ao_metadata.rb @@ -0,0 +1,82 @@ +# 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: system environment, resource control and configuration details + +=end +module SiSU_AO_Metadata + class Metadata + def initialize(md,metad) + @md,@metadata=md,metad + l=SiSU_Env::StandardiseLanguage.new(@md.opt.lng).language + language=l[:n] + @tr=SiSU_Translate::Source.new(md,language) + end + def make_para(obj,ocn) + h={ obj: obj, ocn: 0 } + SiSU_AO_DocumentStructure::ObjectPara.new.paragraph(h) + end + def make_heading(obj,ocn,name,lv,ln) + h={ lv: lv, ln: ln, name: name, obj: obj, ocn: 0 } + SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h) + end + def metadata + end + end +end +__END__ diff --git a/lib/sisu/v5/ao_misc_arrange.rb b/lib/sisu/v5/ao_misc_arrange.rb new file mode 100644 index 00000000..8f7acbc4 --- /dev/null +++ b/lib/sisu/v5/ao_misc_arrange.rb @@ -0,0 +1,157 @@ +# 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: system environment, resource control and configuration details + +=end +module SiSU_AO_MiscArrangeText + class SI + def initialize(md,data) + @md,@data=md,data + end + def conditional_headings(para) + para=para.gsub(/^(:?A~)\s*$/,'\1~ @title @author'). #conditional header + gsub(/^((?:[1-9]|:?[A-C])~\S*)\s*$/,'\1~ [Note: heading marker::required title missing]~#') #conditional header for incorporated document 2004w12 + if para =~/^@\S+?:/ + para=para.gsub(/^@(\S+?):(\s+|$)/,"#{Mx[:meta_o]}\\1#{Mx[:meta_c]}\\2"). + gsub(/^@(\S+?):([+-])(\s+|$)/,"#{Mx[:meta_o]}\\1\\2#{Mx[:meta_c]}\\3") + end + para + end + def code_blocks(para) + def ticks(para) + block_open,block_close,text=nil,nil,nil + if para =~/\A[`]{3}\s+.+?\n.+?\n[`]{3}(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*\Z/m + block_open,text,block_close=/\A([`]{3}\s+.+?)\n(.+?)\n([`]{3}(\s+[~-][#]|\s+\~\{.+?\}\~)?)\s*\Z/m.match(para)[1..3] + ((para=~/^[`]{3}\s+table(?:~h)?\s+/) \ + and (para !~/^[`]{3}\s+table(?:~h)?\s+c\d+/)) \ + ? para + : (para=[]; para << block_open << text << block_close) + elsif para =~/\A[`]{3}\s+.+?\n.*?\Z/m #look at, study + block_open,text=/\A([`]{3}(?:\s+.+?))\n(.*?)\Z/m.match(para)[1,2] + para=[] + if not text.to_s.empty? + para << block_open << text + else + para << block_open + end + elsif para =~/\A.+?\n[`]{3}(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*\Z/m + text,block_close=/\A(.+?)\n([`]{3}(?:\s+[~-][#]|\s+\~\{.+?\}\~)?)\s*\Z/m.match(para)[1,2] + para=[] + if not text.to_s.empty? + para << text.to_s << block_close + else + para << block_close + end + else para + end + para + end + def curly_braces(para) + block_open,block_close,text=nil,nil,nil + para=if para =~/\A(?:code|poem|alt|group|block|table)\{ .+?\n.+?\n\}(?:code|poem|alt|group|block|table)(?: [~-][#])?\s*\Z/m + block_open,text,block_close=/\A((?:code|poem|alt|group|block|table)\{ .+?)\n(.+?)\n(\}(?:code|poem|alt|group|block|table)(?: [~-][#])?)\s*\Z/m.match(para)[1..3] + para=[] + para << block_open << text << block_close + elsif para =~/\A(?:code|poem|alt|group|block|table)\{ .+?\n.+?\Z/m + block_open,text=/\A((?:code|poem|alt|group|block|table)\{ .+?)\n(.+?)\Z/m.match(para)[1,2] + para=[] + if not text.to_s.empty? + para << block_open << text + else + para << block_open + end + elsif para =~/\A.+?\n\}(?:code|poem|alt|group|block|table)(?: [~-][#])?\s*\Z/m + text,block_close=/\A(.+?)\n(\}(?:code|poem|alt|group|block|table)(?: [~-][#])?)\s*\Z/m.match(para)[1,2] + para=[] + if not text.to_s.empty? + para << text.to_s << block_close + else + para << block_close + end + else para + end + para + end + para=para =~/^```/m \ + ? ticks(para) + : para + para=(para =~/^(?:code|poem|alt|group|block|table)\{|^\}(?:code|poem|alt|group|block|table)/m) \ + ? curly_braces(para) + : para + end + def prepare_text + data=@data + data_new=[],[] + if data[0] =~ /^#!\s*(?:\/usr\/bin\/env sisu|\/usr\/bin\/sisu)/ # remove bang from top #! (however file is stripped, so will be removed provided no content precedes it) + data[0]=data[0].gsub(/^#!\s*\/usr\/bin\/sisu/,''). + gsub(/^#!\s*\/usr\/bin\/env sisu/,'') + end + if data[0] =~ /^(SiSU\s+[\d.]*|sisu-[\d.]+)$/ # SiSU identifier + data[0]=data[0].gsub(/^(SiSU\s*[\d.]*)$/,'% \1'). + gsub(/^(sisu-[\d.]+)$/,'% \1') + end + data.each do |para| + para=conditional_headings(para) + data_new << code_blocks(para) + end + data_new=data_new.flatten + end + end +end +__END__ diff --git a/lib/sisu/v5/ao_numbering.rb b/lib/sisu/v5/ao_numbering.rb new file mode 100644 index 00000000..00afdfa5 --- /dev/null +++ b/lib/sisu/v5/ao_numbering.rb @@ -0,0 +1,486 @@ +# 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: system environment, resource control and configuration details + +=end +module SiSU_AO_Numbering + class Numbering + attr_accessor :obj,:osp,:ocn,:lv,:name,:index,:comment + def initialize(md,data) + @md,@data=md,data + @obj=@type=@ocn=@lv=@name=@index=@comment=nil + end + def numbering_song + data=@data + data=number_plaintext_para(data) + data=auto_number_heading_ie_title(data.compact) #tr issue + data=ocn(data.compact) #watch + data=xml(data.compact) + data=minor_numbering(data.compact) + data,tags_map,ocn_html_seg_map=name_para_seg_filename(data) + data=set_heading_top(data) unless @md.set_heading_top + [data,tags_map,ocn_html_seg_map] + end + def number_plaintext_para(data) + @tuned_file=[] + data.each do |dob| + if (dob.of !=:block \ + && dob.of !=:comment \ + && dob.of !=:layout) \ + && dob.ocn_ #and dob.obj !~ /#{Mx[:gr_o]}Th|#{Mx[:tc_o]}#{Mx[:tc_p]}#{Mx[:tc_p]}/ #FIX + dob.obj=dob.obj.gsub(/(.+)\n/,'\1 ') #messy, but idea is that tables should retain breaks + end + unless dob.obj.is_a?(Array) + dob.obj=dob.obj.gsub(/^\s+/,''). + gsub(/\s$/,"\n") + end + @tuned_file << dob + end + @tuned_file=@tuned_file.flatten + end + def number_sub_heading(dob,num,title_no) + unless dob.obj =~/\d+\.|(?:chapter|article|section|clause)\s+\d+/i #name selection arbitrary, fix + dob.obj=case dob.name + when /-/; dob.obj.gsub(/^/,"#{title_no} ") + when /^#/; dob.obj.gsub(/^/,"#{title_no} ") + when /^[a-z_\.]+/; dob.obj.gsub(/^/,"#{title_no} ") + else + dob.name=title_no if dob.name=~/^$/ #where title contains title number + dob.obj.gsub(/^/,"#{title_no} ") if title_no =~/\d+/ #main, where title number is to be provided #watch changed placement + end + if @md.toc_lev_limit \ + and @md.toc_lev_limit < num + dob.obj=dob.obj.gsub(/^/,'!_ ') #bold line, watch + end + end + dob + end + def heading_tag_clean(heading_tag) + heading_tag=heading_tag.gsub(/[ ]+/,'_'). + gsub(/["']/,''). + gsub(/[\/]/,'-'). + gsub(/#{Mx[:fa_bold_o]}|#{Mx[:fa_bold_c]}/,''). + gsub(/#{Mx[:fa_italics_o]}|#{Mx[:fa_italics_c]}/,''). + gsub(/#{Mx[:fa_underscore_o]}|#{Mx[:fa_underscore_c]}/,''). + gsub(/#{Mx[:fa_cite_o]}|#{Mx[:fa_cite_c]}/,''). + gsub(/#{Mx[:fa_insert_o]}|#{Mx[:fa_insert_c]}/,''). + gsub(/#{Mx[:fa_strike_o]}|#{Mx[:fa_strike_c]}/,''). + gsub(/#{Mx[:fa_superscript_o]}|#{Mx[:fa_superscript_c]}/,''). + gsub(/#{Mx[:fa_subscript_o]}|#{Mx[:fa_subscript_c]}/,''). + gsub(/#{Mx[:fa_hilite_o]}|#{Mx[:fa_hilite_c]}/,''). + gsub(/#{Mx[:gl_bullet]}/,'') + end + def auto_number_heading_ie_title(data) #also does some segment naming + @tuned_file=[] + if defined? @md.make.num_top \ + and @md.make.num_top \ + and @md.make.num_top !~/^$/ + input||=@md.make.num_top + end + num_top=(input ? input.to_i : nil) + t_no1=t_no2=t_no3=0 + if num_top + no1=num_top; no2=(num_top + 1); no3=(num_top + 2) + end + chapter_number_counter=0 + data=data.compact + data.each do |dob| #@md.seg_names << [additions to segment names] + title_no=nil + dob=SiSU_AO_DocumentStructureExtract::Structure.new(@md,dob).structure_markup #must happen earlier, node info etc. require + if dob.is ==:heading \ + && dob.autonum_ \ + and defined? @md.make.num_top \ + and @md.make.num_top !~/^$/ + if dob.lv=='1' \ + and dob.obj =~/^#\s|\s#(?:\s|$)/ + chapter_number_counter +=1 + dob.obj=dob.obj.gsub(/^#\s/,"#{chapter_number_counter} "). + gsub(/#([:,]?\s|[.]?$)/,"#{chapter_number_counter}\\1") + end + if dob.ln==no1 + @subnumber=1 + @subnumber=0 if dob.ln==no1 + end + if dob.ln.to_s =~/^[1-6]/ \ + and not dob.toc_ \ + and dob.obj !~/#{Mx[:fa_o]}(?:~#|-#)#{Mx[:fa_c]}/ # <-- fix + if dob.ln==no1 + t_no1+=1; t_no2=0; t_no3=0 + title_no="#{t_no1}" + if @md.seg_names.is_a?(Array) \ + and not @md.seg_names.include?(title_no) + if dob.ln==no1 + dob.name="#{title_no}" if not dob.name + dob.tags=[title_no,dob.tags].flatten if title_no !~/^\d+$/ #check whether will work across file types with stop signs + tag=dob.obj.gsub(/(Article|Clause|Section|Chapter)\s+/,"\\1_#{title_no}").downcase + tag=heading_tag_clean(tag) + dob.tags=[tag,dob.tags].flatten if tag !~/^\d+$/ #check whether will work across file types with stop signs + dob.obj=(dob.obj =~/(Article|Clause|Section)\s+/) \ + ? (dob.obj.gsub(/(Article|Clause|Section)\s+/,"\\1 #{title_no} ")) + : (dob.obj.gsub(/^/,"#{title_no}. ")) #fix stop later + end + if dob.ln !=no1 \ + and dob.obj =~/^[\d.]+\s/ #fix -> if the title starts with a numbering scheme, do not auto-number, review + dob.name ="#{title_no}" if not dob.name + dob.tags=[title_no,dob.tags].flatten if title_no !~/^\d+$/ #check whether will work across file types with stop signs + dob.obj=dob.obj.gsub(/^/,"#{title_no}. ") + end + @md.seg_names << title_no + end + if dob.ln!=no1 \ + and dob.name!~/^[a-z_\.]+$/ \ + and dob.obj !~/[A-Z]\.?\s/ #bug -> tmp fix, excludes A. B. C. lettering, but not roman numerals, is arbitrary, review required # not fixed, work on + dob.tags=[title_no,dob.tags].flatten if title_no !~/^\d+$/ #check whether will work across file types with stop signs + dob.obj=dob.obj.gsub(/^/i,"#{title_no}. ") + end + end + if dob.ln==no1 #watch because here you change dob.name + dob.tags=["h#{title_no}",dob.tags].flatten #check whether will work across file types with stop signs + end + if dob.ln==no2 #watch because here you change dob.name + t_no2+=1; t_no3=0 + title_no="#{t_no1}.#{t_no2}" + dob.tags=["h#{title_no}",dob.tags].flatten #check whether will work across file types with stop signs + dob=number_sub_heading(dob,no2,title_no) + end + if dob.ln==no3 #watch because here you change dob.name + t_no3+=1 + title_no="#{t_no1}.#{t_no2}.#{t_no3}" + dob.tags=["h#{title_no}",dob.tags].flatten #check whether will work across file types with stop signs + dob=number_sub_heading(dob,no3,title_no) + end + elsif dob.ln.to_s =~/^[1-6]/ \ + and dob.name =~ /^[\w-]+-/ # endnotes, watch2005# endnotes, watch2005 + dob.tags=[dob.name,dob.tags].flatten if dob.name !~/^\d+$/ #check whether will work across file types with stop signs + dob.name.gsub(/^([a-z_\.]+)-$/,'\1') + end + elsif dob.is ==:heading \ + and dob.autonum_ \ + and @md.markup =~/num_extract/ #AS DANGEROUS force enable with document, note already does this type of numbering for cisg, locate and coordinate logic, is currently misplaced in code, chengwei inspired 2004w23/4 + #here lies a bug, as is nil when run from -Dv --update, FIX + if (dob.name.nil? or dob.name.empty?) \ + and dob.ln.to_s =~/^[1-9]/ \ + and dob.obj =~ /^([\d\.]+)/ #risky (must be unique) consider output to 4~~\d instead of 4~\d + dob.name=$1 + dob.tags=[dob.name,dob.tags].flatten if dob.name !~/^\d+$/ #check whether will work across file types with stop signs + end + if @md.toc_lev_limit + end + elsif defined? dob.name \ + and dob.name + dob.tags=[dob.name,dob.tags].flatten if dob.name !~/^\d+$/ #check whether will work across file types with stop signs + end + dob.tags=dob.tags.uniq if defined? dob.tags + @tuned_file << dob + end + @tuned_file=@tuned_file.flatten + end + def ocn(data) #and auto segment numbering increment + @tuned_file=SiSU_AO_DocumentStructureExtract::OCN.new(@md,data).ocn + @tuned_file + end + def xml(data) + @tuned_file=SiSU_AO_DocumentStructureExtract::XML.new(@md,data).dom + @tuned_file + end + def minor_numbering(data) #and auto segment numbering increment + @tuned_file=[] + number_small,letter_small=0,0 + letter=%w( a b c d e f g h i j k l m n o p q r s t u v w x y z ) + data.each do |dob| + if dob.of ==:heading \ + || dob.of ==:heading_insert \ + || dob.of ==:para \ + || dob.of ==:block + if dob.is ==:heading \ + and dob.ln.to_s=~/^[1-9]/ #% sub-number system, (baby numbering) reset with any change of major number (more obviously should be placed in number titles, but that is conditionally executed, check and move later) + number_small,letter_small=0,0 + elsif dob.is ==:para + if dob.obj =~/^#[ 1]/ \ + and dob.obj !~/^#\s+(?:~#)?$/ + letter_small=0 + number_small=0 if dob.obj =~ /^#1/ + number_small+=1 + dob.obj=dob.obj.gsub(/^#[ 1]/,"#{number_small}. ") + end + if dob.obj =~/^_# / + dob.obj=dob.obj.gsub(/^_# /,"#{letter[letter_small]}. ") + dob.indent='1' + letter_small+=1 + end + end + end + @tuned_file << dob + end + @tuned_file=@tuned_file.flatten + end + def name_para_seg_filename(data) #segment naming, remaining + # paragraph name/numbering rules + # manual naming overrides, manual naming may be + # alpha-numeric characters mixed, + # numeric only (a number), if + # all segments have been named, + # the numbers used are over 1000 or + # it is not minded that auto-numbering uses a funny scheme for naming segments (not yet implemented) + # [for now a warning is printed for such documents on use of maintenance or very-verbose flag] + # auto-naming takes the form of giving numbers to segments + # the rules for which are as follows + # if the title/heading text starts with a numeric, then that is used (1 3.1 3rd etc.) + # otherwise the level 4 segment number from the embedded document structure info is used + # if there is none a sequential number is designated, preceded by an underscore + @tuned_file,@unique_auto_name=[],[] + tags={} + art_filename_auto=1 + @counter=1 + if not @md.seg_autoname_safe \ + and (@md.opt.act[:verbose_plus][:set]==:on \ + || @md.opt.act[:maintenance][:set]==:on) + puts 'manual segment names, numbers used as names, risk warning (segmented html)' + end + ocn_html_seg=[] + data.each do |dob| + if dob.is==:heading \ + && dob.ln \ + and dob.ln.to_s =~/^[456]/ + if dob.ln==4 \ + and not dob.name \ + and not @md.set_heading_seg + @md.set_heading_seg=true + end + if dob.name !~/^\S+/ \ + and dob.obj =~/^\s*(?:\S+\s+)?([\d.,:-]+)/m #heading starts with a recognised numeric or word followed by a recognised numerical construct, use that as name + possible_seg_name=$1 + possible_seg_name=possible_seg_name.gsub(/(?:[:,-]|\W)/,'.'). + gsub(/\.$/,'') + if @md.seg_names.is_a?(Array) \ + and not @md.seg_names.include?(possible_seg_name) + dob.name=possible_seg_name + dob.tags=[dob.name,dob.tags].flatten if dob.name !~/^\d+$/ + @md.seg_names << possible_seg_name + elsif (@md.opt.act[:verbose_plus][:set]==:on \ + or @md.opt.act[:maintenance][:set]==:on) + puts 'warn, there may be a conflicting numbering scheme' + end + end + if dob.ln==4 \ + and dob.name #extract segment name from embedded document structure info + if @md.seg_names.is_a?(Array) \ + and not @md.seg_names.include?(dob.name) + dob.tags=[dob.name,dob.tags].flatten if dob.name !~/^\d+$/ + @md.seg_names << dob.name + end + end + if dob.ln==4 \ + and not dob.name #if still no segment name, provide a numerical one + pf='_' #pg='' #may use e.g. '' or '~' or '_' + segn_auto="#{pf}#{art_filename_auto.to_s}" + if @md.seg_names.is_a?(Array) \ + and not @md.seg_names.include?(segn_auto) + dob.name=segn_auto + dob.tags=[dob.name,dob.tags].flatten if dob.name !~/^\d+$/ #check whether will work across file types with stop signs + @md.seg_names << segn_auto + else puts 'segment name (numbering) error' + end + art_filename_auto+=1 + end + if dob.ln==4 \ + and not dob.name #should not occur + puts "e r r o r -\t#{__FILE__}::#{__LINE__}\n#{dob.inspect}" + end + end + if (dob.is ==:heading \ + || dob.is ==:heading_insert) \ + && dob.ln==4 + @seg=dob.name + end + @tuned_file << if dob.is==:heading \ + && (@md.pagenew || @md.pagebreak || @md.pageline) + m=dob.ln.to_s + dob_tmp=[] + if @md.pagenew.inspect =~/#{m}/ + dob_tmp << SiSU_AO_DocumentStructure::ObjectLayout.new.break(Hx[:br_page_new]) << dob + elsif @md.pagebreak.inspect =~/#{m}/ + dob_tmp << SiSU_AO_DocumentStructure::ObjectLayout.new.break(Hx[:br_page]) << dob + elsif @md.pageline.inspect =~/#{m}/ + dob_tmp << SiSU_AO_DocumentStructure::ObjectLayout.new.break(Hx[:br_page_line]) << dob + end + unless dob_tmp.length > 0; dob + else dob_tmp + end + else dob + end + if defined? dob.ocn \ + and dob.ocn + @segname=((dob.is==:heading || dob.is==:heading_insert) && dob.ln==4 && (defined? dob.name)) \ + ? (dob.name) + : @segname + tags["#{dob.ocn}"]={ segname: @segname } + ocn_html_seg[dob.ocn]=if (dob.is==:heading || dob.is==:heading_insert) + if dob.ln =~/[1-3]/ + { seg: nil, level: dob.ln } + else #elsif dob.ln =~/[4-6]/ + { seg: @seg, level: dob.ln } + end + else + { seg: @seg, level: nil } + end + end + dob.tags=dob.tags.uniq if defined? dob.tags + if defined? dob.tags \ + and dob.tags.length > 0 + #@segname=((dob.is=='heading'|| dob.is=='heading_insert') && dob.ln==4 && (defined? dob.name)) \ + #? (dob.name) \ + #: @segname + dob.tags.each do |y| + tags[y]={ ocn: dob.ocn.to_s, segname: @segname } + end + end + dob + end + ocn_html_seg.each_with_index do |ocn,i| + if ocn \ + and ocn[:level].to_s=~/[1-3]/ + (1..4).each do |x| + if ocn_html_seg[i+x] and ocn_html_seg[i+x][:level]==4 + ocn[:seg]=ocn_html_seg[i+x][:seg] + end + end + end + end + if @md.seg_names.length > 0 + @md.set_heading_seg=true + end + tuned_file=@tuned_file.flatten + [tuned_file,tags,ocn_html_seg] + end + def set_heading_top(data) #% make sure no false positives + unless @md.set_heading_top + if (@md.opt.act[:verbose_plus][:set]==:on \ + or @md.opt.act[:maintenance][:set]==:on) + puts "\tdocument contains no top level heading, (will have to manufacture one)" + end + @tuned_file=[] + data.each do |t_o| + unless @md.set_heading_top + if t_o !~/^(?:#{Rx[:meta]}|@\S+:)\s/m \ + and t_o !~/\A\s*\Z/m + @md.set_heading_top=true + if defined? @md.title \ + and @md.title \ + and defined? @md.title.full \ + and defined? @md.creator \ + and @md.creator + head=@md.title.main ? ([@lv='1',@obj=@md.title.main]) : ([@lv='1',@obj='[no title provided]']) + @tuned_file << head + end + end + end + @tuned_file << t_o + end + @tuned_file=@tuned_file.flatten + end + end + def set_heading_seg(data) #% make sure no false positives + unless @md.set_heading_seg + if (@md.opt.act[:verbose_plus][:set]==:on \ + or @md.opt.act[:maintenance][:set]==:on) + puts "\tdocument contains no segment level, (will have to manufacture one)" + end + @tuned_file=[] + data.each do |dob| + unless @md.set_heading_seg + if defined? dob.ln and dob.ln.to_s !~/^[123]/m \ + and dob.obj !~/\A\s*\Z/m \ + and dob.is !=:layout + @md.set_heading_seg=true + head=@md.title.main \ + ? (dob.ln,dob.name,dob.obj=4,'seg',@md.title.main) + : (dob.ln,dob.name,dob.obj=4,'seg','[segment]') + @tuned_file << head + end + end + @tuned_file << dob + end + @tuned_file=@tuned_file.flatten + end + end + def set_header_title(data) #% make sure no false positives + unless @md.set_header_title + if (@md.opt.act[:verbose_plus][:set]==:on \ + or @md.opt.act[:maintenance][:set]==:on) + puts "\t no document title provided, (will have to manufacture one)" + end + @tuned_file=[] + data.each do |t_o| + unless @md.set_header_title + if t_o !~/^%{1,2}\s/m \ + and t_o !~/\A\s*\Z/m + @tuned_file << "#{Mx[:meta_o]}title#{Mx[:meta_c]} #{@md.heading_seg_first}" + @md.title.main=@md.heading_seg_first + @md.set_header_title=true + end + end + @tuned_file << t_o + end + @tuned_file=@tuned_file.flatten + end + end + end +end +__END__ diff --git a/lib/sisu/v5/ao_syntax.rb b/lib/sisu/v5/ao_syntax.rb new file mode 100644 index 00000000..22e0124c --- /dev/null +++ b/lib/sisu/v5/ao_syntax.rb @@ -0,0 +1,631 @@ +# 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: Syntax for markup, input markup syntaxes, determined here + +=end +module SiSU_AO_Syntax + class Words + def initialize(line,md,mkp) + @line,@md,@mkp=line,md,mkp + end + end + class Markup + def initialize(md='',data='') + @md,@data=md,data + @vz=SiSU_Viz::Defaults.new + @data_new=[] + url_and_stub=SiSU_Env::InfoEnv.new.url + @output_url="#{url_and_stub.remote}" + @env=SiSU_Env::InfoEnv.new + emph_set=if defined? @md.emphasis_set_to \ + and not @md.emphasis_set_to.nil? + @md.emphasis_set_to + else @env.markup_emphasis + end + @emph=case emph_set + when /bold/ + emph_italics=false + { o: Mx[:fa_bold_o], c: Mx[:fa_bold_c] } + when /italics/ + emph_italics=true + { o: Mx[:fa_italics_o], c: Mx[:fa_italics_c] } + when /underscore/ + emph_italics=false + { o: Mx[:fa_underscore_o], c: Mx[:fa_underscore_c] } + else p __LINE__.to_s + '::' + __FILE__ + end + @http_m=%r{\{.+?\}https?://\S+|https?:\S+|:\S+|\.\.\/\S+|#\S+|\S+?\.png\b|[*]~\S+|^#{Mx[:meta_o]}.+|#{Mx[:gr_o]}(?:code|block|group|alt|verse)(?:-end)?#{Mx[:gr_c]}|#{Mx[:fa_o]}:br#{Mx[:fa_c]}} + @manmkp_ital=emph_italics \ + ? '[i/*]\\{.+?\\}[i/*]' + : '[i/]\\{.+?\\}[i/]' + tail_m_ital=%q{(?:\s|[.,;:?!'")]|~\^|~\\\{\s|$)} + tail_m_bold=%{(?:(?:#{Mx[:fa_italics_c]})?(?:\s|[.,;:?!'")]|~\^|~\\\{\s|$))?} + bold_line=%{^!_\s.+?(?:#{Mx[:br_line]}|\n|$)} + #ital_line=%{^/_\s.+?(?:#{Mx[:br_line]}|\n|$)} #not implemented + @line_scan_ital=if defined? @md.italics_match_list[:str] + /#{@http_m}|#{bold_line}|#{@manmkp_ital}#{tail_m_ital}|#{@md.italics_match_list[:str]}#{tail_m_ital}|\S+|\n/i + elsif defined? @vz.markup_make_italic[:str] + /#{@http_m}|#{bold_line}|#{@manmkp_ital}#{tail_m_ital}|#{@vz.markup_make_italic[:str]}#{tail_m_ital}|\S+|\n/i + end + @manmkp_bold=emph_italics \ + ? '^!_\s.+?(?:\n|$)|[!b]\\{.+?\\}[*!b]|[*!][a-zA-Z0-9\-_]+[!]' + : '^!_\s.+?(?:\n|$)|[*!b]\\{.+?\\}[*!b]|[*!][a-zA-Z0-9\-_]+[*!]' + @line_scan_bold=if (defined? @md.bold_match_list[:str] \ + and @md.bold_match_list[:str]) \ + and (defined? @vz.markup_make_bold[:str] \ + and @vz.markup_make_bold[:str]) + /#{@http_m}|#{bold_line}|(?:#{@manmkp_bold}|#{@md.bold_match_list[:str]}|#{@vz.markup_make_bold[:str]})#{tail_m_bold}|\S+|\n/i + elsif defined? @md.bold_match_list[:str] \ + and @md.bold_match_list[:str] + /#{@http_m}|#{bold_line}|(?:#{@manmkp_bold}|#{@md.bold_match_list[:str]})#{tail_m_bold}|\S+|\n/i + elsif defined? @vz.markup_make_bold[:str] \ + and @vz.markup_make_bold[:str] + /#{@http_m}|#{bold_line}|(?:#{@manmkp_bold}|#{@vz.markup_make_bold[:str]})#{tail_m_bold}|\S+|\n/i + end + end + def songsheet + @data=@data.compact + @data.each do |dob| + dob=breaks(dob) + dob=if @md.sem_tag then sem(dob) else dob end #revisit + dob=line_actions(dob) + dob=paragraph_set(dob) + dob=substitutions(dob) + dob=wordlist_italics(dob) + dob=wordlist_bold(dob) + dob=bodymarkup(dob) + @data_new << dob unless dob.nil? + end + @data_new + end + def sem(dob) #revisit + dob=SiSU_Sem::Tags.new(dob,@md).rm.all + end + def breaks(dob) + if dob.is !=:meta \ + && dob.is !=:comment \ + && dob.is !=:code \ + && dob.is !=:table + dob.obj=dob.obj.gsub(/^-\\\\-\s*$/,"#{Mx[:br_page]}"). + gsub(/^=\\\\=\s*$/,"#{Mx[:br_page_new]}"). + gsub(/ \\\\(?: |$)/,"#{Mx[:br_line]}"). + gsub(/(?:<:?pb>)/,"#{Mx[:br_page]}"). # depreciated + gsub(/(?:<:?pn>)/,"#{Mx[:br_page_new]}"). # depreciated + gsub(/(?:<:?br>|
)/,"#{Mx[:br_line]}"). # depreciated + gsub(/(?:^-\.\.-\s*$)/,"#{Mx[:br_page_line]}") + end + dob + end + def wordlist_italics(dob) + dob=dob.dup + if (defined? @md.italics_match_list[:str] \ + and @md.italics_match_list[:str]) \ + or (defined? @vz.markup_make_italic[:str] \ + and @vz.markup_make_italic[:str]) + dob.obj=if dob.is !=:meta \ + && dob.is !=:heading \ + && dob.is !=:heading_insert \ + && dob.is !=:code \ + && dob.is !=:comment + word=dob.obj.scan(@line_scan_ital) + word=word.flatten.compact + line_array=[] + word.each do |w| + unless /#{@manmkp_ital}|#{@http_m}/.match(w) + if defined? @md.italics_match_list[:regx] \ + and @md.italics_match_list[:regx] + w=w.gsub(@md.italics_match_list[:regx], + "#{Mx[:fa_italics_o]}\\1#{Mx[:fa_italics_c]}") + elsif defined? @vz.markup_make_italic \ + and @vz.markup_make_italic + w=w.gsub(@vz.markup_make_italic, + "#{Mx[:fa_italics_o]}\\1#{Mx[:fa_italics_c]}") + else w + end + end + line_array << w + end + line_array.join(' ') + else dob.obj + end + end + dob + end + def embolden(given) + given=given.gsub(/^!_\s+((?:\{|#{Mx[:lnk_o]})(?:~^ )?.+?(?:\}|#{Mx[:lnk_o]})https?:\/\/\S+.*?)([#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:br_nl]}])/, + "#{Mx[:fa_bold_o]} \\1 #{Mx[:fa_bold_c]}\\2"). + gsub(/^!_\s+((?:\{|#{Mx[:lnk_o]})(?:~^ )?.+?(?:\}|#{Mx[:lnk_o]})https?:\/\/\S+.*)/, + "#{Mx[:fa_bold_o]} \\1 #{Mx[:fa_bold_c]}"). + gsub(/(?:^!_|^#{Mx[:lv_o]}[7-9]:\S*?#{Mx[:lv_c]})\s*(.+?)([#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:br_nl]}])/, + "#{Mx[:fa_bold_o]}\\1#{Mx[:fa_bold_c]}\\2"). + gsub(/(?:^!_|^#{Mx[:lv_o]}[7-9]:\S*?#{Mx[:lv_c]})\s*(.+?)\s+((?:[*]~\S+\s*)+)/, + "#{Mx[:fa_bold_o]}\\1#{Mx[:fa_bold_c]}\\2"). + gsub(/(?:^!_|^#{Mx[:lv_o]}[7-9]:\S*?#{Mx[:lv_c]})\s*(.+?)\s*([~-]#)$/, + "#{Mx[:fa_bold_o]}\\1#{Mx[:fa_bold_c]}\\2"). + gsub(/(?:^!_\s+|^#{Mx[:lv_o]}[7-9]:\S*?#{Mx[:lv_c]}\s*)(.*)?\s*$/, + "#{Mx[:fa_bold_o]}\\1#{Mx[:fa_bold_c]}") + end + def italicise(given) + given=given.gsub(/^\/_\s*(.+?)([#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:br_nl]}])/, + "#{Mx[:fa_italics_o]}\\1#{Mx[:fa_italics_c]}\\2"). + gsub(/^\/_\s*(.+?)\s+((?:[*]~\S+\s*)+)/, + "#{Mx[:fa_italics_o]}\\1#{Mx[:fa_italics_c]}\\2"). + gsub(/^\/_\s*(.+?)\s*([~-]#)$/, + "#{Mx[:fa_italics_o]}\\1#{Mx[:fa_italics_c]}\\2"). + gsub(/^\/_\s+(.*)?\s*$/, + "#{Mx[:fa_italics_o]}\\1#{Mx[:fa_italics_c]}") + end + def line_actions(dob) + dob.obj=if (dob.is !=:heading \ + && dob.is !=:heading_insert \ + && dob.is !=:comment \ + && dob.is !=:meta) \ + and dob.obj =~ /^!_\s+/ + embolden(dob.obj) + elsif dob.obj =~ /^\/_\s+/ + italicise(dob.obj) + else dob.obj + end + dob + end + def paragraph_set(dob) + dob.obj=if dob.is !=:meta \ + && dob.is !=:heading \ + && dob.is !=:heading_insert \ + && dob.is !=:code \ + && dob.is !=:comment \ + && dob.is !=:table + dob.obj.gsub(/\n/m,' '). + gsub(/ \s+/m,' ') + else dob.obj + end + dob + end + def substitutions(dob) + dob=dob.dup + dob=if defined? @md.substitution_match_list[:match_and_replace] \ + and @md.substitution_match_list[:match_and_replace].is_a?(Array) + dob=if dob.is !=:meta \ + && dob.is !=:heading_insert \ + && dob.is !=:code \ + && dob.is !=:comment \ + && dob.is !=:table + if dob.obj =~/#{@md.substitution_match_list[:matches]}/ + @md.substitution_match_list[:match_and_replace].each do |x| + dob.obj=if x[:case_s]==:i + dob.obj.gsub(/#{x[:match]}/mi,x[:replace]) + else + dob.obj.gsub(/#{x[:match]}/m,x[:replace]) + end + end + end + dob + else dob + end + dob + else dob + end + end + def wordlist_bold(dob) + dob=dob.dup + if (defined? @md.bold_match_list[:str] \ + and @md.bold_match_list[:str]) \ + or (defined? @vz.markup_make_bold[:str] \ + and @vz.markup_make_bold[:str]) + dob.obj=if dob.is !=:meta \ + && dob.is !=:heading \ + && dob.is !=:heading_insert \ + && dob.is !=:code \ + && dob.is !=:comment \ + && dob.is !=:table + line_array=[] + word=dob.obj.scan(@line_scan_bold) + word=word.flatten.compact + word.each do |w| + unless /#{@manmkp_bold}|#{@http_m}/.match(w) + if defined? @md.bold_match_list[:regx] \ + and @md.bold_match_list[:regx] #document header: @bold: [bold word list] + w=w.gsub(@md.bold_match_list[:regx],"#{Mx[:fa_bold_o]}\\1#{Mx[:fa_bold_c]}") + elsif defined? @vz.markup_make_bold \ + and @vz.markup_make_bold #defaults adjusted bold word list + w=w.gsub(@vz.markup_make_bold,"#{Mx[:fa_bold_o]}\\1#{Mx[:fa_bold_c]}") + end + else + w=if w =~ /(?:^!_|^#{Mx[:lv_o]}[7-9]:\S*?#{Mx[:lv_c]})\s+/ + embolden(w) #bold paragraph/emphasize #may wish to remove think about 7{ 8{ conversion not satisfactory, as information is lost! + elsif w =~/^\/_\s+/ + italicise(w) + else w + end + end + line_array << w + end + line_array.join(' ') + else dob.obj + end + else + dob.obj=if dob.is==:heading \ + and dob.ln.to_s =~/[7-9]/ + embolden(dob.obj) + else dob.obj + end + end + dob + end + def fontface_lines(dob,leader) + while (dob.obj =~/#{Mx[:br_nl]}/ \ + and dob.obj =~/(?:#{leader})([*!\/_#])\{(.+?)\}\1/m) \ + and $2 =~/#{Mx[:br_nl]}/ + dob=if dob.obj =~/#{Mx[:br_nl]}/ \ + and dob.obj =~/(#{leader})([*!\/_#])\{(.+?)\}\2/m + lead,fce,txt=$1,$2,$3 + dob=if txt =~/#{Mx[:br_nl]}/ + lead_break=if dob.obj =~/^#{Mx[:br_nl]}/ + dob.obj=dob.obj.sub(/^#{Mx[:br_nl]}/,'') + Mx[:br_nl] + else '' + end + txt="#{lead_break}#{fce}\{" + txt.split(Mx[:br_nl]).join("\}#{fce}#{Mx[:br_nl]}#{fce}\{") + "\}#{fce}" + dob.obj=dob.obj.sub(/(?:^|#{Mx[:gl_c]}|\s+|['"]|[#{Mx[:nbsp]}#{Mx[:fa_o_c]}#{Mx[:fa_c]}#{Mx[:lnk_o]}#{Mx[:br_nl]}#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:tc_c]}#{Mx[:tc_p]}]|[\(\[\{]|\>)([*!\/_#])\{.+?\}\1/m,"#{lead}#{txt}") + dob + else dob + end + end + dob + end + dob + end + def fontface(dob) + leader=/^|#{Mx[:gl_c]}|\s+|['"]|[#{Mx[:nbsp]}#{Mx[:fa_o_c]}#{Mx[:fa_c]}#{Mx[:lnk_o]}#{Mx[:br_nl]}#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:tc_c]}#{Mx[:tc_p]}]|[\(\[\{]|[、。]|\>/ + dob=fontface_lines(dob,leader) + dob.obj=dob.obj.gsub(/(#{leader})\*\{(.+?)\}\*/m, + "\\1#{@emph[:o]}\\2#{@emph[:c]}"). #emphasis + gsub(/(#{leader})!\{(.+?)\}!/m, + "\\1#{Mx[:fa_bold_o]}\\2#{Mx[:fa_bold_c]}"). #bold + gsub(/(#{leader})\/\{(.+?)\}\//m, + "\\1#{Mx[:fa_italics_o]}\\2#{Mx[:fa_italics_c]}"). #italics + gsub(/(#{leader})_\{(.+?)\}_/m, + "\\1#{Mx[:fa_underscore_o]}\\2#{Mx[:fa_underscore_c]}"). #underscore + gsub(/(#{leader})#\{(.+?)\}#/m, + "\\1#{Mx[:fa_monospace_o]}\\2#{Mx[:fa_monospace_c]}"). #monospace + gsub(/(^|#{Mx[:gl_c]}|\s+|['"]|[#{Mx[:nbsp]}#{Mx[:fa_o_c]}#{Mx[:fa_c]}]|\(|\>)\"\{(.+?)\}\"/m, + "\\1#{Mx[:fa_cite_o]}\\2#{Mx[:fa_c_o]}cite#{Mx[:fa_c]}"). #cite /blockquote? + gsub(/(^|[^\\])\^\{(.+?)\}\^/m, + "\\1#{Mx[:fa_superscript_o]}\\2#{Mx[:fa_superscript_c]}"). #superscript + gsub(/(^|[^\\]),\{(.+?)\},/m, + "\\1#{Mx[:fa_subscript_o]}\\2#{Mx[:fa_subscript_c]}"). #subscript + gsub(/(^|#{Mx[:gl_c]}|\s+|['"]|#{Mx[:nbsp]}|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)\+\{(.+?)\}\+/m, + "\\1#{Mx[:fa_insert_o]}\\2#{Mx[:fa_insert_c]}"). #inserted text + gsub(/(^|#{Mx[:gl_c]}|\s+|['"]|#{Mx[:nbsp]}|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)-\{(.+?)\}-/m, + "\\1#{Mx[:fa_strike_o]}\\2#{Mx[:fa_strike_c]}"). #strikethrough - deleted text + gsub(/(^|#{Mx[:gl_c]}|\s+|['"]|#{Mx[:nbsp]}|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>|\d+)\^(\S+?)\^/, + "\\1#{Mx[:fa_superscript_o]}\\2#{Mx[:fa_superscript_c]}") #superscript single word, watch digit added + dob + end + def bodymarkup(dob) + # << http://www.jus.uio.no/sisu/sisu_markup_table/markup >> + # See: data/sisu/sample/document_samples_sisu_markup/ + ## fontface + # *{emphasis}* e{emphasis}e emphasis + # !{bold text}! b{bold}b bold text + # _{underline}_ u{underline}u underline + # /{italics}/ i{italics}i italics + # "{citation}" c{citation}c citation #blockquote? + # ^{superscript}^ superscript + # ,{subscript}, subscript + # +{inserted text}+ inserted text + # -{deleted text}- deleted text + # #{monospace text}# + # + # {url address}:url + # {image.png}imageurl + # {image.png}png + # ~{endnote}~ + # !_ #bold/emphasise paragraph + # _" #blockquote paragraph + # _1 <:i1> #indent paragraph 1 step + # _2 <:i2> #indent paragraph 2 steps + # _3 <:i3> #indent paragraph 3 steps + # _4 <:i4> #indent paragraph 4 steps + # _* #bullet (list) ● + # _1* #bullet (list) indented + # _1* #bullet (list) indented + # # #numbered (list) level 1 + # _# #numbered (list) level 2 + dob=dob.dup + if dob.is !=:meta \ + && dob.is !=:comment \ + && dob.is !=:code \ + && dob.is !=:table + line_array=[] + word=dob.obj.scan(/\S+|\n/) #unless line =~/^(?:#{Mx[:meta_o]}|%+\s)/ #visit + if word + word.each do |w| # _ - / # | : ! ^ ~ + unless w =~/~\{|\}~|~\[|\]~|^\^~|~\^|\*~\S+|~#|\{t?~|\{table|https?:\/\/\S+/ # do something earlier about table!! + w=w.gsub(/\\?~/,"#{Mx[:gl_o]}#126#{Mx[:gl_c]}") #escaped special character + end + w=w.gsub(/^\<$/,"#{Mx[:gl_o]}#lt#{Mx[:gl_c]}").gsub(/^\>$/,"#{Mx[:gl_o]}#gt#{Mx[:gl_c]}") #escaped special character + line_array << w + end + dob.obj=line_array.join(' ') + dob.obj=dob.obj.strip + end + dob.obj=dob.obj.gsub(/^([*#-.]{1,12})$/,'\1 ~#'). #ocn off for these paragraph separators + gsub(/~\{(.+?)\}~/m,Mx[:en_a_o] + '\1' + Mx[:en_a_c]). + gsub(/~\[([^*+].+?)\]~/m,Mx[:en_b_o] + '* \1' + Mx[:en_b_c]). #default if markup does not specify + gsub(/~\[(.+?)\]~/m,Mx[:en_b_o] + '\1' + Mx[:en_b_c]) + if dob.is ==:heading \ + and dob.ln ==1 + dob.obj=dob.obj.gsub(/\s*@title\b/," #{@md.title.full}") + dob.obj=if defined? @md.creator.author \ + and @md.creator.author + dob.obj.gsub(/\s+(?:@creator|@author)/,",#{Mx[:br_line]}#{@md.creator.author}") + else dob.obj.gsub(/\s+(?:@creator|@author)/,'') + end + end + if defined? @md.title \ + and @md.title \ + and defined? @md.title.full \ + and defined? @md.creator \ + and @md.creator + if dob.is ==:heading + dob.obj=dob.obj.gsub(/^\s*@title\s*$/,@md.title.full) if dob.lv =~/1/ + dob.obj=if dob.lv =~/[23]/ \ + and defined? @md.creator.author \ + and @md.creator.author + dob.obj.gsub(/^\s*(?:(by\s+)?(?:@creator|@author))\s*$/,"\\1#{@md.creator.author}") + else dob.obj.gsub(/^\s*(?:(by\s+)?(?:@creator|@author))\s*$/,'\1') + end + end + end + dob.obj=dob.obj.gsub(/<(https?:\/\/\S+?)>/,'< \1 >'). #catch problem markup + gsub(/<:=(\S+?)>/,'{ c_\1.png 14x14 }image'). + gsub(//,'<:\1>'). #escaped special character + gsub(/ /,"#{Mx[:nbsp]}"). #escaped special character + gsub(/\\~/,"#{Mx[:gl_o]}#126#{Mx[:gl_c]}"). #escaped special character + gsub(/\\\{/,"#{Mx[:gl_o]}#123#{Mx[:gl_c]}"). #escaped special character + gsub(/\\\}/,"#{Mx[:gl_o]}#125#{Mx[:gl_c]}"). #escaped special character + gsub(/\\\<>/,"#{Mx[:gl_o]}#gt#{Mx[:gl_c]}#{Mx[:gl_o]}#gt#{Mx[:gl_c]}"). #escaped special character + gsub(/\\\/,"#{Mx[:gl_o]}#gt#{Mx[:gl_c]}"). #escaped special character + gsub(/\\\_/,"#{Mx[:gl_o]}#095#{Mx[:gl_c]}"). #escaped special character + gsub(/\\\-/,"#{Mx[:gl_o]}#045#{Mx[:gl_c]}"). #escaped special character + gsub(/\\\+/,"#{Mx[:gl_o]}#043#{Mx[:gl_c]}"). #escaped special character + gsub(/\\\//,"#{Mx[:gl_o]}#047#{Mx[:gl_c]}"). #escaped special character + gsub(/\\\#/,"#{Mx[:gl_o]}#035#{Mx[:gl_c]}"). #escaped special character + gsub(/\\\&/,"#{Mx[:gl_o]}#038#{Mx[:gl_c]}"). #& #escaped special character + gsub(/\\\|/,"#{Mx[:gl_o]}#124#{Mx[:gl_c]}"). #not really a sisu special character but made available as possibility + gsub(/\\\:/,"#{Mx[:gl_o]}#058#{Mx[:gl_c]}"). #not really a sisu special character but made available as possibility + gsub(/\\\!/,"#{Mx[:gl_o]}#033#{Mx[:gl_c]}"). #not really a sisu special character but made available as possibility + gsub(/\\\^/,"#{Mx[:gl_o]}#094#{Mx[:gl_c]}"). #not really a sisu special character but made available as possibility + gsub(/\\\,/,"#{Mx[:gl_o]}#044#{Mx[:gl_c]}"). #not really a sisu special character but made available as possibility + gsub(/\\\\/,"#{Mx[:gl_o]}#092#{Mx[:gl_c]}"). #escaped special character + gsub(/\\\*/,"#{Mx[:gl_o]}#042#{Mx[:gl_c]}"). #escaped special character + gsub(/\\\!/,"#{Mx[:gl_o]}#033#{Mx[:gl_c]}") #escaped special character + if dob.obj=~/(?:https?:|ftp:|\{([^{}]+?)\}(?:#|:|[.]{1,2}\/))\S+/m + if dob.obj=~/(?:^|[#{Mx[:gl_c]}#{Mx[:nbsp]} ])\{~\^ (?:.+?)\s*\}(?:(?:https?:|ftp:|:|[.]{1,2}\/)\S+?)\s*#{Mx[:en_a_o]}(.+?)#{Mx[:en_a_c]}/m + dob.obj=dob.obj.gsub(/(^|[#{Mx[:gl_c]}#{Mx[:nbsp]} ])\{~\^ ([^}]+?)\s*\}((?:https?:|ftp:|:|[.]{1,2}\/)\S+?)\s*#{Mx[:en_a_o]}(.+?)#{Mx[:en_a_c]}/m, + "\\1#{Mx[:lnk_o]}\\2#{Mx[:lnk_c]}\\3 #{Mx[:en_a_o]}\\3 \\4#{Mx[:en_a_c]}") # watch + end + if dob.obj=~/(?:^|[#{Mx[:gl_c]}#{Mx[:nbsp]} ])\{~\^ (?:.+?)\s*\}(?:(?:https?:|ftp:|:|[.]{1,2}\/)\S+?)([;,.]?)(?=\s|[#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:br_nl]}]|$)/m + dob.obj=dob.obj.gsub(/(^|[#{Mx[:gl_c]}#{Mx[:nbsp]} ])\{~\^ (.+?)\s*\}((?:https?:|ftp:|:|[.]{1,2}\/)\S+?)([;,.]?)(?=\s|[#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:br_nl]}]|$)/m, + "\\1#{Mx[:lnk_o]}\\2#{Mx[:lnk_c]}\\3\\4 #{Mx[:en_a_o]}\\3#{Mx[:en_a_c]} ") + end + dob.obj=dob.obj.gsub(/(^|[^#])\{\s*([^{}]+?)\s*\}((?:https?:|:|[.]{2}\/|#)\S+?)(?=\s|[#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:br_nl]}#{Mx[:en_a_o]}#{Mx[:en_b_o]}]|$)/, + "\\1#{Mx[:lnk_o]}\\2#{Mx[:lnk_c]}\\3"). #linked (text or image, however text cannot include modified face, e.g. bold, ital, underline) + gsub(/(^|[#{Mx[:gl_c]}#{Mx[:lnk_c]}#{Mx[:en_a_o]}#{Mx[:en_b_o]}(\s])((?:https?|ftp):\/\/\S+?\.[^>< ]+?)([,.;'"]?)(?=[\s#{Mx[:en_a_c]}#{Mx[:en_b_c]}#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:br_nl]}]|$)/m, + %{\\1#{Mx[:url_o]}\\2#{Mx[:url_c]}\\3}). + gsub(/#{Mx[:lnk_c]}#(\S+?[^>< ]+?)([()\[\]]*[,.;:!?'"]{0,2})(?=[\s#{Mx[:en_a_c]}#{Mx[:en_b_c]}#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:br_nl]}]|$)/m, + %{#{Mx[:lnk_c]}#{Mx[:rel_o]}\\1#{Mx[:rel_c]}\\2}). + gsub(/#{Mx[:lnk_c]}:(\S+?[^>< ]+?)([()\[\]]*[,.;:!?'"]{0,2})(?=[\s#{Mx[:en_a_c]}#{Mx[:en_b_c]}#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:br_nl]}]|$)/m, + %{#{Mx[:lnk_c]}#{Mx[:rel_o]}:\\1#{Mx[:rel_c]}\\2}). + gsub(/#{Mx[:lnk_c]}[.]{2}\/(\S+?[^>< ]+?)([()\[\]]*[,.;:!?'"]{0,2})(?=[\s#{Mx[:en_a_c]}#{Mx[:en_b_c]}#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:br_nl]}]|$)/m, + %{#{Mx[:lnk_c]}#{Mx[:rel_o]}:\\1#{Mx[:rel_c]}\\2}) + end + if dob.obj=~/_(?:https?|ftp):\S+/m # _http://url #CHECK + dob.obj=dob.obj.gsub(/(^|[#{Mx[:gl_c]}#{Mx[:lnk_c]}#{Mx[:en_a_o]}#{Mx[:en_b_o]}(\s])(_(?:https?|ftp):\/\/\S+?\.[^>< ]+?)([,.;'"]?)(?=[\s#{Mx[:en_a_c]}#{Mx[:en_b_c]}#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:br_nl]}]|$)/m, + %{\\1#{Mx[:url_o]}\\2#{Mx[:url_c]}\\3}) + end + dob=fontface(dob) + dob.obj=dob.obj.gsub(/<[:e]\s+(.+?)!?>/, + "#{Mx[:en_a_o]}\\1#{Mx[:en_a_c]}"). #not tested + gsub(/(^|#{Mx[:br_nl]})\s*_\*\s*/, + "\\1#{Mx[:gl_bullet]}"). #bullets, shortcut + gsub(/=\{(.+?)\}/, + "#{Mx[:idx_o]}\\1#{Mx[:idx_c]}"). + gsub(/^\s*_([1-9])\*\s*/, + "#{Mx[:pa_o]}:i\\1:\\1#{Mx[:pa_c]}#{Mx[:gl_bullet]}"). #bullets, shortcut + gsub(/^\s*_([1-9])\s+/, + "#{Mx[:pa_o]}:i\\1:\\1#{Mx[:pa_c]}"). #indent + gsub(/^\s*_([1-9])!\s+(.+?)\s*$/, + "#{Mx[:pa_o]}:i\\1:\\1#{Mx[:pa_c]}#{Mx[:fa_bold_o]}\\2#{Mx[:fa_bold_c]} "). #indent bold + gsub(/^\s*__([1-9])\s+/, + "#{Mx[:pa_o]}:i0:\\1#{Mx[:pa_c]}"). #hang + gsub(/^\s*__([1-9])!\s+(.+?)\s*$/, + "#{Mx[:pa_o]}:i0:\\1#{Mx[:pa_c]}#{Mx[:fa_bold_o]}\\2#{Mx[:fa_bold_c]} "). #hangdef + gsub(/^\s*_([0-9])_([0-9])\s+/, + "#{Mx[:pa_o]}:i\\1:\\2#{Mx[:pa_c]}"). #hang + gsub(/^\s*_([0-9])_([0-9])!\s+(.+?)\s*$/, + "#{Mx[:pa_o]}:i\\1:\\2#{Mx[:pa_c]}#{Mx[:fa_bold_o]}\\3#{Mx[:fa_bold_c]} "). #hangdef + gsub(/<:hi>/,"#{Mx[:fa_hilite_o]}"). #''). # bright yellow rgb(255,255,0) pale yellow rgb(255,255,200) + gsub(/<:\/hi>/,"#{Mx[:fa_hilite_c]}"). #''). + gsub(/(#{Mx[:gr_o]}verse#{Mx[:gr_c]}.+)/m,"\\1\n"). + gsub(/[ ]+($)/,'\1'). + gsub(/\{\s*(.+?)\s*\}(https?:\S+?)([;,.]?)(?=\s|[#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:br_nl]}#{Mx[:en_a_o]}#{Mx[:en_b_o]}]|$)/, + "#{Mx[:lnk_o]}\\1#{Mx[:lnk_c]}#{Mx[:url_o]}\\2#{Mx[:url_c]}\\3"). #any remaining linked text or image + gsub(/\{\s*(.+?)\s*\}(#{Mx[:url_o]}\S+?#{Mx[:url_c]})/, + "#{Mx[:lnk_o]}\\1#{Mx[:lnk_c]}\\2"). #any remaining linked text or image + gsub(/(^|\s)([a-zA-Z0-9._-]+\@\S+?\.[a-zA-Z0-9._-]+)/,"\\1#{Mx[:url_o]}\\2#{Mx[:url_c]}"). + gsub(/(^|[ ])\{\s*(.+?)\s*\}(\S+?)([;,.]?)(?=\s|[#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:br_nl]}#{Mx[:en_a_o]}#{Mx[:en_b_o]}]|$)/, + "\\1#{Mx[:lnk_o]}\\2#{Mx[:lnk_c]}\\3\\4"). #any remaining linked text or image + gsub(/\{\s*(.+?)\s*\}#([a-zA-Z0-9][a-zA-Z0-9_-]*)([;,.]?)(?=\s|[#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:br_nl]}#{Mx[:en_a_o]}#{Mx[:en_b_o]}]|$)/, + "#{Mx[:lnk_o]}\\1#{Mx[:lnk_c]}#{Mx[:rel_o]}\\2#{Mx[:rel_c]}\\3"). #any remaining linked text or image, check need + gsub(/\{\s*(.+?)\s*\}(#{Mx[:rel_o]}\S+?#{Mx[:rel_c]})/, + "#{Mx[:lnk_o]}\\1#{Mx[:lnk_c]}\\2"). #any remaining linked text or image, check need + gsub(/\{\s*(.+?)\s*\}(image)/, + "#{Mx[:lnk_o]}\\1#{Mx[:lnk_c]}\\2") #linked image + elsif dob.is==:table + dob=fontface(dob) + elsif dob.is ==:code + dob.obj=dob.obj.gsub(/#{Mx[:meta_o]}(\S+?)#{Mx[:meta_c]}\s*/,'@\1: '). + gsub(/(^|#{Mx[:gl_c]}|\s)<(br(?: \/)?)>([\s,.]|$)/,'\1<\2>\3') #convert

back, clumsy + if dob.number_ + codeline=[] + ln=1 + dob.obj.split(/#{Mx[:gr_o]}codeline#{Mx[:gr_c]}||\n/).each_with_index do |cl,i| + unless i == 0 + cl=cl.gsub(Mx[:br_nl],'') + w=3-ln.to_s.length + cl = "#{ln}#{Mx[:nbsp]*w}#{Mx[:vline]}#{cl}#{Mx[:br_nl]}" + ln +=1 + end + codeline << cl + end + codeline= codeline.join("") + dob.obj=codeline + else + dob.obj=dob.obj.gsub(/#{Mx[:gr_o]}codeline#{Mx[:gr_c]}/,"\n") + end + dob + else # @\S+?: + end + dob + end + def tech #script markup planned to be more strict for technical documents + # *{emphasis}* e{emphasis}e emphasis + # !{bold text}! b{bold}b bold text + # _{underline}_ u{underline}u underline + # /{italics}/ i{italics}i italics + # "{citation}" c{citation}c citation + # ^{superscript}^ superscript + # ,{subscript}, subscript + # +{inserted text}+ inserted text + # -{deleted text}- deleted text + # #{monospace text}# + # {url address}:url + # {image.png}imageurl + # {image.png}png + # ~{endnote}~ + # +1 + # +2 + puts 'tech' + @data.each do |line| + line=line.gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|[\(\[]|\>)e\{(.+?)\}e/, + "\\1#{@emph[:o]}\\2#{@emph[:c]}"). #emphasis + gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|[\(\[]|\>)b\{(.+?)\}b/, + "\\1#{Mx[:fa_bold_o]}\\2#{Mx[:fa_bold_c]}"). #bold + gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|[\(\[]|\>)u\{(.+?)\}u/, + "\\1#{Mx[:fa_underscore_o]}\\2#{Mx[:fa_underscore_c]}"). #underscore + gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|[\(\[]|\>)c\{(.+?)\}c/, + "\\1#{Mx[:fa_cite_o]}\\2#{Mx[:fa_c_o]}cite#{Mx[:fa_c]}"). #cite + gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|[\(\[]|\>)i\{(.+?)\}i/, + "\\1#{Mx[:fa_italics_o]}\\2#{Mx[:fa_italics_c]}"). #italics + gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|[\(\[]|\>)!\{(.+?)\}!/, + "\\1#{Mx[:fa_bold_o]}\\2#{Mx[:fa_bold_c]}"). #bold + gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|[\(\[]|\>)\*\{(.+?)\}\*/, + "\\1#{@emph[:o]}\\2#{@emph[:c]}"). #emphasis + gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|[\(\[]|\>)_\{(.+?)\}_/, + "\\1#{Mx[:fa_underscore_o]}\\2#{Mx[:fa_underscore_c]}"). #underscore + gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|[\(\[]|\(|\>)\/\{(.+?)\}\//, + "\\1#{Mx[:fa_italics_o]}\\2#{Mx[:fa_italics_c]}"). #italics + gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)\"\{(.+?)\}\"/, + "\\1#{Mx[:fa_cite_o]}\\2#{Mx[:fa_c_o]}cite#{Mx[:fa_c]}"). + gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)\^\{(.+?)\}\^/, + "\\1#{Mx[:fa_superscript_o]}\\2#{Mx[:fa_superscript_c]}"). + gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)9\{(.+?)\}9/, + "\\1#{Mx[:fa_superscript_o]}\\2#{Mx[:fa_superscript_c]}"). + gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>),\{(.+?)\},/, + "\\1#{Mx[:fa_subscript_o]}\\2#{Mx[:fa_subscript_c]}"). + gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)6\{(.+?)\}6/, + "\\1#{Mx[:fa_subscript_o]}\\2#{Mx[:fa_subscript_c]}"). + gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)\+\{(.+?)\}\+/, + "\\1#{Mx[:fa_insert_o]}\\2#{Mx[:fa_insert_c]}"). + gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)v\{(.+?)\}v/, + "\\1#{Mx[:fa_insert_o]}\\2#{Mx[:fa_insert_c]}"). + gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)-\{(.+?)\}-/, + "\\1#{Mx[:fa_strike_o]}\\2#{Mx[:fa_strike_c]}"). + gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)x\{(.+?)\}x/, + "\\1#{Mx[:fa_strike_o]}\\2#{Mx[:fa_strike_c]}"). + gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)\*(\S+?)\*/, + "\\1#{@emph[:o]}\\2#{@emph[:c]}"). #emphasise single word, watch + gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)\!(\S+?)\!/, + "\\1#{Mx[:fa_bold_o]}\\2#{Mx[:fa_bold_c]}"). #bold single word, watch + gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)\/([\(\)a-zA-Z0-9']+?)\/([ ,.;:'"~$]|[^a-zA-Z0-9])/, + "\\1#{Mx[:fa_italics_o]}\\2#{Mx[:fa_italics_c]}\\3"). #italics single word, watch + gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)_(\S+?)_/, + "\\1#{Mx[:fa_underscore_o]}\\2#{Mx[:fa_underscore_c]}"). #underscore single word, watch + gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)\^(\S+?)\^/, + "\\1#{Mx[:fa_superscript_o]}\\2#{Mx[:fa_superscript_c]}"). #check #superscript single word, watch digit added + gsub(/^\s*_\([1-9]\)\(\*\+\)\s*/, + "#{Mx[:pa_o]}:i\\1#{Mx[:pa_c]}#{Mx[:fa_o]}\\2#{Mx[:fa_c_o]}"). #bullets, shortcut + gsub(/^\s*_\([1-9]\)\s+/, + "#{Mx[:pa_o]}:i\\1#{Mx[:pa_c]}"). #watch + gsub(/^\s*__\([1-9]\)\s+/, + "#{Mx[:pa_o]}:h\\1#{Mx[:pa_c]}"). #watch + #line.gsub(/^\s*__\([1-9]\)!\s+/, + # "#{Mx[:pa_o]}:hd\\1#{Mx[:pa_c]}"). #watch + gsub(/#{Mx[:br_line]}\s*_[12]\s+/, + "#{Mx[:br_line]} ") #indent used in endnotes, not implemented, replace when ready with: line.gsub(/(?:
|
)\s*_([12])\s+/,'
<:i\1> ') + end + @data + end + end +end +__END__ diff --git a/lib/sisu/v5/dal.rb b/lib/sisu/v5/dal.rb deleted file mode 100644 index fb8a19ae..00000000 --- a/lib/sisu/v5/dal.rb +++ /dev/null @@ -1,537 +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: preprocessing, (document abstraction), data abstraction used - in subsequent processing - -=end -module SiSU_DAL - require_relative 'defaults' # defaults.rb - include SiSU_Viz - require_relative 'sysenv' # sysenv.rb - include SiSU_Env - require_relative 'param' # param.rb - include SiSU_Param - require_relative 'dal_doc_objects' # dal_doc_objects.rb - require_relative 'dal_syntax' # dal_syntax.rb - include SiSU_DAL_Syntax - require_relative 'dal_doc_str' # dal_doc_str.rb - require_relative 'dal_idx' # dal_idx.rb - require_relative 'dal_numbering' # dal_numbering.rb - require_relative 'dal_hash_digest' # dal_hash_digest.rb - require_relative 'dal_endnotes' # dal_endnotes.rb - require_relative 'dal_images' # dal_images.rb - require_relative 'dal_metadata' # dal_metadata.rb - require_relative 'dal_character_check' # dal_character_check.rb - require_relative 'dal_misc_arrange' # dal_misc_arrange.rb - require_relative 'dal_expand_insertions' # dal_expand_insertions.rb - require_relative 'prog_text_translation' # prog_text_translation.rb - require_relative 'shared_sem' # shared_sem.rb - class Instantiate < SiSU_Param::Parameters::Instructions - def initialize - @@flag_vocab=0 - @@line_mode='' - end - end - class Source #{cf.meta}").txt_grey - end - end - dal.each {|s| dal_array << s} - if @opt.act[:maintenance][:set]==:on - dal_array.each do |obj| - if defined? obj.parent - if defined? obj.ln - if defined? obj.node - puts %{#{obj.ln}: #{obj.ocn} : #{obj.parent} : #{obj.node} - #{obj.lc}} - else - puts %{#{obj.ln}: #{obj.ocn} : #{obj.parent}} - end - else - if defined? obj.node - puts %{ #{obj.ocn} : #{obj.parent} : #{obj.node} - #{obj.lc}} - else - puts %{ #{obj.ocn} : #{obj.parent}} - end - end - end - end - end - dal_array - end - def read_fnm - dal=[] - dal=(FileTest.file?(@fnm)) \ - ? (File.open(@fnm,'r:utf-8'){ |f| dal=Marshal.load(f)}) - : SiSU_DAL::Source.new(@opt).create_dal - end - def read_fnc - dal=[] - dal=(FileTest.file?(@fnc)) \ - ? (File.open(@fnc,'r:utf-8'){ |f| dal=Marshal.load(f)}) - : SiSU_DAL::Source.new(@opt).create_dal - end - def read_idx_sst - m=[] - m=(FileTest.file?(@idx_sst)) \ - ? (File.open(@idx_sst,'r:utf-8'){ |f| m=Marshal.load(f)}) - : nil - end - def read_idx_raw - m=[] - m=(FileTest.file?(@idx_raw)) \ - ? (File.open(@idx_raw,'r:utf-8'){ |f| m=Marshal.load(f)}) - : nil - end - def read_idx_html - m=[] - m=(FileTest.file?(@idx_html)) \ - ? (File.open(@idx_html,'r:utf-8'){ |f| m=Marshal.load(f)}) - : nil - end - def read_idx_xhtml - m=[] - m=(FileTest.file?(@idx_xhtml)) \ - ? (File.open(@idx_xhtml,'r:utf-8'){ |f| m=Marshal.load(f)}) - : nil - end - def read_map_nametags - m=[] - m=(FileTest.file?(@map_nametags)) \ - ? (File.open(@map_nametags,'r:utf-8'){ |f| m=Marshal.load(f)}) - : nil - end - def read_map_ocn_htmlseg - m=[] - m=(FileTest.file?(@map_ocn_htmlseg)) \ - ? (File.open(@map_ocn_htmlseg,'r:utf-8'){ |f| m=Marshal.load(f)}) - : nil - end - end - class Output - def initialize(fn,md,data) - @fn,@md,@data=fn,md,data - @cf=SiSU_Env::CreateFile.new(@fn) - @make=SiSU_Env::InfoFile.new(@fn) - @dir=SiSU_Env::InfoEnv.new(@fn) - end - def screen_dump(o) - if defined? o.of - print %{OF: #{o.of}; } - end - if defined? o.is - print %{IS: #{o.is.to_s}; } - end - if defined? o.ocn - print %{OCN: #{o.ocn}; } - end - if defined? o.node - print %{NODE: #{o.node}; } - end - if defined? o.parent - print %{Parent: #{o.parent}; } - end - if defined? o.obj and not o.obj.empty? - puts %{\n#{o.obj}; } - else "\n" - end - end - def screen_print(t_o) - if defined? t_o - print ' ' + t_o.to_s - end - end - def screen_output(data) - data.each do |o| - print o.class - screen_print(o.ocn) - screen_print(o.obj) - puts "\n" - end - end - def hard_output - if @md.opt.act[:maintenance][:set]==:on - filename_meta=@cf.metaverse.file_meta - @data.each {|o| filename_meta.puts o.inspect.sub(/:0x[0-9a-f]{8}\s/,': ')} #to make diffing easier - filename_txt=@cf.metaverse.file_txt - @data.each do |o| - if defined? o.ocn - filename_txt.puts case o.is - when :heading - "[#{o.is.to_s} #{o.lv}~#{o.name} [#{o.ocn}]] #{o.obj}" - else "[#{o.is.to_s} [#{o.ocn}]] #{o.obj}" - end - else - filename_txt.puts case o.is - when :meta - "[m~#{o.tag}] #{o.obj}" - else "[#{o.is.to_s}] #{o.obj}" - end - end - end - filename_debug=@cf.file_debug - @data.each do |o| - if defined? o.ocn - case o.is - when :heading - filename_debug.puts "#{o.is.to_s} #{o.lv}~#{o.name} odv=#{o.odv} osp=#{o.osp} [#{o.ocn}] -->\n\t#{o.obj}" - end - end - end - else - hard="#{@dir.processing_path.dal}/#{@md.fns}.meta" - File.unlink(hard) if FileTest.file?(hard) - hard="#{@dir.processing_path.dal}/#{@md.fns}.txt" - File.unlink(hard) if FileTest.file?(hard) - hard="#{@dir.processing_path.dal}/#{@md.fns}.debug.txt" - File.unlink(hard) if FileTest.file?(hard) - end - end - def make_marshal_content - marshal_dal=@make.marshal.dal_content - File.open(marshal_dal,'w'){|f| Marshal.dump(@data,f)} if @data.is_a?(Array) - end - def make_marshal_metadata - marshal_dal=@make.marshal.dal_metadata - File.open(marshal_dal,'w'){|f| Marshal.dump(@data,f)} if @data.is_a?(Array) - end - def idx_html_hard_output - if @md.book_idx \ - and @md.opt.act[:maintenance][:set]==:on - filename_meta=@cf.file_meta_idx_html - if @data.is_a?(Array) - @data.each {|s| p s.inspect + "\n" unless s.is_a?(String)} - @data.each {|s| filename_meta.puts s.strip + "\n" unless s.strip.empty?} - end - else - hard_idx_html="#{@dir.processing_path.dal}/#{@md.fns}.idx.html" - File.unlink(hard_idx_html) if FileTest.file?(hard_idx_html) - end - end - def make_marshal_idx_sst_html_seg - marshal_dal=@make.marshal.dal_idx_sst_rel_html_seg - File.open(marshal_dal,'w'){|f| Marshal.dump(@data,f)} if @data.is_a?(Array) - end - def make_marshal_idx_sst_rel - marshal_dal=@make.marshal.dal_idx_sst_rel - File.open(marshal_dal,'w'){|f| Marshal.dump(@data,f)} if @data.is_a?(Array) - end - def make_marshal_idx_html - marshal_dal=@make.marshal.dal_idx_html - File.open(marshal_dal,'w'){|f| Marshal.dump(@data,f)} if @data.is_a?(Array) - end - def make_marshal_idx_xhtml - marshal_dal=@make.marshal.dal_idx_xhtml - File.open(marshal_dal,'w'){|f| Marshal.dump(@data,f)} if @data.is_a?(Array) - end - def make_marshal_map_nametags - marshal_dal=@make.marshal.dal_map_nametags - File.open(marshal_dal,'w'){|f| Marshal.dump(@data,f)} if @data.is_a?(Hash) - end - def make_marshal_map_name_ocn_htmlseg - marshal_dal=@make.marshal.dal_map_ocn_htmlseg - File.open(marshal_dal,'w'){|f| Marshal.dump(@data,f)} if @data.is_a?(Hash) - end - end - class Make - def initialize(fn,md,data) - @fn,@md,@data=fn,md,data - @env=SiSU_Env::InfoEnv.new(@md.fns) - end - def reset - @@flag_vocab=0 - @@line_mode='' - end - def song - reset - data=@data - data=SiSU_DAL_Insertions::Insertions.new(@md,data).expand_insertions? # dal_expand_insertions.rb - data=SiSU_DAL_MiscArrangeText::SI.new(@md,data).prepare_text # dal_misc_arrange.rb - data,metadata=SiSU_DAL_DocumentStructureExtract::Build.new(@md,data).identify_parts # dal_doc_str.rb - data=SiSU_DAL_Syntax::Markup.new(@md,data).songsheet # dal_syntax.rb - data,endnote_array=SiSU_DAL_CharacterCheck::Check.new(data).character_check_and_oldstyle_endnote_array # dal_character_check.rb - data=SiSU_DAL_Images::Images.new(@md,data).images # dal_images.rb - data,tags_map,ocn_html_seg_map=SiSU_DAL_Numbering::Numbering.new(@md,data).numbering_song # dal_numbering.rb - data,book_index_rel,book_index_rel_html_seg,html_idx,xhtml_idx=SiSU_DAL_BookIndex::BookIndex.new(@md,data,@env).indexing_song if @md.book_idx # dal_idx.rb - data=SiSU_DAL_Endnotes::Endnotes.new(@md,data,endnote_array).endnotes # dal_endnotes.rb - outputdata=data - if (@md.opt.act[:dal][:set]==:on \ - || @md.opt.act[:maintenance][:set]==:on) - SiSU_DAL::Output.new(@fn,@md,outputdata).hard_output - SiSU_DAL::Output.new(@fn,@md,outputdata).make_marshal_content - SiSU_DAL::Output.new(@fn,@md,metadata).make_marshal_metadata - SiSU_DAL::Output.new(@fn,@md,html_idx).idx_html_hard_output - SiSU_DAL::Output.new(@fn,@md,book_index_rel_html_seg).make_marshal_idx_sst_html_seg - SiSU_DAL::Output.new(@fn,@md,book_index_rel).make_marshal_idx_sst_rel - SiSU_DAL::Output.new(@fn,@md,html_idx).make_marshal_idx_html - SiSU_DAL::Output.new(@fn,@md,xhtml_idx).make_marshal_idx_xhtml - SiSU_DAL::Output.new(@fn,@md,tags_map).make_marshal_map_nametags - SiSU_DAL::Output.new(@fn,@md,ocn_html_seg_map).make_marshal_map_name_ocn_htmlseg - end - reset - outputdata - end - protected - end -end -__END__ diff --git a/lib/sisu/v5/dal_character_check.rb b/lib/sisu/v5/dal_character_check.rb deleted file mode 100644 index 62aa60c1..00000000 --- a/lib/sisu/v5/dal_character_check.rb +++ /dev/null @@ -1,107 +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: system environment, resource control and configuration details - -=end -module SiSU_DAL_CharacterCheck - class Check - def initialize(data) - @data=data - @comment='%' - @endnote_array=[] - end - def character_check_and_oldstyle_endnote_array - data=@data - @tuned_file,@endnote_array=[],[] - endnote_no=1 - data.each do |dob| - unless dob.is ==:table - dob.obj=dob.obj.strip. - gsub(/^[{~}]\s*$/,''). - gsub(/~#\s*/,"#{Mx[:pa_non_object_no_heading]}"). - gsub(/-#\s*/,"#{Mx[:pa_non_object_dummy_heading]}"). - gsub(/(#{Mx[:en_a_o]})\s*\s+/,'\1 '). - gsub(/(~\{\s*)\s+/,'\1 '). - gsub(/ \/\//,"#{Mx[:br_line]}"). - gsub(/
/,"#{Mx[:br_line]}"). #needed by xml, xhtml etc. - gsub(/\t/,' '). - gsub(/\342\200\231/u,"'"). #if dob =~/’/ #Avoid #‘ ’ #“ ” - gsub(/\\copy(?:right)?\b/,'©'). - gsub(/\\trademark\b|\\tm\b/,'®') - dob.obj=dob.obj + "\n" - unless dob.is ==:code - case dob.obj - when /\^~/ #% Note must do this first (earlier loop) and then enter gathered data into ~^\d+ - sub_dob=dob.obj.dup - @endnote_array << sub_dob.gsub(/\n/,''). - gsub(/\^~\s+(.+)\s*/,%{#{Mx[:en_a_o]}#{endnote_no} \\1 #{Mx[:en_a_c]}}). - strip - endnote_no+=1 - dob=nil if dob.obj =~/\^~ .+/ #watch, removes 'binary' endnote now in endnote array for later insertion - end - end - end - @tuned_file << dob if dob.is_a?(Object) - end - @tuned_file=@tuned_file.flatten.compact - [@tuned_file,@endnote_array] - end - end -end -__END__ diff --git a/lib/sisu/v5/dal_doc_objects.rb b/lib/sisu/v5/dal_doc_objects.rb deleted file mode 100644 index 518535b0..00000000 --- a/lib/sisu/v5/dal_doc_objects.rb +++ /dev/null @@ -1,481 +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: document abstraction - -=end -module SiSU_DAL_DocumentStructure - class Extract - def extract(h,o) - h ? h : o - end - end - class ObjectMetadata - attr_accessor :is,:of,:tags,:obj,:digest - def initialize - @tags={} - @is=@tmp=@digest=nil - @of=:meta - end - def metadata(tags) - of= @of #String, classification - group - is= :meta #String, classification - specific type - tags= tags || ((defined? o.tags) ? o.tags : {}) #String, metadata type/tag - obj= nil - @of,@is,@tags,@obj=of,is,tags,obj - self - end - end - class ObjectMeta - attr_accessor :obj,:is,:of,:tag,:digest,:tmp - def initialize - @is=@obj=@tag=@digest=@digest=@tmp=nil - @of=:meta - end - def metadata(h,o=nil) - of= @of #String, classification - group - is= :meta #String, classification - specific type - tag= h[:tag] || ((defined? o.tag) ? o.tag : nil) #String, metadata type/tag - obj= h[:obj] || ((defined? o.obj) ? o.obj : nil) #String, text content - tmp= h[:tmp] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use - digest= h[:digest] || ((defined? o.digest) ? o.digest : nil) #hash digests, either sha256 or md5 - @of,@is,@tag,@obj,@digest,@tmp=of,is,tag,obj,digest,tmp - self - end - end - class ObjectHeading - attr_accessor :obj,:is,:tags,:of,:lv,:ln,:lc,:toc_,:name,:idx,:ocn,:odv,:osp,:node,:parent,:ocn_,:note_,:autonum_,:digest,:tmp - def initialize - @of=:para - @is=@obj=@lv=@ln=@lc=@toc_=@name=@idx=@size=@ocn=@odv=@osp=@node=@parent=@ocn_=@note_=@autonum_=@digest=@tmp=nil - @tags=[] - end - def heading_ln(lv) - case lv - when /A/; 1 - when /B/; 2 - when /C/; 3 - when /1/; 4 - when /2/; 5 - when /3/; 6 - when /4/; 7 - when /5/; 8 - when /6/; 9 - end - end - def heading_lv(ln) - case ln.to_s - when /1/; 'A' - when /2/; 'B' - when /3/; 'C' - when /4/; '1' - when /5/; '2' - when /6/; '3' - when /7/; '4' - when /8/; '5' - when /9/; '6' - end - end - def heading(h,o=nil) - if not h[:ln] \ - and (h[:lv] and h[:lv]=~/[1-6A-C]/) - h[:ln]=heading_ln(h[:lv]) - elsif not h[:lv] \ - and (h[:ln] and h[:ln].to_s=~/[1-9]/) - h[:lv]=heading_lv(h[:ln]) - end - of= @of #String, classification - group - is= :heading #String, classification - specific type - name= h[:name] || ((defined? o.name) ? o.name : nil) #String, named object? - tags= h[:tags] || ((defined? o.tags) ? o.tags : []) #Array, associated object tags, names if any - obj= h[:obj] || ((defined? o.obj) ? o.obj : nil) #String, text content - idx= h[:idx] || ((defined? o.idx) ? o.idx : nil) #String, book index provided? - ocn= h[:ocn] || ((defined? o.ocn) ? o.ocn : nil) #Integer, sequential on substantive-content objects - odv= h[:odv] || ((defined? o.odv) ? o.odv : nil) - osp= h[:osp] || ((defined? o.osp) ? o.osp : nil) - node= h[:node] || ((defined? o.node) ? o.node : nil) #[Node relationship doc structure info] - parent= h[:parent] || ((defined? o.parent) ? o.parent : nil) #[Node parent] - lv= h[:lv] || ((defined? o.lv) ? o.lv : nil) #Alpha-numeric, document structure as used in markup, A-C then 1-6 - ln= h[:ln] || ((defined? o.ln) ? o.ln : nil) #Integer, document structure level, for convenience in processing 1-9 - lc= h[:lc] || ((defined? o.lc) ? o.lc : nil) #Integer, document structure collapsed level, convenience (collapse sisu's dual level document structure for markup with simple linear structure) - toc_= h[:toc_] || ((defined? o.toc_) ? o.toc_ : false) #Bool, do not include in toc, (relevant to headings) - ocn_=if h[:ocn_].nil? then ((defined? o.ocn_) ? o.ocn_ : true) #Bool? no ocn, non-substantive content, do not include in toc #consider - else h[:ocn_] - end - autonum_= if h[:autonum_].nil? then ((defined? o.autonum_) ? o.autonum_ : true) #Bool? auto-numbering if requested default on, false suppresses - else h[:autonum_] - end - note_= h[:note_] || ((defined? o.note_) ? o.note_ : false) #Bool, endnotes/footnotes? (processing optimization) - digest= h[:digest] || ((defined? o.digest) ? o.digest : nil) #hash digests, either sha256 or md5 - tmp= h[:tmp] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use - @of,@is,@lv,@ln,@lc,@name,@tags,@obj,@idx,@ocn,@odv,@osp,@node,@parent,@toc_,@ocn_,@note_,@autonum_,@digest,@tmp=of,is,lv,ln,lc,name,tags,obj,idx,ocn,odv,osp,node,parent,toc_,ocn_,note_,autonum_,digest,tmp - self - end - def heading_insert(h,o=nil) - heading(h,o=nil) - @is= :heading_insert #String, classification - specific type - self - end - end - class ObjectPara - attr_accessor :obj,:is,:tags,:of,:name,:idx,:bullet_,:indent,:hang,:ocn,:odv,:osp,:parent,:note_,:image_,:ocn_,:digest,:tmp - def initialize - @of=:para - @is=@obj=@name=@idx=@bullet_=@indent=@hang=@size=@ocn=@odv=@osp=@parent=@note_=@image_=@ocn_=@digest=@tmp=nil - @tags=[] - end - def paragraph(h,o=nil) - of= @of #String, classification - group - is= :para #String, classification - specific type - name= h[:name] || ((defined? o.name) ? o.name : nil) #String, named object? - tags= h[:tags] || ((defined? o.tags) ? o.tags : []) #Array, associated object tags, names if any - obj= h[:obj] || ((defined? o.obj) ? o.obj : nil) #String, text content - idx= h[:idx] || ((defined? o.idx) ? o.idx : nil) #String, book index provided? - ocn= h[:ocn] || ((defined? o.ocn) ? o.ocn : nil) #Integer, sequential on substantive-content objects - odv= h[:odv] || ((defined? o.odv) ? o.odv : nil) - osp= h[:osp] || ((defined? o.osp) ? o.osp : nil) - parent= h[:parent] || ((defined? o.parent) ? o.parent : nil) #[Node parent] - indent= h[:indent].to_s || ((defined? o.indent) ? o.indent.to_s : nil) #Integer, indent level - hang= h[:hang].to_s || ((defined? o.hang) ? o.hang.to_s : nil) #Integer, hanging indent level - bullet_=h[:bullet_] || ((defined? o.bullet_) ? o.bullet_ : false) #Bool, bulleted? - note_= h[:note_] || ((defined? o.note_) ? o.note_ : false) #Bool, endnotes/footnotes? (processing optimization) - image_= h[:image_] || ((defined? o.image_) ? o.image_ : false) #Bool, images? (processing optimization) - ocn_=if h[:ocn_].nil? then ((defined? o.ocn_) ? o.ocn_ : true) #Bool? no ocn, non-substantive content, do not include in toc #consider - else h[:ocn_] - end - digest= h[:digest] || ((defined? o.digest) ? o.digest : nil) #hash digests, either sha256 or md5 - tmp= h[:tmp] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use - @of,@is,@name,@tags,@obj,@indent,@hang,@bullet_,@idx,@ocn,@odv,@osp,@parent,@image_,@note_,@ocn_,@digest,@tmp=of,is,name,tags,obj,indent,hang,bullet_,idx,ocn,odv,osp,parent,image_,note_,ocn_,digest,tmp - self - end - def docinfo(h,o=nil) - of= @of #String, classification - group - is= :docinfo #String, classification - specific type - name= h[:name] || ((defined? o.name) ? o.name : nil) #String, named object? - tags= h[:tags] || ((defined? o.tags) ? o.tags : nil) #Array, associated object tags, names if any - obj= h[:obj] || ((defined? o.obj) ? o.obj : nil) #String, text content - idx= nil #String, book index provided? - ocn= nil #Integer, sequential on substantive-content objects - odv= h[:odv] || ((defined? o.odv) ? o.odv : nil) - osp= h[:osp] || ((defined? o.osp) ? o.osp : nil) - parent= h[:parent] || ((defined? o.parent) ? o.parent : nil) #[Node parent] - indent= nil #Integer, indent level - hang= nil #Integer, indent level - bullet_=false #Bool, bulleted? - note_= false #Bool, endnotes/footnotes? (processing optimization) - image_= h[:image_] || ((defined? o.image_) ? o.image_ : false) #Bool, images? (processing optimization) - ocn_=if h[:ocn_].nil? then ((defined? o.ocn_) ? o.ocn_ : true) #Bool? no ocn, non-substantive content, do not include in toc #consider - else h[:ocn_] - end - digest= h[:digest] || ((defined? o.digest) ? o.digest : nil) #hash digests, either sha256 or md5 - tmp= h[:tmp] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use - @of,@is,@name,@tags,@obj,@indent,@hang,@bullet_,@idx,@ocn,@odv,@osp,@parent,@image_,@note_,@ocn_,@digest,@tmp=of,is,name,tags,obj,indent,hang,bullet_,idx,ocn,odv,osp,parent,image_,note_,ocn_,digest,tmp - self - end - end - class ObjectBlockTxt - attr_accessor :obj,:is,:of,:tags,:idx,:ocn,:odv,:osp,:parent,:note_,:number_,:ocn_,:digest,:tmp - def initialize - @of=:block - @is=@obj=@idx=@ocn=@odv=@osp=@parent=@note_=@number_=@ocn_=@digest=@tmp=nil - @tags=[] - end - def code(h,o=nil) - of= @of #String, classification - group #alt 'code' - is= :code #String, classification - specific type - tags= h[:tags] || ((defined? o.tags) ? o.tags : []) #Array, associated object tags, names if any - obj= h[:obj] || ((defined? o.obj) ? o.obj : nil) #String, text content - idx= h[:idx] || ((defined? o.idx) ? o.idx : nil) #String, book index provided? - ocn= h[:ocn] || ((defined? o.ocn) ? o.ocn : nil) #Integer, sequential on substantive-content objects - odv= h[:odv] || ((defined? o.odv) ? o.odv : nil) - osp= h[:osp] || ((defined? o.osp) ? o.osp : nil) - parent= h[:parent] || ((defined? o.parent) ? o.parent : nil) #[Node parent] - number_= h[:number_] || ((defined? o.number_) ? o.number_ : false) #Bool, numbered or not? - note_= h[:note_] || ((defined? o.note_) ? o.note_ : false) #Bool, endnotes/footnotes? (processing optimization) - ocn_= if h[:ocn_].nil? then ((defined? o.ocn_) ? o.ocn_ : true) #Bool? no ocn, non-substantive content, do not include in toc #consider - else h[:ocn_] - end - digest= h[:digest] || ((defined? o.digest) ? o.digest : nil) #hash digests, either sha256 or md5 - tmp= h[:tmp] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use - @of,@is,@tags,@obj,@idx,@ocn,@odv,@osp,@parent,@number_,@note_,@ocn_,@digest,@tmp=of,is,tags,obj,idx,ocn,odv,osp,parent,number_,note_,ocn_,digest,tmp - self - end - def block(h,o=nil) - of= @of #String, classification - group - is= :block #String, classification - specific type - tags= h[:tags] || ((defined? o.tags) ? o.tags : []) #Array, associated object tags, names if any - obj= h[:obj] || ((defined? o.obj) ? o.obj : nil) #String, text content - idx= h[:idx] || ((defined? o.idx) ? o.idx : nil) #String, book index provided? - ocn= h[:ocn] || ((defined? o.ocn) ? o.ocn : nil) #Integer, sequential on substantive-content objects - odv= h[:odv] || ((defined? o.odv) ? o.odv : nil) - osp= h[:osp] || ((defined? o.osp) ? o.osp : nil) - parent= h[:parent] || ((defined? o.parent) ? o.parent : nil) #[Node parent] - note_= h[:note_] || ((defined? o.note_) ? o.note_ : false) #Bool, endnotes/footnotes? (processing optimization) - ocn_= if h[:ocn_].nil? then ((defined? o.ocn_) ? o.ocn_ : true) #Bool? no ocn, non-substantive content, do not include in toc #consider - else h[:ocn_] - end - digest= h[:digest] || ((defined? o.digest) ? o.digest : nil) #hash digests, either sha256 or md5 - tmp= h[:tmp] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use - @of,@is,@tags,@obj,@idx,@ocn,@odv,@osp,@parent,@note_,@ocn_,@digest,@tmp=of,is,tags,obj,idx,ocn,odv,osp,parent,note_,ocn_,digest,tmp - self - end - def group(h,o=nil) - of= @of #String, classification - group - is= :group #String, classification - specific type - tags= h[:tags] || ((defined? o.tags) ? o.tags : []) #Array, associated object tags, names if any - obj= h[:obj] || ((defined? o.obj) ? o.obj : nil) #String, text content - idx= h[:idx] || ((defined? o.idx) ? o.idx : nil) #String, book index provided? - ocn= h[:ocn] || ((defined? o.ocn) ? o.ocn : nil) #Integer, sequential on substantive-content objects - odv= h[:odv] || ((defined? o.odv) ? o.odv : nil) - osp= h[:osp] || ((defined? o.osp) ? o.osp : nil) - parent= h[:parent] || ((defined? o.parent) ? o.parent : nil) #[Node parent] - note_= h[:note_] || ((defined? o.note_) ? o.note_ : false) #Bool, endnotes/footnotes? (processing optimization) - ocn_= if h[:ocn_].nil? then ((defined? o.ocn_) ? o.ocn_ : true) #Bool? no ocn, non-substantive content, do not include in toc #consider - else h[:ocn_] - end - digest= h[:digest] || ((defined? o.digest) ? o.digest : nil) #hash digests, either sha256 or md5 - tmp= h[:tmp] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use - @of,@is,@tags,@obj,@idx,@ocn,@odv,@osp,@parent,@note_,@ocn_,@digest,@tmp=of,is,tags,obj,idx,ocn,odv,osp,parent,note_,ocn_,digest,tmp - self - end - def alt(h,o=nil) #see block - of= @of #String, classification - group - is= :alt #String, classification - specific type - tags= h[:tags] || ((defined? o.tags) ? o.tags : []) #Array, associated object tags, names if any - obj= h[:obj] || ((defined? o.obj) ? o.obj : nil) #String, text content - idx= h[:idx] || ((defined? o.idx) ? o.idx : nil) #String, book index provided? - ocn= h[:ocn] || ((defined? o.ocn) ? o.ocn : nil) #Integer, sequential on substantive-content objects - odv= h[:odv] || ((defined? o.odv) ? o.odv : nil) - osp= h[:osp] || ((defined? o.osp) ? o.osp : nil) - parent= h[:parent] || ((defined? o.parent) ? o.parent : nil) #[Node parent] - note_= h[:note_] || ((defined? o.note_) ? o.note_ : false) #Bool, endnotes/footnotes? (processing optimization) - ocn_= if h[:ocn_].nil? then ((defined? o.ocn_) ? o.ocn_ : true) #Bool? no ocn, non-substantive content, do not include in toc #consider - else h[:ocn_] - end - digest= h[:digest] || ((defined? o.digest) ? o.digest : nil) #hash digests, either sha256 or md5 - tmp= h[:tmp] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use - @of,@is,@tags,@obj,@idx,@ocn,@odv,@osp,@parent,@note_,@ocn_,@digest,@tmp=of,is,tags,obj,idx,ocn,odv,osp,parent,note_,ocn_,digest,tmp - self - end - def verse(h,o=nil) #part of poem decide how you deal with this - of= @of #String, classification - group - is= :verse #String, classification - specific type - tags= h[:tags] || ((defined? o.tags) ? o.tags : []) #Array, associated object tags, names if any - obj= h[:obj] || ((defined? o.obj) ? o.obj : nil) #String, text content - idx= h[:idx] || ((defined? o.idx) ? o.idx : nil) #String, book index provided? - ocn= h[:ocn] || ((defined? o.ocn) ? o.ocn : nil) #Integer, sequential on substantive-content objects - odv= h[:odv] || ((defined? o.odv) ? o.odv : nil) - osp= h[:osp] || ((defined? o.osp) ? o.osp : nil) - parent= h[:parent] || ((defined? o.parent) ? o.parent : nil) #[Node parent] - ocn_= if h[:ocn_].nil? then ((defined? o.ocn_) ? o.ocn_ : true) #Bool? no ocn, non-substantive content, do not include in toc #consider - else h[:ocn_] - end - digest= h[:digest] || ((defined? o.digest) ? o.digest : nil) #hash digests, either sha256 or md5 - tmp= h[:tmp] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use - @of,@is,@tags,@obj,@idx,@ocn,@odv,@osp,@parent,@note_,@ocn_,@digest,@tmp=of,is,tags,obj,idx,ocn,odv,osp,parent,note_,ocn_,digest,tmp - @h=nil - self - end - end - class ObjectTable - attr_accessor :obj,:is,:of,:lv,:tags,:name,:idx,:indent,:hang,:size,:ocn,:number,:head_,:cols,:widths,:odv,:osp,:parent,:note_,:ocn_,:digest,:tmp - def initialize - @of=:block - @is=@obj=@lv=@name=@idx=@indent=@hang=@size=@ocn,@number,@head_,@cols,@widths=@odv=@osp=@parent=@note_=@ocn_=@digest=@tmp=nil - @tags=[] - end - def table(h,o=nil) - of= @of #String, classification - group - is= :table #String, classification - specific type - tags= h[:tags] || ((defined? o.tags) ? o.tags : []) #Array, associated object tags, names if any - cols= h[:cols] || ((defined? o.cols) ? o.cols : nil) - widths= h[:widths] || ((defined? o.widths) ? o.widths : nil) - obj= h[:obj] || ((defined? o.obj) ? o.obj : nil) #String, text content - idx= h[:idx] || ((defined? o.idx) ? o.idx : nil) #String, book index provided? - ocn= h[:ocn] || ((defined? o.ocn) ? o.ocn : nil) #Integer, sequential on substantive-content objects - odv= h[:odv] || ((defined? o.odv) ? o.odv : nil) - osp= h[:osp] || ((defined? o.osp) ? o.osp : nil) - parent= h[:parent] || ((defined? o.parent) ? o.parent : nil) #[Node parent] - head_= h[:head_] || ((defined? o.head_) ? o.head_ : false) - note_= h[:note_] || ((defined? o.note_) ? o.note_ : false) #Bool, endnotes/footnotes? (processing optimization) - ocn_=if h[:ocn_].nil? then ((defined? o.ocn_) ? o.ocn_ : true) #Bool? no ocn, non-substantive content, do not include in toc #consider - else h[:ocn_] - end - digest= h[:digest] || ((defined? o.digest) ? o.digest : nil) #hash digests, either sha256 or md5 - tmp= h[:tmp] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use - @of,@is,@tags,@cols,@widths,@obj,@idx,@ocn,@odv,@osp,@parent,@head_,@note_,@ocn_,@digest,@tmp=of,is,tags,cols,widths,obj,idx,ocn,odv,osp,parent,head_,note_,ocn_,digest,tmp - self - end - end - class ObjectImage - attr_accessor :obj,:is,:of,:lv,:idx,:size,:ocn,:parent,:note_,:ocn_,:digest,:tmp - def initialize - @of=:image - @is=@obj=@lv=@idx=@size=@ocn=@parent=@note_=@ocn_=@tmp=@digest=nil - @tags=[] - end - def image(h,o=nil) #not yet used, and what of a paragraph containing several images, consider - of= @of #String, classification - group - is= :image #String, classification - specific type - tags= h[:tags] || ((defined? o.tags) ? o.tags : []) #Array, associated object tags, names if any - obj= h[:obj] || ((defined? o.obj) ? o.obj : nil) #String, text content - size= h[:size] || ((defined? o.size) ? o.size : nil) - idx= h[:idx] || ((defined? o.idx) ? o.idx : nil) #String, book index provided? - ocn= h[:ocn] || ((defined? o.ocn) ? o.ocn : nil) #Integer, sequential on substantive-content objects - odv= h[:odv] || ((defined? o.odv) ? o.odv : nil) - osp= h[:osp] || ((defined? o.osp) ? o.osp : nil) - parent= h[:parent] || ((defined? o.parent) ? o.parent : nil) #[Node parent] - note_= h[:note_] || ((defined? o.note_) ? o.note_ : false) #Bool, endnotes/footnotes? (processing optimization) - ocn_=if h[:ocn_].nil? then ((defined? o.ocn_) ? o.ocn_ : true) #Bool? no ocn, non-substantive content, do not include in toc #consider - else h[:ocn_] - end - digest= h[:digest] || ((defined? o.digest) ? o.digest : nil) #hash digests, either sha256 or md5 - tmp= h[:tmp] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use - @of,@is,@tags,@obj,@size,@idx,@ocn,@odv,@osp,@parent,@note_,@ocn_,@digest,@tmp=of,is,tags,obj,size,idx,ocn,odv,osp,parent,note_,ocn_,digest,tmp - self - end - end - class ObjectStructure - attr_accessor :obj,:tag,:node,:lv,:ln,:lc,:status,:is,:of,:tmp - def initialize - @of=:structure - @is=@obj=@node=@lv=@ln=@lc=@status=@tmp=nil - end - def xml_dom(h,o=nil) - of= @of #String, classification - group - is= :xml_dom #String, classification - specific type - obj= h[:obj] || ((defined? o.obj) ? o.obj : '') #String, text content - lv= h[:lv] || ((defined? o.lv) ? o.lv : nil) #Alpha-numeric, document structure as used in markup, A-C then 1-6 - ln= h[:ln] || ((defined? o.ln) ? o.ln : nil) #Integer, document structure level, for convenience in processing 1-9 - lc= h[:lc] || ((defined? o.lc) ? o.lc : nil) #Integer, document structure collapsed level, convenience (collapse sisu's dual level document structure for markup with simple linear structure) - node= h[:node] || ((defined? o.node) ? o.node : nil) #[Node relationship doc structure info] - status= h[:status] || ((defined? o.status) ? o.status : nil) #tag status open or close - tmp= h[:tmp] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use - @of,@is,@obj,@status,@node,@lv,@ln,@lc,@tmp=of,is,obj,status,node,lv,ln,lc,tmp - self - end - end - class ObjectComment - attr_accessor :obj,:is,:of,:tmp - def initialize - @of=:comment - @is=@obj=@tmp=nil - end - def comment(h,o=nil) - of= @of #String, classification - group - is= :comment #String, classification - specific type - obj= h[:obj] || ((defined? o.obj) ? o.obj : nil) #String, text content - tmp= h[:tmp] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use - @of,@is,@obj,@tmp=of,is,obj,tmp - self - end - end - class ObjectFlag - attr_accessor :obj,:is,:of,:flag,:mod,:tmp - def initialize - @of=:flag - @is=@obj=@flag=@mod=@tmp=nil - end - def flag(h,o=nil) - of= @of #String, classification - group - is= :flag #String, classification - specific type - obj= nil #String, text content - flag= h[:flag] || ((defined? o.flag) ? o.flag : nil) #String, text content - mod= h[:mod] || ((defined? o.mod) ? o.mod : nil) #String, text content - tmp= h[:flag] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use - @of,@is,@obj,@flag,@mod,@tmp=of,is,obj,flag,mod,tmp - self - end - def flag_ocn(h,o=nil) - of= @of #String, classification - group - is= :flag_ocn #String, classification - specific type - obj= nil #String, text content - flag= h[:flag] || ((defined? o.flag) ? o.flag : nil) #String, text content - mod= h[:mod] || ((defined? o.mod) ? o.mod : nil) #String, text content - tmp= h[:flag] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use - @of,@is,@obj,@flag,@mod,@tmp=of,is,obj,flag,mod,tmp - self - end - end - class ObjectLayout - attr_accessor :obj,:is,:of,:from,:tmp - def initialize - @of=:layout - @is=@obj=@from=@tmp=nil - end - def break(h,f=nil) #decide how to deal with - of= @of #String, classification - group - is= :break #String, classification - specific type - obj= h[:obj] #String, text content - from= f - tmp= h[:tmp] #available for processing, empty after use - @of,@is,@obj,@from,@tmp=of,is,obj,from,tmp - self - end - def insert(h,o=nil) #decide how to deal with, could mimic paragraph? - of= @of #String, classification - group - is= :insert #String, classification - specific type - obj= h[:obj] || ((defined? o.obj) ? o.obj : nil) #String, text content - tmp= h[:tmp] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use - @of,@is,@obj,@tmp=of,is,obj,tmp - self - end - end -end -__END__ -# ~# |-# no paragraph number # -# not included in toc diff --git a/lib/sisu/v5/dal_doc_str.rb b/lib/sisu/v5/dal_doc_str.rb deleted file mode 100644 index 7a89dfb1..00000000 --- a/lib/sisu/v5/dal_doc_str.rb +++ /dev/null @@ -1,1427 +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: document abstraction - -=end -module SiSU_DAL_DocumentStructureExtract - class Instantiate < SiSU_Param::Parameters::Instructions - @@flag={ - ocn: :on, - code: :off, - poem: :off, - block: :off, - group: :off, - alt: :off, - table: :off, - table_to: :off, - } - def initialize - @@counter=@@column=@@columns=0 - @@line_mode='' - end - end - class Build - @@flag={ - ocn: :on, - code: :off, - poem: :off, - block: :off, - group: :off, - alt: :off, - table: :off, - table_to: :off, - } - def initialize(md,data) - @md,@data=md,data - SiSU_DAL_DocumentStructureExtract::Instantiate.new - @pb=SiSU_DAL_DocumentStructure::ObjectLayout.new.break(Hx[:br_page]) - @pbn=SiSU_DAL_DocumentStructure::ObjectLayout.new.break(Hx[:br_page_new]) - @pbl=SiSU_DAL_DocumentStructure::ObjectLayout.new.break(Hx[:br_page_line]) - end - def ln_get(lv) - case lv - when /A/; 1 - when /B/; 2 - when /C/; 3 - when /1/; 4 - when /2/; 5 - when /3/; 6 - when /4/; 7 - when /5/; 8 - when /6/; 9 - end - end - def image_test(str) - str=~/\{\s*\S+?\.png.+?\}https?:\/\/\S+/ \ - ? true - : false - end - def bullet_test(str) - (str=~/\*/) \ - ? true - : false - end - def hang_and_indent_test(str) - hang_indent=if str=~/^_([1-9])[^_]/ - [$1,$1] - elsif str=~/^__([1-9])/ - [0,$1] - elsif str=~/^_([0-9])_([0-9])/ - [$1,$2] - else - [0,0] - end - hang,indent=hang_indent[0],hang_indent[1] - [hang,indent] - end - def hang_and_indent_def_test(str1,str2) - hang_indent=if str1=~/^_([1-9])[^_]/ - [$1,$1] - elsif str1=~/^__([1-9])/ - [0,$1] - elsif str1=~/^_([0-9])_([0-9])/ - [$1,$2] - else - [0,0] - end - obj=if str2 =~/^(.+?)\s+\\\\(?:\s+|\n)/ - str2.gsub(/^(.+?)(\s+\\\\(?:\s+|\n))/,"#{Mx[:fa_bold_o]}\\1#{Mx[:fa_bold_c]}\\2") - else - str2.gsub(/^(.+?)\n/,"#{Mx[:fa_bold_o]}\\1#{Mx[:fa_bold_c]}\n") - end - hang,indent=hang_indent[0],hang_indent[1] - [hang,indent,obj] - end - def endnote_test?(str) - (str=~/~\{.+?\}~|~\[.+?\]~/) \ - ? true - : false - end - def extract_tags(str,nametag=nil) - tags=[] - if str.nil? - else - if str =~/(?:^|[ ])\*~([a-z0-9._-]+)(?=[ #{Mx[:br_nl]}]|$)/ - str=str.gsub(/(^|[ ])\*~([a-z0-9._-]+)(?=[ #{Mx[:br_nl]}]|$)/i, - "\\1#{Mx[:tag_o]}\\2#{Mx[:tag_c]}"). - gsub(/ [ ]+/i,' ') - tags=str.scan(/#{Mx[:tag_o]}(\S+?)#{Mx[:tag_c]}/).flatten - str=str.gsub(/[ ]?#{Mx[:tag_o]}\S+?#{Mx[:tag_c]}[ ]?/,' ') #may be issues with spaces would leave one, but "code" blocks? - end - tags=nametag ? (tags << nametag) : tags - end - [str,tags] - end - def rgx_idx_ocn_seg - @rgx_idx_ocn_seg=/(.+?)\s*[+](\d+)/ - end - def construct_idx_array_and_hash(idxraw) - idx_array_raw=idxraw.scan(/[^;]+/) - idx_hash,idx_array,idx_lst={},[],[] - idx_array_raw.each do |idx| - idx_lst=case idx - when /\S+?\s*:/ - idx_couplet_tmp=[] - idx_couplet=idx.scan(/\s*[^:]+\s*/) - if idx_couplet[1] =~/[|]/ - idx_couplet_tmp << idx_couplet[0] << idx_couplet[1].scan(/\s*[^|]+\s*/) - else - idx_couplet_tmp << idx_couplet[0] << [idx_couplet[1]] - end - idx_couplet=idx_couplet_tmp - else [idx] - end - term_nodes=[] - idx_lst.each do |term_node| - case term_node - when String - term_node=term_node[0].chr.capitalize + term_node[1,term_node.length] - term_node=(term_node =~/.+?[+]\d+/) \ - ? term_node - : (term_node + '+0') - term_nodes << term_node - use,plus=rgx_idx_ocn_seg.match(term_node)[1,2] - @use=use.strip - idx_hash[@use]={ sub: [], plus: plus } unless idx_hash[@use] and defined? idx_hash[@use] - when Array - subterm_nodes=[] - term_node.each do |subterm_node| - subterm_node=(subterm_node =~/.+?[+]\d+/) \ - ? subterm_node - : (subterm_node + '+0') - subterm_nodes << subterm_node - sub,sub_plus=rgx_idx_ocn_seg.match(subterm_node)[1,2] - idx_hash[@use]={ sub: [], plus: 0 } unless idx_hash[@use] and defined? idx_hash[@use] - idx_hash[@use][:sub] << {sub.strip => { plus: sub_plus }} - end - term_nodes << subterm_nodes - end - end - idx_array << term_nodes - end - { hash: idx_hash, array: idx_array } - end - def identify_parts - tuned_file=[] - @tuned_block,@tuned_code=[],[] - @@counter,@verse_count=0,0 - @metadata={} - @data.each do |t_o| - if t_o =~/^--([+~-])[#]$/ - h=case $1 - when /[+]/ - @@flag[:ocn]=:on - {flag: :ocn_on} - when /[~]/ - @@flag[:ocn]=:off_headings_substantive - {flag: :ocn_off, mod: :headings_substantive} - when /[-]/ - @@flag[:ocn]=:off_headings_exclude - {flag: :ocn_off, mod: :headings_exclude} - else - @@flag[:ocn]=:on - {flag: :ocn_on} - end - t_o=SiSU_DAL_DocumentStructure::ObjectFlag.new.flag_ocn(h) - next - end - t_o=t_o.gsub(/(?:\n\s*\n)+/m,"\n") if @@flag[:code]==:off - if t_o !~/^(?:code|poem|alt|group|block)\{|^\}(?:code|poem|alt|group|block)|^(?:table\{|\{table)[ ~]/ \ - and t_o !~/^[`]{3}\s+(?:code|poem|alt|group|block|table)|^[`]{3}(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/ \ - and @@flag[:code]==:off \ - and @@flag[:poem]==:off \ - and @@flag[:group]==:off \ - and @@flag[:block]==:off \ - and @@flag[:alt]==:off \ - and @@flag[:table]==:off - unless t_o =~/^(?:@\S+?:|%+)\s/ # extract book index for paragraph if any - idx=if t_o=~/^=\{(.+)\}\s*$\Z/m; m=$1 - m=m.split(/\n/).join(' '). - gsub(/\s+([|:;])\s+/,'\1'). - gsub(/\s+([+]\d+)\s+/,'\1') - t_o=t_o.gsub(/\n=\{.+\}\s*$\Z/m,'') - idx_array_and_hash=construct_idx_array_and_hash(m) - idx_array_and_hash[:hash] - else nil - end - end - t_o=case t_o - when /^#{Mx[:meta_o]}\S+?#{Mx[:meta_c]}/ #metadata, header - if t_o=~/^#{Mx[:meta_o]}(\S+?)#{Mx[:meta_c]}\s*(.+)/m - tag,obj=$1,$2 - @metadata[tag]=obj - end - t_o=nil - when /^%+\s/ #comment - t_o=if t_o=~/^%+\s+(.+)/ - h={obj: $1} - SiSU_DAL_DocumentStructure::ObjectComment.new.comment(h) - else nil - end - when /^:?([A-C1-6])\~/ #heading / lv - lv=$1 - ln=ln_get(lv) - t_o=if t_o=~/^:?[A-C1-6]\~\s+(.+)/m - obj=$1 - note=endnote_test?(obj) - obj,tags=extract_tags(obj) - if @@flag[:ocn]==:off_headings_exclude \ - or @@flag[:ocn]==:off_headings_substantive - unless obj =~ /[~-][#]\s*$/ - if @@flag[:ocn]==:off_headings_exclude - obj << ' -#' - elsif @@flag[:ocn]==:off_headings_substantive - obj << ' ~#' - end - end - end - h={ lv: lv, ln: ln, obj: obj, idx: idx, tags: tags } - SiSU_DAL_DocumentStructure::ObjectHeading.new.heading(h) - elsif t_o=~/^:?[A-C1-6]\~(\S+?)-\s+(.+)/m - name,obj=$1,$2 - note=endnote_test?(obj) - obj,tags=extract_tags(obj) - if @@flag[:ocn]==:off_headings_exclude \ - or @@flag[:ocn]==:off_headings_substantive - unless obj =~ /[~-][#]\s*$/ - if @@flag[:ocn]==:off_headings_exclude - obj << ' -#' - elsif @@flag[:ocn]==:off_headings_substantive - obj << ' ~#' - end - end - end - h={ lv: lv, name: name, obj: obj, idx: idx, autonum_: false, tags: tags} - SiSU_DAL_DocumentStructure::ObjectHeading.new.heading(h) - elsif t_o=~/^:?[A-C1-6]\~(\S+)\s+(.+)/m - name,obj=$1,$2 - note=endnote_test?(obj) - obj,tags=extract_tags(obj,name) - if @@flag[:ocn]==:off_headings_exclude \ - or @@flag[:ocn]==:off_headings_substantive - unless obj =~ /[~-][#]\s*$/ - if @@flag[:ocn]==:off_headings_exclude - obj << ' -#' - elsif @@flag[:ocn]==:off_headings_substantive - obj << ' ~#' - end - end - end - h={ lv: lv, name: name, obj: obj, idx: idx, tags: tags } - SiSU_DAL_DocumentStructure::ObjectHeading.new.heading(h) - else nil - end - when /^_(?:[1-9]!?|[1-9]?\*)\s+/ #indented and/or bullet paragraph - t_o=if t_o=~/^(_(?:[1-9]?\*|[1-9]!?)\s+)(.+)/m - tst,obj=$1,$2 - if t_o=~/^_[1-9]!\s+.+/m - hang,indent,obj=hang_and_indent_def_test(tst,obj) - else - hang,indent=hang_and_indent_test(tst) - end - bullet=bullet_test(tst) - image=image_test(obj) - note=endnote_test?(obj) - obj,tags=extract_tags(obj) - unless obj=~/\A\s*\Z/m - if @@flag[:ocn]==:off_headings_exclude \ - or @@flag[:ocn]==:off_headings_substantive - unless obj =~ /[~-][#]\s*$/ - obj << ' ~#' - end - end - h={ bullet_: bullet, hang: hang, indent: indent, obj: obj, idx: idx, note_: note, image_: image, tags: tags } - SiSU_DAL_DocumentStructure::ObjectPara.new.paragraph(h) - end - else nil - end - when /^_[0-9]?_[0-9]!?\s+/ #hanging indent paragraph - t_o=if t_o=~/^(_[0-9]?_[0-9]!?\s+)(.+)/m - tst,obj=$1,$2 - if t_o=~/^_[0-9]?_[0-9]!\s+.+/m - hang,indent,obj=hang_and_indent_def_test(tst,obj) - else - hang,indent=hang_and_indent_test(tst) - end - image=image_test(obj) - note=endnote_test?(obj) - obj,tags=extract_tags(obj) - unless obj=~/\A\s*\Z/m - if @@flag[:ocn]==:off_headings_exclude \ - or @@flag[:ocn]==:off_headings_substantive - unless obj =~ /[~-][#]\s*$/ - obj << ' ~#' - end - end - h={ hang: hang, indent: indent, obj: obj, idx: idx, note_: note, image_: image, tags: tags } - SiSU_DAL_DocumentStructure::ObjectPara.new.paragraph(h) - end - else nil - end - when /^<(?:br)?:(?:pa?r|o(?:bj|---)?)>\s*$/ #[br:par] #[br:obj] - SiSU_DAL_DocumentStructure::ObjectLayout.new.break(Hx[:br_obj]) - when /^(?:-\\\\-|<:pb>)\s*$/ #[br:pg] - SiSU_DAL_DocumentStructure::ObjectLayout.new.break(Hx[:br_page],:markup) - when /^(?:=\\\\=|<:pn>)\s*$/ #[br:pgn] - SiSU_DAL_DocumentStructure::ObjectLayout.new.break(Hx[:br_page_new],:markup) - when /^-\.\.-\s*$/ #[br:pgl] - SiSU_DAL_DocumentStructure::ObjectLayout.new.break(Hx[:br_page_line],:markup) - else #paragraph - image=image_test(t_o) - note=endnote_test?(t_o) - obj,tags=extract_tags(t_o) - if @@flag[:ocn]==:off_headings_exclude \ - or @@flag[:ocn]==:off_headings_substantive - unless obj =~ /[~-][#]\s*$/ - obj << ' ~#' - end - end - unless obj=~/\A\s*\Z/m - h={ bullet_: false, indent: 0, hang: 0, obj: obj, idx: idx, note_: note, image_: image, tags: tags } - SiSU_DAL_DocumentStructure::ObjectPara.new.paragraph(h) - end - end - elsif @@flag[:code]==:off - if t_o =~/^(?:code\{|[`]{3}\s+code)/ - @@flag[:code]=case t_o - when /^code\{/; :curls - when /^[`]{3}\s+code/; :tics - else @@flag[:code] #error - end - @@counter=1 - @codeblock_numbered=(t_o =~/^(?:code\{#|[`]{3}\s+code\s[#])/) ? true : false - h={ obj: 'code block start' } #introduce a counter - t_o=SiSU_DAL_DocumentStructure::ObjectComment.new.comment(h) - elsif t_o =~/^(?:poem\{|[`]{3}\s+poem)/ - @@flag[:poem]=case t_o - when /^poem\{/; :curls - when /^[`]{3}\s+poem/; :tics - else @@flag[:poem] #error - end - h={ obj: 'poem start' } #introduce a counter - t_o=SiSU_DAL_DocumentStructure::ObjectComment.new.comment(h) - tuned_file << t_o - elsif t_o =~/^(?:group\{|[`]{3}\s+group)/ - @@flag[:group]=case t_o - when /^group\{/; :curls - when /^[`]{3}\s+group/; :tics - else @@flag[:group] #error - end - h={ obj: 'group text start' } #introduce a counter - t_o=SiSU_DAL_DocumentStructure::ObjectComment.new.comment(h) - tuned_file << t_o - elsif t_o =~/^(?:block\{|[`]{3}\s+block)/ - @@flag[:block]=case t_o - when /^block\{/; :curls - when /^[`]{3}\s+block/; :tics - else @@flag[:block] #error - end - h={ obj: 'block text start' } #introduce a counter - t_o=SiSU_DAL_DocumentStructure::ObjectComment.new.comment(h) - tuned_file << t_o - elsif t_o =~/^(?:alt\{|[`]{3}\s+alt)/ - @@flag[:alt]=case t_o - when /^alt\{/; :curls - when /^[`]{3}\s+alt/; :tics - else @@flag[:alt] #error - end - h={ obj: 'alt text start' } #introduce a counter - t_o=SiSU_DAL_DocumentStructure::ObjectComment.new.comment(h) - tuned_file << t_o - elsif t_o =~/^(?:table\{|[`]{3}\s+table|\{table)[ ~]/ - h={ obj: 'table start' } #introduce a counter - ins=SiSU_DAL_DocumentStructure::ObjectComment.new.comment(h) - tuned_file << ins - if t_o=~/^table\{(?:~h)?\s+/ - @@flag[:table]=:curls - @rows='' - case t_o - when /table\{~h\s+c(\d+);\s+(.+)/ - cols=$1 - col=$2.scan(/\d+/) - heading=true - when /table\{\s+c(\d+);\s+(.+)/ - cols=$1 - col=$2.scan(/\d+/) - heading=false - end - @h={ head_: heading, cols: cols, widths: col, idx: idx } - elsif t_o=~/^[`]{3}\s+table(?:~h)?\s+c\d+/ - @@flag[:table]=:tics - @rows='' - case t_o - when /^[`]{3}\s+table~h\s+c(\d+);\s+(.+)/ - cols=$1 - col=$2.scan(/\d+/) - heading=true - when /^[`]{3}\s+table\s+c(\d+);\s+(.+)/ - cols=$1 - col=$2.scan(/\d+/) - heading=false - end - @h={ head_: heading, cols: cols, widths: col, idx: idx } - elsif t_o=~/^\{table(?:~h)?(?:\s+\d+;?)?\}\n.+\Z/m - m1,m2,hd=nil,nil,nil - tbl=/^\{table(?:~h)?(?:\s+\d+;?)?\}\n(.+)\Z/m.match(t_o)[1] - hd=((t_o =~/^\{table~h/) ? true : false) - tbl,tags=extract_tags(tbl) - rws=tbl.split(/\n/) - rows='' - cols=nil - rws.each do |r| - cols=(cols ? cols : (r.scan('|').length) +1) - r=r.gsub(/\s*\|\s*/m,"#{Mx[:tc_p]}") #r.gsub!(/\|/m,"#{Mx[:tc_p]}") - rows += r + Mx[:tc_c] - end - col=[] - if t_o =~/^\{table(?:~h)?\s+(\d+);?\}/ #width of col 1 given as %, usually when wider than rest that are even - c1=$1.to_i - width=(100 - c1)/(cols - 1) - col=[ c1 ] - (cols - 1).times { col << width } - else #all columns of equal width - width=100.00/cols - cols.times { col << width } - end - h={ head_: hd, cols: cols, widths: col, obj: rows, idx: idx, tags: tags } - t_o=SiSU_DAL_DocumentStructure::ObjectTable.new.table(h) unless h.nil? - tuned_file << t_o - h={ obj: 'table end' } #introduce a counter - t_o=SiSU_DAL_DocumentStructure::ObjectComment.new.comment(h) - t_o - elsif t_o=~/^[`]{3}\s+table(?:~h)?\s+/ - m1,m2,hd=nil,nil,nil - h=case t_o - when /^[`]{3}\s+table~h\s+(.+?)\n(.+)\Z/m #two table representations should be consolidated as one - m1,tbl,hd=$1,$2,true - when /^[`]{3}\s+table\s+(.+?)\n(.+)\Z/m #two table representations should be consolidated as one - m1,tbl,hd=$1,$2,false - else nil - end - tbl,tags=extract_tags(tbl) - col=m1.scan(/\d+/) - rws=tbl.split(/\n/) - rows='' - rws.each do |r| - r=r.gsub(/\s*\|\s*/m,"#{Mx[:tc_p]}") #r.gsub!(/\|/m,"#{Mx[:tc_p]}") - rows += r + Mx[:tc_c] - end - h={ head_: hd, cols: col.length, widths: col, obj: rows, idx: idx, tags: tags } - t_o=SiSU_DAL_DocumentStructure::ObjectTable.new.table(h) unless h.nil? - tuned_file << t_o - h={ obj: 'table end' } #introduce a counter - t_o=SiSU_DAL_DocumentStructure::ObjectComment.new.comment(h) - t_o - elsif t_o=~/^\{table(?:~h)?\s+/ - m1,m2,hd=nil,nil,nil - h=case t_o - when /\{table~h\s+(.+?)\}\n(.+)\Z/m #two table representations should be consolidated as one - m1,tbl,hd=$1,$2,true - when /\{table\s+(.+?)\}\n(.+)\Z/m #two table representations should be consolidated as one - m1,tbl,hd=$1,$2,false - else nil - end - tbl,tags=extract_tags(tbl) - col=m1.scan(/\d+/) - rws=tbl.split(/\n/) - rows='' - rws.each do |r| - r=r.gsub(/\s*\|\s*/m,"#{Mx[:tc_p]}") #r.gsub!(/\|/m,"#{Mx[:tc_p]}") - rows += r + Mx[:tc_c] - end - h={ head_: hd, cols: col.length, widths: col, obj: rows, idx: idx, tags: tags } - t_o=SiSU_DAL_DocumentStructure::ObjectTable.new.table(h) unless h.nil? - tuned_file << t_o - h={ obj: 'table end' } #introduce a counter - t_o=SiSU_DAL_DocumentStructure::ObjectComment.new.comment(h) - t_o - end - end - t_o - end - if @@flag[:table]==:curls or @@flag[:table]==:tics - if (@@flag[:table]==:curls \ - and t_o =~/^\}table/) \ - or (@@flag[:table]==:tics \ - and t_o =~/^[`]{3}(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/) - @@flag[:table]=:off - headings,columns,widths,idx=@h[:head_],@h[:cols],@h[:widths],@h[:idx] - @h={ head_: headings, cols: columns, widths: widths, idx: idx, obj: @rows } - t_o=SiSU_DAL_DocumentStructure::ObjectTable.new.table(@h) - tuned_file << t_o - @h,@rows=nil,'' - h={ obj: 'table end' } #introduce a counter - t_o=SiSU_DAL_DocumentStructure::ObjectComment.new.comment(h) - t_o - else - if t_o.is_a?(String) \ - and t_o !~/^(?:table\{|[`]{3}\s+table)/ - t_o=t_o.gsub(/^\n+/m,''). #check added for ruby 1.9.2 not needed in 1.8 series (tested in v2) - gsub(/\n+/m,"#{Mx[:tc_p]}") - @rows += t_o + Mx[:tc_c] - end - t_o=nil - end - end - if @@flag[:code]==:curls or @@flag[:code]==:tics - if (@@flag[:code]==:curls and t_o =~/^\}code/) \ - or (@@flag[:code]==:tics and t_o =~/^[`]{3}(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/) - @@flag[:code]=:off - obj=@tuned_code.join("\n") - tags=[] - h={ obj: obj, tags: tags, number_: @codeblock_numbered } - t_o=SiSU_DAL_DocumentStructure::ObjectBlockTxt.new.code(h) - @tuned_code=[] - tuned_file << t_o - h={ obj: 'code block end' } #introduce a counter - t_o=SiSU_DAL_DocumentStructure::ObjectComment.new.comment(h) - end - if (@@flag[:code]==:curls or @@flag[:code]==:tics) \ - and t_o.is_a?(String) - sub_array=t_o.dup + "#{Mx[:br_nl]}" - @line_mode=[] - sub_array.scan(/.+/) {|w| @line_mode << w if w =~/[\S]+/} - t_o=SiSU_DAL_DocumentStructureExtract::Build.new(@md,@line_mode).build_lines(:code).join - @tuned_code << t_o - t_o=nil - end - elsif (@@flag[:poem]==:curls or @@flag[:poem]==:tics) \ - or (@@flag[:group]==:curls or @@flag[:group]==:tics) \ - or (@@flag[:block]==:curls or @@flag[:block]==:tics) \ - or (@@flag[:alt]==:curls or @@flag[:alt]==:tics) - if (@@flag[:poem]==:curls and t_o =~/^\}poem/) \ - or (@@flag[:poem]==:tics and t_o =~/^[`]{3}(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/) - @@flag[:poem]=:off - h={ obj: 'poem end' } #introduce a counter - t_o=SiSU_DAL_DocumentStructure::ObjectComment.new.comment(h) - elsif (@@flag[:group]==:curls and t_o =~/^\}group/) \ - or (@@flag[:group]==:tics and t_o =~/^[`]{3}(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/) - @@flag[:group]=:off - obj,tags=extract_tags(@tuned_block.join("\n")) - h={ obj: obj, tags: tags } - @tuned_block=[] - t_o=SiSU_DAL_DocumentStructure::ObjectBlockTxt.new.group(h) - tuned_file << t_o - h={ obj: 'group text end' } #introduce a counter - t_o=SiSU_DAL_DocumentStructure::ObjectComment.new.comment(h) - elsif (@@flag[:block]==:curls and t_o =~/^\}block/) \ - or (@@flag[:block]==:tics and t_o =~/^[`]{3}(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/) - @@flag[:block]=:off - obj,tags=extract_tags(@tuned_block.join("\n")) - h={ obj: obj, tags: tags } - @tuned_block=[] - t_o=SiSU_DAL_DocumentStructure::ObjectBlockTxt.new.block(h) - tuned_file << t_o - h={ obj: 'block text end' } #introduce a counter - t_o=SiSU_DAL_DocumentStructure::ObjectComment.new.comment(h) - elsif (@@flag[:alt]==:curls and t_o =~/^\}alt/) \ - or (@@flag[:alt]==:tics and t_o =~/^[`]{3}(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/) - @@flag[:alt]=:off - obj,tags=extract_tags(@tuned_block.join("\n")) - h={ obj: obj, tags: tags } - t_o=SiSU_DAL_DocumentStructure::ObjectBlockTxt.new.alt(h) - @tuned_block=[] - tuned_file << t_o - h={ obj: 'alt text end' } #introduce a counter - t_o=SiSU_DAL_DocumentStructure::ObjectComment.new.comment(h) - end - if (@@flag[:poem]==:curls or @@flag[:poem]==:tics \ - or @@flag[:group]==:curls or @@flag[:group]==:tics \ - or @@flag[:alt]==:curls or @@flag[:alt]==:tics) \ - and t_o =~/\S/ \ - and t_o !~/^(?:\}(?:verse|code|alt|group|block)|(?:verse|code|alt|group|block)\{)/ \ - and t_o !~/^[`]{3}\s+(?:code|poem|alt|group|block)|^[`]{3}(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/ # fix logic - sub_array=t_o.dup - @line_mode=sub_array.scan(/.+/) - type=if @@flag[:poem]==:curls or @@flag[:poem]==:tics - t_o=SiSU_DAL_DocumentStructureExtract::Build.new(@md,@line_mode).build_lines(type).join - poem=t_o.split(/\n\n/) - poem.each do |v| - v=v.gsub(/\n/m,"#{Mx[:br_nl]}\n") - obj,tags=extract_tags(v) - h={ obj: obj, tags: tags } - t_o=SiSU_DAL_DocumentStructure::ObjectBlockTxt.new.verse(h) - tuned_file << t_o - end - :poem - else :group - end - end - @verse_count+=1 if @@flag[:poem]==:curls or @@flag[:poem]==:tics - end - if @@flag[:code]==:off - if @@flag[:poem]==:curls or @@flag[:poem]==:tics \ - or @@flag[:group]==:curls or @@flag[:group]==:tics \ - or @@flag[:alt]==:curls or @@flag[:alt]==:tics - if t_o.is_a?(String) - t_o=t_o.gsub(/\n/m,"#{Mx[:br_nl]}"). - gsub(/[ ][ ]/m,"#{Mx[:nbsp]*2}"). - gsub(/#{Mx[:nbsp]}\s/,"#{Mx[:nbsp]*2}") - t_o=t_o + Mx[:br_nl] if t_o =~/\S+/ - elsif t_o.is==:group \ - || t_o.is==:block \ - || t_o.is==:alt \ - || t_o.is==:verse - t_o.obj=t_o.obj.gsub(/\n/m,"#{Mx[:br_nl]}"). - gsub(/[ ][ ]/m,"#{Mx[:nbsp]*2}"). - gsub(/#{Mx[:nbsp]}\s/,"#{Mx[:nbsp]*2}") - end - @tuned_block << t_o if t_o =~/\S+/ - else tuned_file << t_o - end - else tuned_file << t_o - end - end - if @md.flag_endnotes - tuned_file << @pb - h={ ln: 2, lc: 2, obj: 'Endnotes', autonum_: false } - tuned_file << SiSU_DAL_DocumentStructure::ObjectHeading.new.heading_insert(h) - h={ ln: 4, lc: 3, obj: 'Endnotes', name: 'endnotes', autonum_: false } - tuned_file << SiSU_DAL_DocumentStructure::ObjectHeading.new.heading_insert(h) - h={ obj: 'Endnotes' } - end - if @md.book_idx - tuned_file << @pb - h={ ln: 2, lc: 2, obj: 'Index', autonum_: false } - tuned_file << SiSU_DAL_DocumentStructure::ObjectHeading.new.heading_insert(h) - h={ ln: 4, lc: 3, obj: 'Index', name: 'book_index', autonum_: false } - tuned_file << SiSU_DAL_DocumentStructure::ObjectHeading.new.heading_insert(h) - h={ obj: 'Index' } - end - tuned_file << @pb - h={ ln: 2, lc: 2, obj: 'Metadata', autonum_: false, ocn_: false } - tuned_file << SiSU_DAL_DocumentStructure::ObjectHeading.new.heading_insert(h) - h={ ln: 4, lc: 3, obj: 'SiSU Metadata, document information', name: 'metadata', autonum_: false, ocn_: false } - tuned_file << SiSU_DAL_DocumentStructure::ObjectHeading.new.heading_insert(h) - h={ obj: 'eof' } - meta=SiSU_DAL_DocumentStructure::ObjectMetadata.new.metadata(@metadata) - [tuned_file,meta] - end - def table_rows_and_columns_array(table_str) - table=[] - table_str.split(/#{Mx[:tc_c]}/).each do |table_row| - table_row_with_columns=table_row.split(/#{Mx[:tc_p]}/) - table << table_row_with_columns - end - table - end - def meta_heading(h) - h={ lv: h[:lv], ln: h[:ln], name: h[:name], obj: h[:obj], ocn: '0' } - SiSU_DAL_DocumentStructure::ObjectHeading.new.heading(h) - end - def meta_para(str) - h={ obj: str, ocn_: false } - SiSU_DAL_DocumentStructure::ObjectPara.new.paragraph(h) - end - def build_lines(type=:none) - lines,lines_new=@data,[] - lines.each do |line| - line=if line =~/\S/ \ - and line !~/^(?:code\{|\}code)/ \ - and line !~/^(?:[`]{3}\s+code|[`]{3}(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$)/ \ - and not line.is_a?(Hash) #watch - @@counter+=1 if @@flag[:code]==:curls or @@flag[:code]==:tics - line=line.gsub(/\s\s/,"#{Mx[:nbsp]*2}"). - gsub(/#{Mx[:nbsp]}\s/,"#{Mx[:nbsp]*2}") - line=line.gsub(/^/,"#{Mx[:gr_o]}codeline#{Mx[:gr_c]}") if type==:code # REMOVE try sort for texpdf special case - line=if line =~/(?:https?|file|ftp):\/\/\S+$/ - line.gsub(/\s*$/," #{Mx[:br_nl]}") - else line.gsub(/\s*$/,"#{Mx[:br_nl]}") #unless type=='code' - end - elsif line =~/^\s*$/ - line.gsub(/\s*$/,"#{Mx[:br_nl]}") - else line - end - lines_new << line - end - lines_new - end - end - class Structure # this must happen early - def initialize(md,dob) - @md,@dob=md,dob - end - def structure - structure_markup - @dob - end - def structure_markup #build structure where structure provided only in meta header - @dob=if @dob.is==:para \ - && (((@dob.hang !~/[1-9]/) && (@dob.indent !~/[1-9]/)) \ - || (@dob.hang != @dob.indent)) \ - and not @dob.bullet_ - @dob=case @dob.obj - when /^#{@md.lv1}/ - h={ lv: 'A', ln: 1 } - SiSU_DAL_DocumentStructure::ObjectHeading.new.heading(h,@dob) - when /^#{@md.lv2}/ - h={ lv: 'B', ln: 2 } - SiSU_DAL_DocumentStructure::ObjectHeading.new.heading(h,@dob) - when /^#{@md.lv3}/ - h={ lv: 'C', ln: 3 } - SiSU_DAL_DocumentStructure::ObjectHeading.new.heading(h,@dob) - when /^#{@md.lv4}/ - h={ lv: '1', ln: 4 } - SiSU_DAL_DocumentStructure::ObjectHeading.new.heading(h,@dob) - when /^#{@md.lv5}/ - h={ lv: '2', ln: 5 } - SiSU_DAL_DocumentStructure::ObjectHeading.new.heading(h,@dob) - when /^#{@md.lv6}/ - h={ lv: '3', ln: 6 } - SiSU_DAL_DocumentStructure::ObjectHeading.new.heading(h,@dob) - else @dob - end - else @dob - end - @dob - end - end - class OCN - def initialize(md,data) - @md,@data=md,data - end - def structure_info - def lv - %w[0 A~ B~ C~ 1 2 3] - end - def possible_parents(child) - case child - when /A~/ - 'none' - when /B~/ - 'A~' - when /C~/ - 'B~' - when /1/ - 'A~, B~, C~' - when /2/ - '1' - when /3/ - '3' - end - end - def possible_children(parent) - case parent - when /A~/ - 'B~, 1' - when /B~/ - 'C~, 1' - when /C~/ - '1' - when /1/ - '2' - when /2/ - '3' - when /3/ - 'none' - end - end - self - end - def document_structure_check_info(node,node_parent,status=:ok) - node_ln=/^([0-6])/.match(node)[1].to_i - node_parent_ln=/^([0-6])/.match(node_parent)[1].to_i - if status==:error \ - or @md.opt.act[:maintenance][:set]==:on - puts %{node: #{node}, parent node: #{node_parent} #{status.upcase}} - if status==:error - node_ln=/^([0-6])/.match(node)[1].to_i - node_parent_ln=/^([0-6])/.match(node_parent)[1].to_i - puts %{current level: #{structure_info.lv[node_ln]} (possible parent levels: #{structure_info.possible_parents(structure_info.lv[node_ln])}) -parent level: #{structure_info.lv[node_parent_ln]} (possible child levels: #{structure_info.possible_children(structure_info.lv[node_parent_ln])}) --- } - end - end - end - def warning_incorrect_parent_level_or_level(txt) - puts %{warning, -#{txt} -has incorrect level and/or parent level} - end - def ocn #and auto segment numbering increment - data=@data - @o_array=[] - node=ocn=ocn_dv=ocn_sp=ocnh=ocnh1=ocnh2=ocnh3=ocnh4=ocnh5=ocnh6=ocno=ocnp=ocnt=ocnc=ocng=ocni=ocnu=0 # h heading, o other, t table, g group, i image - regex_exclude_ocn_and_node = /#{Rx[:meta]}|^@\S+?:\s|^4~endnotes|^#{Mx[:lv_o]}4:endnotes#{Mx[:lv_c]}|^\^~ |<:e[:_]\d+?>|^<:\#|<:- |<[:!]!4|
- if dob.is==:heading - ln=case dob.lv - when 'A'; 1 - when 'B'; 2 - when 'C'; 3 - when '1'; 4 - when '2'; 5 - when '3'; 6 - when '4'; 7 - when '5'; 8 - when '6'; 9 - end - end - if not dob.obj =~/~#|-#/ - ocn+=1 - end - if dob.is==:heading \ - and (ln.to_s =~/^[1-9]/ \ - or ln.to_s =~@md.lv1 \ - or ln.to_s =~@md.lv2 \ - or ln.to_s =~@md.lv3 \ - or ln.to_s =~@md.lv4 \ - or ln.to_s =~@md.lv5 \ - or ln.to_s =~@md.lv6) - if not dob.obj =~/~#|-#/ - ocnh+=1 - end - if ln==1 \ - or ln=~@md.lv1 - if not dob.obj =~/~#|-#/ - ocn_flag=true - ocnh1+=1 #heading - node1="1:#{ocnh1};#{ocn}" - else - ocn_flag=false - node1="1:0;0" - end - document_structure_check_info(node1,node0) - @collapsed_lv1=1 - collapsed_level=@collapsed_lv1 - node,ocn_sp,parent=node1,"h#{ocnh}",node0 #FIX - elsif ln==2 \ - or ln=~@md.lv2 - if not dob.obj =~/~#|-#/ - ocn_flag=true - ocnh2+=1 - node2="2:#{ocnh2};#{ocn}" - else - ocn_flag=false - node2="2:0;0" - end - parent=if node1 - document_structure_check_info(node2,node1) - @collapsed_lv2=@collapsed_lv1+1 - node1 - else - document_structure_check_info(node2,node0,:error) - node0 - end - collapsed_level=@collapsed_lv2 - node,ocn_sp=node2,"h#{ocnh}" - elsif ln==3 \ - or ln=~@md.lv3 - if not dob.obj =~/~#|-#/ - ocn_flag=true - ocnh3+=1 - node3="3:#{ocnh3};#{ocn}" - else - ocn_flag=false - node3="3:0;0" - end - parent=if node2 - document_structure_check_info(node3,node2) - @collapsed_lv3=@collapsed_lv2+1 - node2 - elsif node1 - warning_incorrect_parent_level_or_level(dob.obj) - puts %{parent is :A~ & this level #{dob.lv} -either parent should be level :B~ -or this level should be level :B~ rather than #{dob.lv}} - document_structure_check_info(node3,node1,:error) - @collapsed_lv3=@collapsed_lv1+1 - node1 - else - document_structure_check_info(node3,node0,:error) - warning_incorrect_parent_level_or_level(dob.obj) - node0 - end - collapsed_level=@collapsed_lv3 - node,ocn_sp=node3,"h#{ocnh}" - elsif ln==4 \ - or ln=~@md.lv4 - if not dob.obj =~/~#|-#/ - ocn_flag=true - ocnh4+=1 - node4="4:#{ocnh4};#{ocn}" - else - ocn_flag=false - node4="4:0;0" - end - parent=if node3 - document_structure_check_info(node4,node3) - @collapsed_lv4=@collapsed_lv3+1 - node3 - elsif node2 - document_structure_check_info(node4,node2) - @collapsed_lv4=@collapsed_lv2+1 - node2 - elsif node1 - document_structure_check_info(node4,node1) - @collapsed_lv4=@collapsed_lv1+1 - node1 - else - warning_incorrect_parent_level_or_level(dob.obj) - document_structure_check_info(node4,node0,:error) - node0 - end - collapsed_level=@collapsed_lv4 - node,ocn_sp=node4,"h#{ocnh}" - elsif ln==5 \ - or ln=~@md.lv5 - if not dob.obj =~/~#|-#/ - ocn_flag=true - ocnh5+=1 - node5="5:#{ocnh5};#{ocn}" - else - ocn_flag=false - node5="5:0;0" - end - parent=if node4 - document_structure_check_info(node5,node4) - @collapsed_lv5=@collapsed_lv4+1 - node4 - elsif node3 - warning_incorrect_parent_level_or_level(dob.obj) - document_structure_check_info(node5,node3,:error) - @collapsed_lv5=@collapsed_lv3+1 - node3 - elsif node2 - warning_incorrect_parent_level_or_level(dob.obj) - document_structure_check_info(node5,node2,:error) - @collapsed_lv5=@collapsed_lv2+1 - node2 - elsif node1 - warning_incorrect_parent_level_or_level(dob.obj) - document_structure_check_info(node5,node1,:error) - @collapsed_lv5=@collapsed_lv1+1 - node1 - else - document_structure_check_info(node5,node0,:error) - node0 - end - collapsed_level=@collapsed_lv5 - node,ocn_sp=node5,"h#{ocnh}" - elsif ln==6 \ - or ln=~@md.lv6 - if not dob.obj =~/~#|-#/ - ocn_flag=true - ocnh6+=1 - node6="6:#{ocnh6};#{ocn}" - else - ocn_flag=false - node6="6:0;0" - end - parent=if node5 - document_structure_check_info(node6,node5) - @collapsed_lv6=@collapsed_lv5+1 - node5 - elsif node4 - warning_incorrect_parent_level_or_level(dob.obj) - puts "parent is level 4~ & this level #{dob.lv} -either parent should be level 5~ -or this level should be 5~ rather #{dob.lv}" #level 6 - document_structure_check_info(node6,node4,:error) - @collapsed_lv6=@collapsed_lv4+1 - node4 - elsif node3 - warning_incorrect_parent_level_or_level(dob.obj) - document_structure_check_info(node6,node3,:error) - @collapsed_lv6=@collapsed_lv3+1 - node3 - elsif node2 - warning_incorrect_parent_level_or_level(dob.obj) - document_structure_check_info(node6,node2,:error) - @collapsed_lv6=@collapsed_lv2+1 - node2 - elsif node1 - warning_incorrect_parent_level_or_level(dob.obj) - document_structure_check_info(node6,node1,:error) - @collapsed_lv6=@collapsed_lv1+1 - node1 - else - document_structure_check_info(node6,node0,:error) - node0 - end - collapsed_level=@collapsed_lv6 - node,ocn_sp=node6,"h#{ocnh}" - end - else - if not dob.obj =~/~#|-#/ - ocn_flag=true - else - ocn_flag=false - end - ocno+=1 - if dob.is==:table - ocnt+=1 - ocn_sp,parent="t#{ocnt}",node - elsif dob.is==:code - ocnc+=1 - ocn_sp,parent="c#{ocnc}",node - elsif dob.is==:group \ - || dob.is==:block \ - || dob.is==:alt \ - || dob.is==:verse - ocng+=1 #group, poem - ocn_sp,parent="g#{ocng}",node - elsif dob.is==:image #check - ocni+=1 - ocn_sp,parent="i#{ocni}",node - else ocnp+=1 #paragraph - ocn_sp,parent="p#{ocnp}",node - end - end - if dob.is==:heading - if ocn_flag==true - dob.ln,dob.node,dob.ocn,dob.ocn_,dob.odv,dob.osp,dob.parent,dob.lc=ln,node,ocn,ocn_flag,ocn_dv,ocn_sp,parent,collapsed_level - else - ocnu+=1 - dob.obj=dob.obj.gsub(/#{Mx[:fa_o]}[~-]##{Mx[:fa_c]}/,'') if dob.obj - ocn_dv,ocn_sp="u#{ocnu}","u#{ocnu}" - dob.ln,dob.node,dob.ocn,dob.ocn_,dob.odv,dob.osp,dob.parent,dob.lc=ln,node,nil,ocn_flag,ocn_dv,ocn_sp,parent,collapsed_level - end - else - if dob.of !=:meta \ - && dob.of !=:comment \ - && dob.of !=:layout - if ocn_flag == true - dob.ocn,dob.ocn_,dob.odv,dob.osp,dob.parent=ocn,ocn_flag,ocn_dv,ocn_sp,parent - else - ocnu+=1 - dob.obj=dob.obj.gsub(/#{Mx[:fa_o]}[~-]##{Mx[:fa_c]}/,'') if dob.obj - ocn_dv,ocn_sp="u#{ocnu}","u#{ocnu}" - dob.ocn,dob.ocn_,dob.odv,dob.osp,dob.parent=nil,ocn_flag,ocn_dv,ocn_sp,parent - end - end - end - h - elsif dob.obj=~/#{Mx[:pa_non_object_no_heading]}/ - dob.obj=dob.obj.gsub(/#{Mx[:pa_non_object_no_heading]}/,'') - if dob.is==:para - h={ obj: dob.obj, ocn_: false, ocn: nil, hang: dob.hang, indent: dob.indent, bullet_: dob.bullet_, tags: dob.tags, parent: dob.parent } - dob=SiSU_DAL_DocumentStructure::ObjectPara.new.paragraph(h,dob) - elsif dob.is==:heading - h={ obj: dob.obj, ocn_: false, ocn: nil, toc_: true, parent: dob.parent } - dob=SiSU_DAL_DocumentStructure::ObjectHeading.new.heading(h,dob) - end - elsif dob.obj=~/#{Mx[:pa_non_object_dummy_heading]}/ - dob.obj=dob.obj.gsub(/#{Mx[:pa_non_object_dummy_heading]}/,'') - if dob.is==:para - h={ obj: dob.obj, ocn_: false, ocn: nil, hang: dob.hang, indent: dob.indent, bullet_: dob.bullet_, tags: dob.tags, parent: dob.parent } - dob=SiSU_DAL_DocumentStructure::ObjectPara.new.paragraph(h,dob) - elsif dob.is==:heading - h={ obj: dob.obj, ocn_: false, ocn: nil, toc_: false, parent: dob.parent } - dob=SiSU_DAL_DocumentStructure::ObjectHeading.new.heading(h,dob) - end - else dob - end - if dob.is==:code \ - || dob.is==:verse \ - || dob.is==:alt \ - || dob.is==:group \ - || dob.is==:block - dob.obj=dob.obj.gsub(/\n\n/,"\n") #newlines taken out - end - @o_array << dob - end - @o_array - end - end - class XML - def initialize(md,data) - @data,@md=data,md - end - def dom - @s=['0', - 'A', - 'B', - 'C', - '1', - '2', - '3' - ] - @sp=' ' - tuned_file=structure_build - tuned_file - end - def structure_build - data=@data - tuned_file=[] - hs=[0,false,false,false] - t={ lv: @s[0], status: 'open' } - tuned_file << tags(t) - if @md.opt.act[:verbose_plus][:set]==:on - puts "\nXML sisu structure outline --->\n" - puts "<#{@s[0]}>" - end - data.each_with_index do |o,i| - if o.is==:heading \ - || o.is==:heading_insert - case o.ln - when 1 - tuned_file << tag_close(o.ln,hs) - tuned_file << tag_open(o,@s) - if @md.opt.act[:verbose_plus][:set]==:on - puts_tag_close(o.ln,hs) - puts_tag_open(o,@s) - end - hs=[1,true,false,false] - when 2 - tuned_file << tag_close(o.ln,hs) - tuned_file << tag_open(o,@s) - if @md.opt.act[:verbose_plus][:set]==:on - puts_tag_close(o.ln,hs) - puts_tag_open(o,@s) - end - hs=[2,true,true,false] - when 3 - tuned_file << tag_close(o.ln,hs) - tuned_file << tag_open(o,@s) - if @md.opt.act[:verbose_plus][:set]==:on - puts_tag_close(o.ln,hs) - puts_tag_open(o,@s) - end - hs=[3,true,true,true] - when 4 - tuned_file << tag_close(o.ln,hs) - tuned_file << tag_open(o,@s) - if @md.opt.act[:verbose_plus][:set]==:on - puts_tag_close(o.ln,hs) - puts_tag_open(o,@s) - end - hs[0]=4 - when 5 - tuned_file << tag_close(o.ln,hs) - tuned_file << tag_open(o,@s) - if @md.opt.act[:verbose_plus][:set]==:on - puts_tag_close(o.ln,hs) - puts_tag_open(o,@s) - end - hs[0]=5 - when 6 - tuned_file << tag_close(o.ln,hs) - tuned_file << tag_open(o,@s) - if @md.opt.act[:verbose_plus][:set]==:on - puts_tag_close(o.ln,hs) - puts_tag_open(o,@s) - end - hs[0]=6 - end - end - tuned_file << o - end - if @md.opt.act[:verbose_plus][:set]==:on - puts_tag_close(0,hs) - end - tuned_file << tag_close(0,hs) - tuned_file=tuned_file.flatten - end - def tags(o) - tag=(o[:status]=='open') \ - ? %{<#{o[:lv]} id="#{o[:node]}">} - : "" - ln=case o[:lv] - when 'A'; 1 - when 'B'; 2 - when 'C'; 3 - when '1'; 4 - when '2'; 5 - when '3'; 6 - when '4'; 7 - when '5'; 8 - when '6'; 9 - end - h={ tag: tag, node: o[:node], lv: o[:lv], ln: ln, status: o[:status] } - SiSU_DAL_DocumentStructure::ObjectStructure.new.xml_dom(h) #downstream code utilise else ignore like comments - end - def tag_open(o,tag) - t={ lv: tag[o.ln], node: o.node, status: 'open' } - t_o=tags(t) - t_o - end - def tag_close(lev,hs) - ary=[] - case hs[0] - when 1 - if (lev <= 1) and hs[1] - t={ lv: @s[1], status: 'close' } - ary << tags(t) - end - if (lev==0) - t={ lv: @s[0], status: 'close' } - ary << tags(t) - end - when 2 - if (lev <= 2) and hs[2] - t={ lv: @s[2], status: 'close' } - ary << tags(t) - end - if (lev <= 1) and hs[1] - t={ lv: @s[1], status: 'close' } - ary << tags(t) - end - if (lev==0) - t={ lv: @s[0], status: 'close' } - ary << tags(t) - end - when 3 - if (lev <= 3) and hs[3] - t={ lv: @s[3], status: 'close' } - ary << tags(t) - end - if (lev <= 2) and hs[2] - t={ lv: @s[2], status: 'close' } - ary << tags(t) - end - if (lev <= 1) and hs[1] - t={ lv: @s[1], status: 'close' } - ary << tags(t) - end - if (lev==0) - t={ lv: @s[0], status: 'close' } - ary << tags(t) - end - when 4 - if (lev <= 4) - t={ lv: @s[4], status: 'close' } - ary << tags(t) - end - if (lev <= 3) and hs[3] - t={ lv: @s[3], status: 'close' } - ary << tags(t) - end - if (lev <= 2) and hs[2] - t={ lv: @s[2], status: 'close' } - ary << tags(t) - end - if (lev <= 1) and hs[1] - t={ lv: @s[1], status: 'close' } - ary << tags(t) - end - if (lev==0) - t={ lv: @s[0], status: 'close' } - ary << tags(t) - end - when 5 - if (lev <= 5) - t={ lv: @s[5], status: 'close' } - ary << tags(t) - end - if (lev <= 4) - t={ lv: @s[4], status: 'close' } - ary << tags(t) - end - if (lev <= 3) and hs[3] - t={ lv: @s[3], status: 'close' } - ary << tags(t) - end - if (lev <= 2) and hs[2] - t={ lv: @s[2], status: 'close' } - ary << tags(t) - end - if (lev <= 1) and hs[1] - t={ lv: @s[1], status: 'close' } - ary << tags(t) - end - if (lev==0) - t={ lv: @s[0], status: 'close' } - ary << tags(t) - end - when 6 - if (lev <= 6) - t={ lv: @s[6], status: 'close' } - ary << tags(t) - end - if (lev <= 5) - t={ lv: @s[5], status: 'close' } - ary << tags(t) - end - if (lev <= 4) - t={ lv: @s[4], status: 'close' } - ary << tags(t) - end - if (lev <= 3) and hs[3] - t={ lv: @s[3], status: 'close' } - ary << tags(t) - end - if (lev <= 2) and hs[2] - t={ lv: @s[2], status: 'close' } - ary << tags(t) - end - if (lev <= 1) and hs[1] - t={ lv: @s[1], status: 'close' } - ary << tags(t) - end - if (lev==0) - t={ lv: @s[0], status: 'close' } - ary << tags(t) - end - end - ary - end - def puts_tag_open(o,tag) - puts %{#{@sp*o.ln}<#{tag[o.ln]} id="#{o.node}">} - end - def puts_tag_close(lev,hs) - case hs[0] - when 1 - puts "#{@sp*1}" if (lev <= 1) and hs[1] - puts "" if (lev==0) - when 2 - puts "#{@sp*2}" if (lev <= 2) and hs[2] - puts "#{@sp*1}" if (lev <= 1) and hs[1] - puts "" if (lev==0) - when 3 - puts "#{@sp*3}" if (lev <= 3) and hs[3] - puts "#{@sp*2}" if (lev <= 2) and hs[2] - puts "#{@sp*1}" if (lev <= 1) and hs[1] - puts "" if (lev==0) - when 4 - puts "#{@sp*4}" if (lev <= 4) - puts "#{@sp*3}" if (lev <= 3) and hs[3] - puts "#{@sp*2}" if (lev <= 2) and hs[2] - puts "#{@sp*1}" if (lev <= 1) and hs[1] - puts "" if (lev==0) - when 5 - puts "#{@sp*5}" if (lev <= 5) - puts "#{@sp*4}" if (lev <= 4) - puts "#{@sp*3}" if (lev <= 3) and hs[3] - puts "#{@sp*2}" if (lev <= 2) and hs[2] - puts "#{@sp*1}" if (lev <= 1) and hs[1] - puts "" if (lev==0) - when 6 - puts "#{@sp*6}" if (lev <= 6) - puts "#{@sp*5}" if (lev <= 5) - puts "#{@sp*4}" if (lev <= 4) - puts "#{@sp*3}" if (lev <= 3) and hs[3] - puts "#{@sp*2}" if (lev <= 2) and hs[2] - puts "#{@sp*1}" if (lev <= 1) and hs[1] - puts "" if (lev==0) - end - end - end -end -__END__ diff --git a/lib/sisu/v5/dal_endnotes.rb b/lib/sisu/v5/dal_endnotes.rb deleted file mode 100644 index 839691da..00000000 --- a/lib/sisu/v5/dal_endnotes.rb +++ /dev/null @@ -1,128 +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: system environment, resource control and configuration details - -=end -module SiSU_DAL_Endnotes - class Endnotes - def initialize(md,data,endnote_array=nil) - @md,@data,@endnote_array=md,data,endnote_array - @endnote_counter,@endnote_counter_asterisk,@endnote_counter_dag=1,1,1 - end - def endnotes - data=@data - @tuned_file=[] - endnote_ref=1 - data.each do |dob| - # manually numbered endnotes --> - if @md.opt.mod.inspect =~/--no-asterisk|--no-annotate/ - dob.obj=dob.obj.gsub(/#{Mx[:en_b_o]}\s.+?#{Mx[:en_b_c]}/,'') - end - if @md.opt.mod.inspect =~/--no-dagger|--no-annotate/ - dob.obj=dob.obj.gsub(/#{Mx[:en_b_o]}[+]\s.+?#{Mx[:en_b_c]}/,'') - end - if (defined? dob.obj) \ - && (defined? dob.is) \ - && dob.is !=:code - case dob.obj # auto-numbered endnotes --> - when /#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}[*+]\s+.+?#{Mx[:en_b_c]}/ - dob.obj=dob.obj.gsub(/\s*(#{Mx[:en_a_c]}|#{Mx[:en_b_c]})/,'\1') - word_mode=dob.obj.scan(/\S+/m) - word_mode=endnote_call_number(word_mode) - dob.obj=word_mode.join(' ') - endnote_ref+=1 - when /~\^(?:\s|$)|<:e>/ #%note inserts endnotes previously gathered from /^(|[-~]\{{3})/ (in earlier loop) - word_mode=dob.obj.scan(/\S+/m) - word_mode=endnote_call_number(word_mode) - dob.obj=word_mode.join(' ') - endnote_ref+=1 - end - end - @tuned_file << dob - end - @endnote_counter,@endnote_counter_asterisk,@endnote_counter_dag=1,1,1 - @tuned_file=@tuned_file.flatten - end - def endnote_call_number(words) - words.each do |word| - case word - when /#{Mx[:en_a_o]}/ - unless word =~/#{Mx[:en_a_o]}[*+]+/ - word.gsub!(/#{Mx[:en_a_o]}/,"#{Mx[:en_a_o]}#{@endnote_counter} ") - @endnote_counter+=1 - end - when /#{Mx[:en_b_o]}/ - if word =~/#{Mx[:en_b_o]}[+]/ - word.gsub!(/#{Mx[:en_b_o]}[+]/,"#{Mx[:en_b_o]}\+#{@endnote_counter_dag} ") - @endnote_counter_dag+=1 - else - word.gsub!(/#{Mx[:en_b_o]}[*]?/,"#{Mx[:en_b_o]}\*#{@endnote_counter_asterisk} ") - @endnote_counter_asterisk+=1 - end - when /~\^|<:e>/ - if @endnote_array - word.gsub!(/~\^|<:e>/,"#{@endnote_array[@endnote_counter-1]}") - @endnote_counter+=1 - end - end - end - end - end -end -__END__ diff --git a/lib/sisu/v5/dal_expand_insertions.rb b/lib/sisu/v5/dal_expand_insertions.rb deleted file mode 100644 index e43dd3af..00000000 --- a/lib/sisu/v5/dal_expand_insertions.rb +++ /dev/null @@ -1,450 +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: system environment, resource control and configuration details - -=end -module SiSU_DAL_Insertions - class Insertions - def initialize(md,data) - @md,@data=md,data - end - def output_filetypes_in_cmd(cmd_shortcut,lnk=nil) #make list of file types in shortcut command (as configured), e.g. when sisu -3 is used - cf_defaults=SiSU_Env::InfoProcessingFlag.new - cmd_list=case cmd_shortcut.inspect - when /0/; cf_defaults.cf_0 - when /1/; cf_defaults.cf_1 - when /2/; cf_defaults.cf_2 - when /3/; cf_defaults.cf_3 - when /4/; cf_defaults.cf_4 - when /5/; cf_defaults.cf_5 - end - file_type_names={} - file_type_names[:gen],file_type_names[:src]=[],[] - file_type_names[:gen] <<= if cmd_list =~ /y/ then "~^ { document manifest }#{lnk[:manifest]}" - end - file_type_names[:gen] <<= if cmd_list =~ /h/ then [" { html, segmented text }#{lnk[:html_toc]}"," { html, scroll, document in one }#{lnk[:html_doc]}"] - end - file_type_names[:gen] <<= if cmd_list =~ /e/ then [" { epub }#{lnk[:epub]}"] - end - file_type_names[:gen] <<= if cmd_list =~ /p/ then [" { pdf, landscape }#{lnk[:pdf_landscape]}"," { pdf, portrait }#{lnk[:pdf_portrait]}"] - end - file_type_names[:gen] <<= if cmd_list =~ /o/ then " { odf:odt, open document text }#{lnk[:odt]}" - end - file_type_names[:gen] <<= if cmd_list =~ /b/ then " { xhtml scroll }#{lnk[:xhtml]}" - end - file_type_names[:gen] <<= if cmd_list =~ /x/ then " { xml, sax }#{lnk[:xml_sax]}" - end - file_type_names[:gen] <<= if cmd_list =~ /X/ then " { xml, dom }#{lnk[:xml_dom]}" - end - file_type_names[:gen] <<= if cmd_list =~ /a/ then " { plain text utf-8 }#{lnk[:txt]}" - end - file_type_names[:gen] <<= if cmd_list =~ /g/ then 'wiki.txt' - end - file_type_names[:gen] <<= if cmd_list =~ /w/ then " { concordance }#{lnk[:html_concordance]}" - end - file_type_names[:gen] <<= if cmd_list =~ /N/ then " { dcc, document content certificate (digests) }#{lnk[:digest]}" - end - file_type_names[:src] <<= if source and cmd_shortcut =~ /s/ then " { markup source text }#{lnk[:source]}" - end - file_type_names[:src] <<= if cmd_shortcut =~ /S/ then " { markup source (zipped) pod }#{lnk[:sisupod]}" - end - file_type_names[:gen]=file_type_names[:gen].flatten - file_type_names[:src]=file_type_names[:src].flatten - file_type_names - end - def by_language(linked_doc,lng,src=nil) - @linked_doc,@lng,@src=linked_doc,lng,src - @base_path="#{@md.file.output_path.base.url}/#{lng}" - def fnh - { - fn: @linked_doc, - } - end - def path_and_file(fn,pth) - "#{@base_path}/#{pth}/#{fn}" - end - def manifest - fn=@md.file.base_filename.manifest(fnh) - path_and_file(fn,'manifest') - end - def html_toc - fn=@md.file.base_filename.html_segtoc(fnh) - "#{@base_path}/html/#{@linked_doc}/#{fn}" - end - def html_doc - fn=@md.file.base_filename.html_scroll(fnh) - path_and_file(fn,'html') - end - def html_concordance - fn=@md.file.base_filename.html_concordance - "#{@base_path}/html/#{@linked_doc}/#{fn}" - end - def epub - fn=@md.file.base_filename.epub(fnh) - path_and_file(fn,'epub') - end - def pdf_landscape - fn=@md.file.base_filename.pdf_l_a4(fnh) - path_and_file(fn,'pdf') - end - def pdf_portrait - fn=@md.file.base_filename.pdf_p_a4(fnh) - path_and_file(fn,'pdf') - end - def odt - fn=@md.file.base_filename.odt(fnh) - path_and_file(fn,'odt') - end - def xhtml - fn=@md.file.base_filename.xhtml(fnh) - path_and_file(fn,'xhtml') - end - def xml_sax - fn=@md.file.base_filename.xml_sax(fnh) - path_and_file(fn,'xml_sax') - end - def xml_dom - fn=@md.file.base_filename.xml_dom(fnh) - path_and_file(fn,'xml_dom') - end - def txt - fn=@md.file.base_filename.txt(fnh) - path_and_file(fn,'txt') - end - def digest - fn=@md.file.base_filename.hash_digest(fnh) - path_and_file(fn,'digest') - end - def source - "#{@base_path}/src/#{@src}" - end - def sisupod - "#{@base_path}/src/#{@src}.zip" - end - self - end - def by_filetype(linked_doc,lng,src=nil) - @linked_doc,@lng,@src=linked_doc,lng,src - @lc=SiSU_Env::FilenameLanguageCodeInsert.new(@md.opt,lng).language_code_insert - @base_path="#{@md.file.output_path.base.url}" - def fnh - { - fn: @linked_doc, - lng: @lc, - } - end - def path_and_file(fn,pth) - "#{@base_path}/#{pth}/#{fn}" - end - def manifest - fn=@md.file.base_filename.manifest(fnh) - path_and_file(fn,'manifest') - end - def html_toc - fn=@md.file.base_filename.html_segtoc(fnh) - path_and_file(fn,'html') - end - def html_doc - fn=@md.file.base_filename.html_scroll(fnh) - path_and_file(fn,'html') - end - def html_concordance - fn=@md.file.base_filename.html_concordance - path_and_file(fn,'html') - end - def epub - fn=@md.file.base_filename.epub(fnh) - path_and_file(fn,'epub') - end - def pdf_landscape - fn=@md.file.base_filename.pdf_l_a4(fnh) - path_and_file(fn,'pdf') - end - def pdf_portrait - fn=@md.file.base_filename.pdf_p_a4(fnh) - path_and_file(fn,'pdf') - end - def odt - fn=@md.file.base_filename.odt(fnh) - path_and_file(fn,'odt') - end - def xhtml - fn=@md.file.base_filename.xhtml(fnh) - path_and_file(fn,'xhtml') - end - def xml_sax - fn=@md.file.base_filename.xml_sax(fnh) - path_and_file(fn,'xml_sax') - end - def xml_dom - fn=@md.file.base_filename.xml_dom(fnh) - path_and_file(fn,'xml_dom') - end - def txt - fn=@md.file.base_filename.txt(fnh) - path_and_file(fn,'txt') - end - def digest - fn=@md.file.base_filename.hash_digest(fnh) - path_and_file(fn,'digest') - end - def source - "#{@base_path}/src/#{@src}" - end - def sisupod - "#{@base_path}/src/#{@src}.zip" - end - self - end - def by_filename(linked_doc,lng,src=nil) - @linked_doc,@lng,@src=linked_doc,lng,src - @lc=SiSU_Env::FilenameLanguageCodeInsert.new(@md.opt,lng).language_code_insert - @base_path="#{@md.file.output_path.base.url}/#{@linked_doc}" - def fnh - { - fn: @linked_doc, - lng: @lc, - } - end - def path_and_file(fn,pth=nil) - (pth.nil?) \ - ? "#{@base_path}/#{fn}" - : "#{@base_path}/#{pth}/#{fn}" - end - def manifest - fn=@md.file.base_filename.manifest(fnh) - path_and_file(fn) - end - def html_toc - fn=@md.file.base_filename.html_segtoc(fnh) - path_and_file(fn) - end - def html_doc - fn=@md.file.base_filename.html_scroll(fnh) - path_and_file(fn) - end - def html_concordance - fn=@md.file.base_filename.html_concordance - path_and_file(fn) - end - def epub - fn=@md.file.base_filename.epub(fnh) - path_and_file(fn,'epub') - end - def pdf_landscape - fn=@md.file.base_filename.pdf_l_a4(fnh) - path_and_file(fn) - end - def pdf_portrait - fn=@md.file.base_filename.pdf_p_a4(fnh) - path_and_file(fn) - end - def odt - fn=@md.file.base_filename.odt(fnh) - path_and_file(fn) - end - def xhtml - fn=@md.file.base_filename.xhtml(fnh) - path_and_file(fn) - end - def xml_sax - fn=@md.file.base_filename.xml_sax(fnh) - path_and_file(fn) - end - def xml_dom - fn=@md.file.base_filename.xml_dom(fnh) - path_and_file(fn) - end - def txt - fn=@md.file.base_filename.txt(fnh) - path_and_file(fn) - end - def digest - fn=@md.file.base_filename.hash_digest(fnh) - path_and_file(fn) - end - def source - "#{@base_path}/#{@src}" - end - def sisupod - "#{@base_path}/#{@src}.zip" - end - self - end - def expand_insertions? - data=@data - tuned_file,tuned_file_tmp=[],[] - codeblock_=false - data.each do |para| - codeblock_=if para =~/^(?:code\{|[`]{3}\s+code)/ - true - elsif para =~/^(?:\}code|[`]{3}(?:\s|$))/m - false - else codeblock_ - end - if para !~/^%+\s/ \ - and not codeblock_ \ - and para =~/\{(?:~\^\s+)?(.+?)\s\[(?:\d(?:[sS]*))\]\}(?:\.\.\/\S+?\/|\S+?\.ss[tm]\b)/ - manifest=nil - @u=SiSU_Env::InfoEnv.new.url - m_cmd='' - if defined? @u.remote - if /(?.+?)\{(?.+?)\s\[(?\d[sS]*)\]\}(?(?\S+?)\.ss[tm]\b)(?.*)/m =~ para - m_pre=m_pre.strip - elsif /\{(?.+?)\s\[(?\d[sS]*)\]\}(?(?\S+?)\.ss[tm]\b)(?.*)/m =~ para - end - if m_linked_doc =~ /(\S+?)\/(\S+)/ - m_linked_doc,m_linked_doc_lang=$1,$2 - else - m_linked_doc,m_linked_doc_lang=m_linked_doc,@md.opt.lng_base - end - else - puts "error, does currently support relative paths (reltive paths were removed, as had problems for citation, and was not suited to all output types should possibly reconsider) #{__FILE__} #{__LINE__}" - if /\{(?:~\^\s+)?(?.+?)\s\[(?\d[sS]*)\]\}\.\.\/(?\S+?)\/(?\s+#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]})?/ =~ para - end - end - lnk=case @md.opt.dir_structure_by - when :language - { - manifest: by_language(m_linked_doc,m_linked_doc_lang).manifest, - html_toc: by_language(m_linked_doc,m_linked_doc_lang).html_toc, - html_doc: by_language(m_linked_doc,m_linked_doc_lang).html_doc, - epub: by_language(m_linked_doc,m_linked_doc_lang).epub, - pdf_landscape: by_language(m_linked_doc,m_linked_doc_lang).pdf_landscape, - pdf_portrait: by_language(m_linked_doc,m_linked_doc_lang).pdf_landscape, - odt: by_language(m_linked_doc,m_linked_doc_lang).odt, - xhtml: by_language(m_linked_doc,m_linked_doc_lang).xhtml, - xml_sax: by_language(m_linked_doc,m_linked_doc_lang).xml_sax, - xml_dom: by_language(m_linked_doc,m_linked_doc_lang).xml_dom, - txt: by_language(m_linked_doc,m_linked_doc_lang).txt, - html_concordance: by_language(m_linked_doc,m_linked_doc_lang).html_concordance, - digest: by_language(m_linked_doc,m_linked_doc_lang).digest, - sisupod: by_language(m_linked_doc,m_linked_doc_lang,m_source).sisupod, - source: by_language(m_linked_doc,m_linked_doc_lang,m_source).source, - } - when :filetype - { - manifest: by_filetype(m_linked_doc,m_linked_doc_lang).manifest, - html_toc: by_filetype(m_linked_doc,m_linked_doc_lang).html_toc, - html_doc: by_filetype(m_linked_doc,m_linked_doc_lang).html_doc, - epub: by_filetype(m_linked_doc,m_linked_doc_lang).epub, - pdf_landscape: by_filetype(m_linked_doc,m_linked_doc_lang).pdf_landscape, - pdf_portrait: by_filetype(m_linked_doc,m_linked_doc_lang).pdf_landscape, - odt: by_filetype(m_linked_doc,m_linked_doc_lang).odt, - xhtml: by_filetype(m_linked_doc,m_linked_doc_lang).xhtml, - xml_sax: by_filetype(m_linked_doc,m_linked_doc_lang).xml_sax, - xml_dom: by_filetype(m_linked_doc,m_linked_doc_lang).xml_dom, - txt: by_filetype(m_linked_doc,m_linked_doc_lang).txt, - html_concordance: by_filetype(m_linked_doc,m_linked_doc_lang).html_concordance, - digest: by_filetype(m_linked_doc,m_linked_doc_lang).digest, - sisupod: by_filetype(m_linked_doc,m_linked_doc_lang,m_source).sisupod, - source: by_filetype(m_linked_doc,m_linked_doc_lang,m_source).source, - } - else - { - manifest: by_filename(m_linked_doc,m_linked_doc_lang).manifest, - html_toc: by_filename(m_linked_doc,m_linked_doc_lang).html_toc, - html_doc: by_filename(m_linked_doc,m_linked_doc_lang).html_doc, - epub: by_filename(m_linked_doc,m_linked_doc_lang).epub, - pdf_landscape: by_filename(m_linked_doc,m_linked_doc_lang).pdf_landscape, - pdf_portrait: by_filename(m_linked_doc,m_linked_doc_lang).pdf_landscape, - odt: by_filename(m_linked_doc,m_linked_doc_lang).odt, - xhtml: by_filename(m_linked_doc,m_linked_doc_lang).xhtml, - xml_sax: by_filename(m_linked_doc,m_linked_doc_lang).xml_sax, - xml_dom: by_filename(m_linked_doc,m_linked_doc_lang).xml_dom, - txt: by_filename(m_linked_doc,m_linked_doc_lang).txt, - html_concordance: by_filename(m_linked_doc,m_linked_doc_lang).html_concordance, - digest: by_filename(m_linked_doc,m_linked_doc_lang).digest, - sisupod: by_filename(m_linked_doc,m_linked_doc_lang,m_source).sisupod, - source: by_filename(m_linked_doc,m_linked_doc_lang,m_source).source, - } - end - linked_title="#{m_pre}{#{m_txt} }#{lnk[:manifest]}#{m_note}\n\n" - tuned_file_tmp << linked_title - output_filetypes=output_filetypes_in_cmd(m_cmd,lnk) - output_filetypes[:gen].each do |o_f| - describe = o_f - if describe - tuned_file_tmp << if @u.remote #to double space <:br> at beginning of entry - "#{Mx[:nbsp]*4} #{describe} " - else # remove ... - "[provide document placement host location]" - end - end - end - output_filetypes[:src].each do |o_f| - describe = o_f - if describe - tuned_file_tmp << if @u.remote - "#{Mx[:nbsp]*4} #{describe} " - else - "[provide document placement host location]" - end - end - end - tuned_file << 'group{' << tuned_file_tmp.join("\n") << '}group' - tuned_file_tmp=[] - else tuned_file << para - end - end - tuned_file - end - end -end -__END__ diff --git a/lib/sisu/v5/dal_hash_digest.rb b/lib/sisu/v5/dal_hash_digest.rb deleted file mode 100644 index 9f620aa2..00000000 --- a/lib/sisu/v5/dal_hash_digest.rb +++ /dev/null @@ -1,157 +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: system environment, resource control and configuration details - -=end -module SiSU_DAL_Hash - require_relative 'shared_markup_alt.rb' #shared_markup_alt.rb - class ObjectDigest - def initialize(md,data,env=nil) - @md,@data,@env=md,data,env - @env ||=SiSU_Env::InfoEnv.new(@md.fns) - end - def object_digest - # 1. clean/stripped text without any markup, paragraph, headings etc. without endnotes - # 2. endnotes clean/stripped text digest only (there may be several endnotes within a paragraph) - # 3. whole object, text with markup and any endnotes, (question: with or without the endnote digests??? presumption better without, [however may be easier to check with?]) - # [digests should not include other digests] - data=@data.compact - @tuned_file=[] - sha_ =(@env.digest.type=='sha256' ? true : false) - sha_ ? (require 'digest/sha2') : (require 'digest/md5') - data.each do |t_o| - unless t_o.obj.is_a?(Array) - t_o.obj=t_o.obj.strip - end - if (t_o.of !=:structure \ - && t_o.of !=:comment \ - && t_o.of !=:layout) \ - && t_o.ocn.is_a?(Fixnum) - if sha_ - for hash_class in [ Digest::SHA256 ] - @tuned_file << stamped(t_o,hash_class) - end - else - for hash_class in [ Digest::MD5 ] - @tuned_file << stamped(t_o,hash_class) - end - end - else @tuned_file << t_o unless t_o.nil? - end - end - @tuned_file=@tuned_file.flatten - #use md5 or to create hash of each dal object including ocn, & add into to each dal object - end - def endnote_digest(data) - t_o_bit=[] - data.each do |en_plus| - t_o_bit <<= case en_plus - when /#{Mx[:en_a_o]}|#{Mx[:en_b_o]}/ - if en_plus =~/#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]}/ - t_o_txt,en_open,en_txt,en_close=/(.*?)(#{Mx[:en_a_o]}|#{Mx[:en_b_o]})(.+?)(#{Mx[:en_a_c]}|#{Mx[:en_b_c]})/m.match(en_plus)[1..4] - stripped_en=SiSU_TextRepresentation::Alter.new(en_txt).strip_clean_of_markup - digest_en_strip=if @env.digest.type =~/sha256/ - Digest::SHA256.hexdigest(stripped_en) - else - Digest::MD5.hexdigest(stripped_en) - end - t_o_txt + en_open + en_txt + Mx[:id_o] + digest_en_strip + Mx[:id_c] + en_close - else STDERR.puts "Error Exception - problem encountered with:\n#{en_plus}" #arbitrary exception, tidy up - end - else en_plus - end - end - t_o_bit.join - end - def stamped(t_o,hash_class) #decide what hash information is most useful, is compromise necessary? - t_o.obj=SiSU_TextRepresentation::Alter.new(t_o).strip_clean_of_extra_spaces - #SiSU_TextRepresentation::Alter.new(t_o).strip_clean_of_markup #check - #SiSU_TextRepresentation::Alter.new(t_o).semi_revert_markup #check - #SiSU_TextRepresentation::ModifiedTextPlusHashDigest.new(@md,t_o).composite.dgst #check - unless t_o.is==:code - case t_o.obj - when /#{Mx[:en_a_o]}[\d*+]+\s+.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}[*+]\d+\s+.+?#{Mx[:en_b_c]}/m - en_and_t_o_digest=[] - t_o.obj=t_o.obj.gsub(/\s*(#{Mx[:en_a_c]}|#{Mx[:en_b_c]})/m,' \1') #watch - t_o_plus_en=t_o.obj.scan(/.*?#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|.*?#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]}/m) - t_o_tail=if t_o.obj =~/(?:.*?#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|.*?#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]})+([\s\S]+)/m - /(?:.*?#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|.*?#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]})+.*/m.match(t_o.obj)[1] - else '' - end - t_o_plus_en << t_o_tail - en_and_t_o_digest << endnote_digest(t_o_plus_en) - en_and_t_o_digest.join(' ') - else #@tuned << t_o + Mx[:id_o] + digest_strip + ':' + digest_all + Mx[:id_c] unless t_o.nil? - end - else #@tuned << t_o + Mx[:id_o] + digest_strip + ':' + digest_all + Mx[:id_c] unless t_o.nil? - end - t_o #KEEP intact - end - def strip_clean_extra_spaces(s) # dal output tuned - s=s.dup - s=s.gsub(/[ ]+([,.;:?](?:$|\s))/,'\1') unless s =~/#{Mx[:en_a_o]}|#{Mx[:en_b_o]}/ - s=s.gsub(/ [ ]+/,' '). - gsub(/^ [ ]+/,''). - gsub(/ [ ]+$/,''). - gsub(/((?:#{Mx[:fa_bold_c]}|#{Mx[:fa_italics_c]})')[ ]+(s )/,'\1\2'). - gsub(/((?:#{Mx[:fa_bold_c]}|#{Mx[:fa_italics_c]})')[ ]+(s )/,'\1\2') - end - end -end -__END__ diff --git a/lib/sisu/v5/dal_idx.rb b/lib/sisu/v5/dal_idx.rb deleted file mode 100644 index be8a0211..00000000 --- a/lib/sisu/v5/dal_idx.rb +++ /dev/null @@ -1,326 +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: system environment, resource control and configuration details - -=end -module SiSU_DAL_BookIndex - class BookIndex - def initialize(md,data,env=nil) - @md,@data,@env=md,data,env - @rgx_idx=/#{Mx[:idx_o]}(?:.+?)#{Mx[:idx_c]}\s*/ - @rgx_idx_ocn_seg=/(.+?)~(\d+)~(\S+)/ - @rgx_idx_ocn=/(.+?)~(\d+)/ - @env ||=SiSU_Env::InfoEnv.new(@md.fns) - end - def indexing_song - data=@data - data,sisu_markup_idx_rel,sisu_markup_idx_rel_html_seg,html_idx,xhtml_idx=extract_book_index(data) - data=clean_and_insert_index(data,sisu_markup_idx_rel_html_seg) - [data,sisu_markup_idx_rel,sisu_markup_idx_rel_html_seg,html_idx,xhtml_idx] - end - def extract_book_index(data) - tuned_file=[] - idx_array=[] - data.each do |dob| - if (dob.is ==:heading \ - || dob.is ==:heading_insert) \ - && dob.ln==4 - @seg=dob.name - end - if defined? dob.idx \ - and dob.idx.is_a?(Hash) - idx_array << {idx: dob.idx, ocn: dob.ocn, seg: @seg } - end - tuned_file << dob if dob - end - if idx_array.length > 0 - the_idx=construct_book_index(idx_array) - sisu_markup_idx_rel,sisu_markup_idx_rel_html_seg,html_idx,xhtml_idx=nil,nil,nil,nil - if @md.book_idx - idx=index(the_idx) - sisu_markup_idx_rel,sisu_markup_idx_rel_html_seg,html_idx,xhtml_idx=idx[:sst_rel],idx[:sst_rel_html_seg],idx[:html],idx[:xhtml] - end - end - [tuned_file,sisu_markup_idx_rel,sisu_markup_idx_rel_html_seg,html_idx,xhtml_idx] - end - def construct_book_index(idx_array) - the_idx={} - idx_array.each do |idx| - idx[:idx].each_pair do |term,term_info| - location=(term_info[:plus].to_i > 0) \ - ? (%{#{idx[:ocn]}-#{idx[:ocn].to_i + term_info[:plus].to_i}}) - : idx[:ocn].to_s - the_idx[term]={} unless the_idx[term] and defined? the_idx[term] - the_idx[term]['node_0_terms']=[] unless the_idx[term]['node_0_terms'] and defined? the_idx[term]['node_0_terms'] - the_idx[term]['node_0_terms'] << { ocn: idx[:ocn], range: location, seg: idx[:seg] } - if term_info[:sub].is_a?(Array) \ - and term_info[:sub].length > 0 - term_info[:sub].each do |y| - y.each_pair do |subterm,subterm_info| - location=(subterm_info[:plus].to_i > 0) \ - ? (%{#{idx[:ocn]}-#{idx[:ocn].to_i + subterm_info[:plus].to_i}}) - : idx[:ocn].to_s - the_idx[term]={} unless the_idx[term] and defined? the_idx[term] - the_idx[term]['node_0_terms']=[] unless the_idx[term]['node_0_terms'] and defined? the_idx[term]['node_0_terms'] - the_idx[term]['node_1_subterms']={} unless the_idx[term]['node_1_subterms'] and defined? the_idx[term]['node_1_subterms'] - the_idx[term]['node_1_subterms'][subterm]=[] unless the_idx[term]['node_1_subterms'][subterm] and defined? the_idx[term]['node_1_subterms'][subterm] - the_idx[term]['node_1_subterms'][subterm] << { ocn: idx[:ocn], range: location, seg: idx[:seg] } - end - end - end - end - end - the_idx=the_idx.sort - the_idx - end - def clean_xml(str) - str=str.gsub(/&/,'&') - str - end - def index(the_idx) - @x=1 - idx={} - idx[:sst_rel_html_seg],idx[:sst_rel],idx[:html],idx[:xhtml]=[],[],[],[] - h={obj: Mx[:br_page]} - o=SiSU_DAL_DocumentStructure::ObjectLayout.new.break(h) - idx[:sst_rel_html_seg] << o - idx[:sst_rel] << o - h={lv: '2', name: 'index', obj: "Index"} - o=SiSU_DAL_DocumentStructure::ObjectHeading.new.heading(h) - idx[:sst_rel_html_seg] << o - idx[:sst_rel] << o - h={lv: '4', name: 'idx', obj: " [Index] #{Mx[:pa_non_object_dummy_heading]}"} - o=SiSU_DAL_DocumentStructure::ObjectHeading.new.heading(h) - idx[:sst_rel_html_seg] << o - idx[:sst_rel] << o - alph=%W[9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z] - idx[:html] << '

' - idx[:xhtml] << '

' - alph.each do |x| - if x =~/[0-9]/ - idx[:html] << '' - idx[:xhtml] << '' - else - idx[:html] << %{#{x},#{$ep[:hsp]}} - idx[:xhtml] << %{#{x},#{$ep[:hsp]}} - end - end - idx[:html] << '

' - idx[:xhtml] << '

' - letter=alph.shift - idx[:html] << %{\n

} - idx[:xhtml] << %{\n

0 - 9

} - the_idx.each do |i| - i.each do |x| - if x.is_a?(String) - f=/^(\S)/.match(x)[1] - if letter < f - while letter < f - if alph.length > 0 - letter=alph.shift - idx[:html] << %{\n

#{letter}

} - idx[:xhtml] << %{\n

#{letter}

} - else break - end - end - end - idx[:sst_rel_html_seg] << %{\n\n#{Mx[:fa_bold_o]}#{x},#{Mx[:fa_bold_c]} } - idx[:sst_rel] << %{\n\n#{Mx[:fa_bold_o]}#{x},#{Mx[:fa_bold_c]} } - aname=x.gsub(/\s+/,'_') - idx[:html] << %{\n

#{x}, } - c=clean_xml(x.dup) - idx[:xhtml] << %{\n

#{c}, } - @o=idx[:sst_rel_html_seg].index(idx[:sst_rel_html_seg].last) - @t=idx[:sst_rel].index(idx[:sst_rel].last) - @q=idx[:html].index(idx[:html].last) - @r=idx[:xhtml].index(idx[:xhtml].last) - print "\n" + x + ', ' if @md.opt.act[:verbose_plus][:set]==:on - elsif x.is_a?(Array) - p 'array error? -->' - print x - elsif x.is_a?(Hash) - if x['node_0_terms'].is_a?(Array) - x['node_0_terms'].each do |a| - if a[:range] - idx[:sst_rel_html_seg][@o]=idx[:sst_rel_html_seg][@o] + %{#{Mx[:lnk_o]}#{a[:range]}#{Mx[:lnk_c]}#{Mx[:rel_o]}/#{a[:seg]}.html##{a[:ocn]}#{Mx[:rel_c]}, } - idx[:sst_rel][@t]=idx[:sst_rel][@t] + %{#{Mx[:lnk_o]}#{a[:range]}#{Mx[:lnk_c]}#{Mx[:rel_o]}#{a[:ocn]}#{Mx[:rel_c]}, } - idx[:html][@q]=idx[:html][@q] + %{#{a[:range]}, } - idx[:xhtml][@q]=idx[:xhtml][@q] + %{#{a[:range]}, } - print a[:range] + ', ' if @md.opt.act[:verbose_plus][:set]==:on - elsif a[:ocn] - idx[:sst_rel_html_seg][@o]=idx[:sst_rel_html_seg][@o] + %{#{Mx[:lnk_o]}#{a[:ocn]}#{Mx[:lnk_c]}#{Mx[:rel_o]}#{a[:seg]}.html##{a[:ocn]}#{Mx[:rel_c]}, } - idx[:sst_rel][@t]=idx[:sst_rel][@t] + %{#{Mx[:lnk_o]}#{a[:ocn]}#{Mx[:lnk_c]}#{Mx[:rel_o]}#{a[:ocn]}#{Mx[:rel_c]}, } - idx[:html][@q]=idx[:html][@q] + %{#{a[:ocn]}, } - idx[:xhtml][@q]=idx[:xhtml][@q] + %{#{a[:ocn]}, } - print a[:ocn] + ', ' if @md.opt.act[:verbose_plus][:set]==:on - else p 'error' - end - end - idx[:html][@q]=idx[:html][@q] + '

' - idx[:xhtml][@r]=idx[:xhtml][@r] + '

' - end - if x['node_1_subterms'] - x['node_1_subterms'].sort.each do |k,y| - if k !~/node_0_terms/ - idx[:sst_rel_html_seg][@o]=idx[:sst_rel_html_seg][@o] + %{#{k}, } - idx[:sst_rel][@t]=idx[:sst_rel][@t] + %{#{k}, } - idx[:html][@q]=idx[:html][@q] + %{\n

#{k}, } - c=clean_xml(k.dup) - idx[:xhtml][@r]=idx[:xhtml][@r] + %{\n

#{c}, } - print "\n\t" + k + ', ' if @md.opt.act[:verbose_plus][:set]==:on - y.each do |z| - if z[:range] - idx[:sst_rel_html_seg][@o]=idx[:sst_rel_html_seg][@o] + %{#{Mx[:lnk_o]}#{z[:range]}#{Mx[:lnk_c]}#{Mx[:rel_o]}#{z[:seg]}.html##{z[:ocn]}#{Mx[:rel_c]}, } - idx[:sst_rel][@t]=idx[:sst_rel][@t] + %{#{Mx[:lnk_o]}#{z[:range]}#{Mx[:lnk_c]}#{Mx[:rel_o]}#{z[:ocn]}#{Mx[:rel_c]}, } - idx[:html][@q]=idx[:html][@q] + %{#{z[:range]}, } - idx[:xhtml][@q]=idx[:xhtml][@q] + %{#{z[:range]}, } - print z[:range] + ', ' if @md.opt.act[:verbose_plus][:set]==:on - elsif z[:ocn] - idx[:sst_rel_html_seg][@o]=idx[:sst_rel_html_seg][@o] + %{#{Mx[:lnk_o]}#{z[:ocn]}#{Mx[:lnk_c]}#{Mx[:rel_o]}#{z[:seg]}.html##{z[:ocn]}#{Mx[:rel_c]}, } - idx[:sst_rel][@t]=idx[:sst_rel][@t] + %{#{Mx[:lnk_o]}#{z[:ocn]}#{Mx[:lnk_c]}#{Mx[:rel_o]}#{z[:ocn]}#{Mx[:rel_c]}, } - idx[:html][@q]=idx[:html][@q] + %{#{z[:ocn]}, } - idx[:xhtml][@q]=idx[:xhtml][@q] + %{#{z[:ocn]}, } - print z[:ocn] + ', ' if @md.opt.act[:verbose_plus][:set]==:on - else p 'error' - end - end - idx[:html][@q]=idx[:html][@q] + '

' - idx[:xhtml][@r]=idx[:xhtml][@r] + '

' - end - end - end - @x +=1 - end - end - end - print "\n" if @md.opt.act[:verbose_plus][:set]==:on - idx - end - def screen_print(the_idx) - the_idx.each do |i| - i.each do |x| - if x.is_a?(String) - print "\n" + x + ', ' - elsif x.is_a?(Array) - p 'array error? -->' - print x - elsif x.is_a?(Hash) - if x['node_0_terms'].is_a?(Array) - x['node_0_terms'].each do |a| - if a[:range] - print a[:range] + ', ' - elsif a[:ocn] - print a[:ocn] + ', ' - else p 'error' - end - end - end - if x['node_1_subterms'] - x['node_1_subterms'].sort.each do |k,y| - if k !~/node_0_terms/ - print "\n\t" + k + ', ' - y.each do |z| - if z[:range] - print z[:range] + ', ' - elsif z[:ocn] - print z[:ocn] + ', ' - else p 'error' - end - end - end - end - end - end - end - end - end - def output_idx(idx) - if @md.book_idx - path="#{@env.path.output}/#{@md.fnb}" - Dir.mkdir(path) unless FileTest.directory?(path) - puts "#{path}/#{@md.fn[:book_idx_html]} #{__FILE__}::#{__LINE__}" - html_index_file=File.new("#{path}/#{@md.fn[:book_idx_html]}",'w') - idx[:html].each {|x| html_index_file << x } - html_index_file.close - end - end - def clean_and_insert_index(data,sisu_markup_idx) - tuned_file=[] - data.each do |dob| - tuned_file << dob - if dob.obj =~/#{Mx[:br_endnotes]}/ \ - and sisu_markup_idx - sisu_markup_idx.each do |idx| - tuned_file << idx - end - end - end - tuned_file - end - def clean_index(data) #check on use of dob - tuned_file=[] - data.each do |para| - para=para.gsub(/\n*#{@rgx_idx}/m,'') - tuned_file << para - end - tuned_file - end - end -end -__END__ diff --git a/lib/sisu/v5/dal_images.rb b/lib/sisu/v5/dal_images.rb deleted file mode 100644 index 33a5e627..00000000 --- a/lib/sisu/v5/dal_images.rb +++ /dev/null @@ -1,165 +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: system environment, resource control and configuration details - -=end -module SiSU_DAL_Images - class Images - #require 'RMagick' - #include Magick - def initialize(md,data) - @md,@data=md,data - end - def images - data=@data - tuned_file=[] - @rmgk=false - imagemagick_=true #imagemagick_=SiSU_Env::InfoSettings.new.program?('rmagick') - if imagemagick_ - begin - @rmgk=SiSU_Env::Load.new('RMagick').prog - rescue - @rmgk=false - end - else - if (@md.opt.act[:verbose][:set]==:on \ - || @md.opt.act[:verbose_plus][:set]==:on \ - || @md.opt.act[:maintenance][:set]==:on) - SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set],'*WARN* use of RMagick is not enabled in sisurc.yml').warn - end - end - data.each do |dob| - unless dob.is ==:table - dob.obj=dob.obj.strip - if dob.obj =~/#{Mx[:lnk_o]}\s*\S+\.(?:png|jpg|gif)(?:\s*|\s+.+)?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|image)/ - if dob.obj !~/#{Mx[:lnk_o]}\s*\S+\.(?:png|jpg|gif)\s+\d+x\d+/ - m=/#{Mx[:lnk_o]}\s*(\S+\.(?:png|jpg|gif))/ - if imagemagick_ - imgs=dob.obj.scan(m).flatten - img_col=img_row=nil - images=imgs.each do |image| - dir=SiSU_Env::InfoEnv.new(@md.fns) - path_image=[dir.path.image_source_include_local,dir.path.image_source_include_remote,dir.path.image_source_include] - image_path=nil - path_image.each do |img_pth| - image_path=img_pth - break if FileTest.exist?("#{img_pth}/#{image}") - end - if FileTest.exist?("#{image_path}/#{image}") - if @rmgk - img=Magick::ImageList.new("#{image_path}/#{image}") - img_col,img_row=img.columns,img.rows - else - if (@md.opt.act[:verbose][:set]==:on \ - || @md.opt.act[:verbose_plus][:set]==:on \ - || @md.opt.act[:maintenance][:set]==:on) - SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set],'*WARN* RMagick not present, will attempt to use imagemagick (identify) directly').warn - end - imgk=SiSU_Env::SystemCall.new.imagemagick - gmgk=SiSU_Env::SystemCall.new.graphicksmagick - if imgk or gmgk - if imgk - imgsys=`identify #{image_path}/#{image}`.strip #system call - elsif gmgk - imgsys=`gm identify #{image_path}/#{image}`.strip #system call - end - img_col,img_row=/(\d+)x(\d+)/m.match(imgsys)[1,2] - img_col,img_row=img_col.to_i,img_row.to_i - end - end - row=((img && defined? img.rows) ? img.rows : img_row) - col=((img && defined? img.columns) ? img.columns : img_col) - if img_col > img_row #landscape - if img_col> 640 - img_col=640 - img_row=((1.00*img_col/col)*row).round - end - else #portrait - if img_col> 640 - img_col=640 - img_row=((1.00*img_col/col)*row).round - end - if img_row > 640 - img_row=640 - img_col=((1.00*img_row/row)*col).round - end - end - dob.obj=dob.obj.gsub(/(#{image})/,"#{image} #{img_col}x#{img_row}") - else dob.obj=dob.obj.gsub(/#{Mx[:lnk_o]}\s*(\S+)\.(png|jpg|gif).+?#{Mx[:lnk_c]}(#{Mx[:url_o]}\S+?#{Mx[:url_c]}|image)/,'[ \1 (\2 missing) ]') - end - end - else - images=dob.obj.scan(m) do |image| - SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set],'*WARN* where image dimensions have not been provided RMagick or imagemagick is required',image).warn unless @md.opt.act[:quiet][:set]==:on - end - end - end - end - if dob.obj =~/#{Mx[:lnk_o]}\s*\S+\.(?:png|jpg|gif).+?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|image)/ - dob.obj=dob.obj.gsub(/(#{Mx[:lnk_o]})\s*(\S+\.(?:png|jpg|gif))\s+/i,'\1\2 ') - end - end - tuned_file << dob unless dob.nil? - end - tuned_file - end - end -end -__END__ -imgsys=`identify #{image_path}/#{image}`.strip diff --git a/lib/sisu/v5/dal_metadata.rb b/lib/sisu/v5/dal_metadata.rb deleted file mode 100644 index 1fa5619c..00000000 --- a/lib/sisu/v5/dal_metadata.rb +++ /dev/null @@ -1,82 +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: system environment, resource control and configuration details - -=end -module SiSU_DAL_Metadata - class Metadata - def initialize(md,metad) - @md,@metadata=md,metad - l=SiSU_Env::StandardiseLanguage.new(@md.opt.lng).language - language=l[:n] - @tr=SiSU_Translate::Source.new(md,language) - end - def make_para(obj,ocn) - h={ obj: obj, ocn: 0 } - SiSU_DAL_DocumentStructure::ObjectPara.new.paragraph(h) - end - def make_heading(obj,ocn,name,lv,ln) - h={ lv: lv, ln: ln, name: name, obj: obj, ocn: 0 } - SiSU_DAL_DocumentStructure::ObjectHeading.new.heading(h) - end - def metadata - end - end -end -__END__ diff --git a/lib/sisu/v5/dal_misc_arrange.rb b/lib/sisu/v5/dal_misc_arrange.rb deleted file mode 100644 index e6cc72db..00000000 --- a/lib/sisu/v5/dal_misc_arrange.rb +++ /dev/null @@ -1,157 +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: system environment, resource control and configuration details - -=end -module SiSU_DAL_MiscArrangeText - class SI - def initialize(md,data) - @md,@data=md,data - end - def conditional_headings(para) - para=para.gsub(/^(:?A~)\s*$/,'\1~ @title @author'). #conditional header - gsub(/^((?:[1-9]|:?[A-C])~\S*)\s*$/,'\1~ [Note: heading marker::required title missing]~#') #conditional header for incorporated document 2004w12 - if para =~/^@\S+?:/ - para=para.gsub(/^@(\S+?):(\s+|$)/,"#{Mx[:meta_o]}\\1#{Mx[:meta_c]}\\2"). - gsub(/^@(\S+?):([+-])(\s+|$)/,"#{Mx[:meta_o]}\\1\\2#{Mx[:meta_c]}\\3") - end - para - end - def code_blocks(para) - def ticks(para) - block_open,block_close,text=nil,nil,nil - if para =~/\A[`]{3}\s+.+?\n.+?\n[`]{3}(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*\Z/m - block_open,text,block_close=/\A([`]{3}\s+.+?)\n(.+?)\n([`]{3}(\s+[~-][#]|\s+\~\{.+?\}\~)?)\s*\Z/m.match(para)[1..3] - ((para=~/^[`]{3}\s+table(?:~h)?\s+/) \ - and (para !~/^[`]{3}\s+table(?:~h)?\s+c\d+/)) \ - ? para - : (para=[]; para << block_open << text << block_close) - elsif para =~/\A[`]{3}\s+.+?\n.*?\Z/m #look at, study - block_open,text=/\A([`]{3}(?:\s+.+?))\n(.*?)\Z/m.match(para)[1,2] - para=[] - if not text.to_s.empty? - para << block_open << text - else - para << block_open - end - elsif para =~/\A.+?\n[`]{3}(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*\Z/m - text,block_close=/\A(.+?)\n([`]{3}(?:\s+[~-][#]|\s+\~\{.+?\}\~)?)\s*\Z/m.match(para)[1,2] - para=[] - if not text.to_s.empty? - para << text.to_s << block_close - else - para << block_close - end - else para - end - para - end - def curly_braces(para) - block_open,block_close,text=nil,nil,nil - para=if para =~/\A(?:code|poem|alt|group|block|table)\{ .+?\n.+?\n\}(?:code|poem|alt|group|block|table)(?: [~-][#])?\s*\Z/m - block_open,text,block_close=/\A((?:code|poem|alt|group|block|table)\{ .+?)\n(.+?)\n(\}(?:code|poem|alt|group|block|table)(?: [~-][#])?)\s*\Z/m.match(para)[1..3] - para=[] - para << block_open << text << block_close - elsif para =~/\A(?:code|poem|alt|group|block|table)\{ .+?\n.+?\Z/m - block_open,text=/\A((?:code|poem|alt|group|block|table)\{ .+?)\n(.+?)\Z/m.match(para)[1,2] - para=[] - if not text.to_s.empty? - para << block_open << text - else - para << block_open - end - elsif para =~/\A.+?\n\}(?:code|poem|alt|group|block|table)(?: [~-][#])?\s*\Z/m - text,block_close=/\A(.+?)\n(\}(?:code|poem|alt|group|block|table)(?: [~-][#])?)\s*\Z/m.match(para)[1,2] - para=[] - if not text.to_s.empty? - para << text.to_s << block_close - else - para << block_close - end - else para - end - para - end - para=para =~/^```/m \ - ? ticks(para) - : para - para=(para =~/^(?:code|poem|alt|group|block|table)\{|^\}(?:code|poem|alt|group|block|table)/m) \ - ? curly_braces(para) - : para - end - def prepare_text - data=@data - data_new=[],[] - if data[0] =~ /^#!\s*(?:\/usr\/bin\/env sisu|\/usr\/bin\/sisu)/ # remove bang from top #! (however file is stripped, so will be removed provided no content precedes it) - data[0]=data[0].gsub(/^#!\s*\/usr\/bin\/sisu/,''). - gsub(/^#!\s*\/usr\/bin\/env sisu/,'') - end - if data[0] =~ /^(SiSU\s+[\d.]*|sisu-[\d.]+)$/ # SiSU identifier - data[0]=data[0].gsub(/^(SiSU\s*[\d.]*)$/,'% \1'). - gsub(/^(sisu-[\d.]+)$/,'% \1') - end - data.each do |para| - para=conditional_headings(para) - data_new << code_blocks(para) - end - data_new=data_new.flatten - end - end -end -__END__ diff --git a/lib/sisu/v5/dal_numbering.rb b/lib/sisu/v5/dal_numbering.rb deleted file mode 100644 index 96f4134b..00000000 --- a/lib/sisu/v5/dal_numbering.rb +++ /dev/null @@ -1,486 +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: system environment, resource control and configuration details - -=end -module SiSU_DAL_Numbering - class Numbering - attr_accessor :obj,:osp,:ocn,:lv,:name,:index,:comment - def initialize(md,data) - @md,@data=md,data - @obj=@type=@ocn=@lv=@name=@index=@comment=nil - end - def numbering_song - data=@data - data=number_plaintext_para(data) - data=auto_number_heading_ie_title(data.compact) #tr issue - data=ocn(data.compact) #watch - data=xml(data.compact) - data=minor_numbering(data.compact) - data,tags_map,ocn_html_seg_map=name_para_seg_filename(data) - data=set_heading_top(data) unless @md.set_heading_top - [data,tags_map,ocn_html_seg_map] - end - def number_plaintext_para(data) - @tuned_file=[] - data.each do |dob| - if (dob.of !=:block \ - && dob.of !=:comment \ - && dob.of !=:layout) \ - && dob.ocn_ #and dob.obj !~ /#{Mx[:gr_o]}Th|#{Mx[:tc_o]}#{Mx[:tc_p]}#{Mx[:tc_p]}/ #FIX - dob.obj=dob.obj.gsub(/(.+)\n/,'\1 ') #messy, but idea is that tables should retain breaks - end - unless dob.obj.is_a?(Array) - dob.obj=dob.obj.gsub(/^\s+/,''). - gsub(/\s$/,"\n") - end - @tuned_file << dob - end - @tuned_file=@tuned_file.flatten - end - def number_sub_heading(dob,num,title_no) - unless dob.obj =~/\d+\.|(?:chapter|article|section|clause)\s+\d+/i #name selection arbitrary, fix - dob.obj=case dob.name - when /-/; dob.obj.gsub(/^/,"#{title_no} ") - when /^#/; dob.obj.gsub(/^/,"#{title_no} ") - when /^[a-z_\.]+/; dob.obj.gsub(/^/,"#{title_no} ") - else - dob.name=title_no if dob.name=~/^$/ #where title contains title number - dob.obj.gsub(/^/,"#{title_no} ") if title_no =~/\d+/ #main, where title number is to be provided #watch changed placement - end - if @md.toc_lev_limit \ - and @md.toc_lev_limit < num - dob.obj=dob.obj.gsub(/^/,'!_ ') #bold line, watch - end - end - dob - end - def heading_tag_clean(heading_tag) - heading_tag=heading_tag.gsub(/[ ]+/,'_'). - gsub(/["']/,''). - gsub(/[\/]/,'-'). - gsub(/#{Mx[:fa_bold_o]}|#{Mx[:fa_bold_c]}/,''). - gsub(/#{Mx[:fa_italics_o]}|#{Mx[:fa_italics_c]}/,''). - gsub(/#{Mx[:fa_underscore_o]}|#{Mx[:fa_underscore_c]}/,''). - gsub(/#{Mx[:fa_cite_o]}|#{Mx[:fa_cite_c]}/,''). - gsub(/#{Mx[:fa_insert_o]}|#{Mx[:fa_insert_c]}/,''). - gsub(/#{Mx[:fa_strike_o]}|#{Mx[:fa_strike_c]}/,''). - gsub(/#{Mx[:fa_superscript_o]}|#{Mx[:fa_superscript_c]}/,''). - gsub(/#{Mx[:fa_subscript_o]}|#{Mx[:fa_subscript_c]}/,''). - gsub(/#{Mx[:fa_hilite_o]}|#{Mx[:fa_hilite_c]}/,''). - gsub(/#{Mx[:gl_bullet]}/,'') - end - def auto_number_heading_ie_title(data) #also does some segment naming - @tuned_file=[] - if defined? @md.make.num_top \ - and @md.make.num_top \ - and @md.make.num_top !~/^$/ - input||=@md.make.num_top - end - num_top=(input ? input.to_i : nil) - t_no1=t_no2=t_no3=0 - if num_top - no1=num_top; no2=(num_top + 1); no3=(num_top + 2) - end - chapter_number_counter=0 - data=data.compact - data.each do |dob| #@md.seg_names << [additions to segment names] - title_no=nil - dob=SiSU_DAL_DocumentStructureExtract::Structure.new(@md,dob).structure_markup #must happen earlier, node info etc. require - if dob.is ==:heading \ - && dob.autonum_ \ - and defined? @md.make.num_top \ - and @md.make.num_top !~/^$/ - if dob.lv=='1' \ - and dob.obj =~/^#\s|\s#(?:\s|$)/ - chapter_number_counter +=1 - dob.obj=dob.obj.gsub(/^#\s/,"#{chapter_number_counter} "). - gsub(/#([:,]?\s|[.]?$)/,"#{chapter_number_counter}\\1") - end - if dob.ln==no1 - @subnumber=1 - @subnumber=0 if dob.ln==no1 - end - if dob.ln.to_s =~/^[1-6]/ \ - and not dob.toc_ \ - and dob.obj !~/#{Mx[:fa_o]}(?:~#|-#)#{Mx[:fa_c]}/ # <-- fix - if dob.ln==no1 - t_no1+=1; t_no2=0; t_no3=0 - title_no="#{t_no1}" - if @md.seg_names.is_a?(Array) \ - and not @md.seg_names.include?(title_no) - if dob.ln==no1 - dob.name="#{title_no}" if not dob.name - dob.tags=[title_no,dob.tags].flatten if title_no !~/^\d+$/ #check whether will work across file types with stop signs - tag=dob.obj.gsub(/(Article|Clause|Section|Chapter)\s+/,"\\1_#{title_no}").downcase - tag=heading_tag_clean(tag) - dob.tags=[tag,dob.tags].flatten if tag !~/^\d+$/ #check whether will work across file types with stop signs - dob.obj=(dob.obj =~/(Article|Clause|Section)\s+/) \ - ? (dob.obj.gsub(/(Article|Clause|Section)\s+/,"\\1 #{title_no} ")) - : (dob.obj.gsub(/^/,"#{title_no}. ")) #fix stop later - end - if dob.ln !=no1 \ - and dob.obj =~/^[\d.]+\s/ #fix -> if the title starts with a numbering scheme, do not auto-number, review - dob.name ="#{title_no}" if not dob.name - dob.tags=[title_no,dob.tags].flatten if title_no !~/^\d+$/ #check whether will work across file types with stop signs - dob.obj=dob.obj.gsub(/^/,"#{title_no}. ") - end - @md.seg_names << title_no - end - if dob.ln!=no1 \ - and dob.name!~/^[a-z_\.]+$/ \ - and dob.obj !~/[A-Z]\.?\s/ #bug -> tmp fix, excludes A. B. C. lettering, but not roman numerals, is arbitrary, review required # not fixed, work on - dob.tags=[title_no,dob.tags].flatten if title_no !~/^\d+$/ #check whether will work across file types with stop signs - dob.obj=dob.obj.gsub(/^/i,"#{title_no}. ") - end - end - if dob.ln==no1 #watch because here you change dob.name - dob.tags=["h#{title_no}",dob.tags].flatten #check whether will work across file types with stop signs - end - if dob.ln==no2 #watch because here you change dob.name - t_no2+=1; t_no3=0 - title_no="#{t_no1}.#{t_no2}" - dob.tags=["h#{title_no}",dob.tags].flatten #check whether will work across file types with stop signs - dob=number_sub_heading(dob,no2,title_no) - end - if dob.ln==no3 #watch because here you change dob.name - t_no3+=1 - title_no="#{t_no1}.#{t_no2}.#{t_no3}" - dob.tags=["h#{title_no}",dob.tags].flatten #check whether will work across file types with stop signs - dob=number_sub_heading(dob,no3,title_no) - end - elsif dob.ln.to_s =~/^[1-6]/ \ - and dob.name =~ /^[\w-]+-/ # endnotes, watch2005# endnotes, watch2005 - dob.tags=[dob.name,dob.tags].flatten if dob.name !~/^\d+$/ #check whether will work across file types with stop signs - dob.name.gsub(/^([a-z_\.]+)-$/,'\1') - end - elsif dob.is ==:heading \ - and dob.autonum_ \ - and @md.markup =~/num_extract/ #AS DANGEROUS force enable with document, note already does this type of numbering for cisg, locate and coordinate logic, is currently misplaced in code, chengwei inspired 2004w23/4 - #here lies a bug, as is nil when run from -Dv --update, FIX - if (dob.name.nil? or dob.name.empty?) \ - and dob.ln.to_s =~/^[1-9]/ \ - and dob.obj =~ /^([\d\.]+)/ #risky (must be unique) consider output to 4~~\d instead of 4~\d - dob.name=$1 - dob.tags=[dob.name,dob.tags].flatten if dob.name !~/^\d+$/ #check whether will work across file types with stop signs - end - if @md.toc_lev_limit - end - elsif defined? dob.name \ - and dob.name - dob.tags=[dob.name,dob.tags].flatten if dob.name !~/^\d+$/ #check whether will work across file types with stop signs - end - dob.tags=dob.tags.uniq if defined? dob.tags - @tuned_file << dob - end - @tuned_file=@tuned_file.flatten - end - def ocn(data) #and auto segment numbering increment - @tuned_file=SiSU_DAL_DocumentStructureExtract::OCN.new(@md,data).ocn - @tuned_file - end - def xml(data) - @tuned_file=SiSU_DAL_DocumentStructureExtract::XML.new(@md,data).dom - @tuned_file - end - def minor_numbering(data) #and auto segment numbering increment - @tuned_file=[] - number_small,letter_small=0,0 - letter=%w( a b c d e f g h i j k l m n o p q r s t u v w x y z ) - data.each do |dob| - if dob.of ==:heading \ - || dob.of ==:heading_insert \ - || dob.of ==:para \ - || dob.of ==:block - if dob.is ==:heading \ - and dob.ln.to_s=~/^[1-9]/ #% sub-number system, (baby numbering) reset with any change of major number (more obviously should be placed in number titles, but that is conditionally executed, check and move later) - number_small,letter_small=0,0 - elsif dob.is ==:para - if dob.obj =~/^#[ 1]/ \ - and dob.obj !~/^#\s+(?:~#)?$/ - letter_small=0 - number_small=0 if dob.obj =~ /^#1/ - number_small+=1 - dob.obj=dob.obj.gsub(/^#[ 1]/,"#{number_small}. ") - end - if dob.obj =~/^_# / - dob.obj=dob.obj.gsub(/^_# /,"#{letter[letter_small]}. ") - dob.indent='1' - letter_small+=1 - end - end - end - @tuned_file << dob - end - @tuned_file=@tuned_file.flatten - end - def name_para_seg_filename(data) #segment naming, remaining - # paragraph name/numbering rules - # manual naming overrides, manual naming may be - # alpha-numeric characters mixed, - # numeric only (a number), if - # all segments have been named, - # the numbers used are over 1000 or - # it is not minded that auto-numbering uses a funny scheme for naming segments (not yet implemented) - # [for now a warning is printed for such documents on use of maintenance or very-verbose flag] - # auto-naming takes the form of giving numbers to segments - # the rules for which are as follows - # if the title/heading text starts with a numeric, then that is used (1 3.1 3rd etc.) - # otherwise the level 4 segment number from the embedded document structure info is used - # if there is none a sequential number is designated, preceded by an underscore - @tuned_file,@unique_auto_name=[],[] - tags={} - art_filename_auto=1 - @counter=1 - if not @md.seg_autoname_safe \ - and (@md.opt.act[:verbose_plus][:set]==:on \ - || @md.opt.act[:maintenance][:set]==:on) - puts 'manual segment names, numbers used as names, risk warning (segmented html)' - end - ocn_html_seg=[] - data.each do |dob| - if dob.is==:heading \ - && dob.ln \ - and dob.ln.to_s =~/^[456]/ - if dob.ln==4 \ - and not dob.name \ - and not @md.set_heading_seg - @md.set_heading_seg=true - end - if dob.name !~/^\S+/ \ - and dob.obj =~/^\s*(?:\S+\s+)?([\d.,:-]+)/m #heading starts with a recognised numeric or word followed by a recognised numerical construct, use that as name - possible_seg_name=$1 - possible_seg_name=possible_seg_name.gsub(/(?:[:,-]|\W)/,'.'). - gsub(/\.$/,'') - if @md.seg_names.is_a?(Array) \ - and not @md.seg_names.include?(possible_seg_name) - dob.name=possible_seg_name - dob.tags=[dob.name,dob.tags].flatten if dob.name !~/^\d+$/ - @md.seg_names << possible_seg_name - elsif (@md.opt.act[:verbose_plus][:set]==:on \ - or @md.opt.act[:maintenance][:set]==:on) - puts 'warn, there may be a conflicting numbering scheme' - end - end - if dob.ln==4 \ - and dob.name #extract segment name from embedded document structure info - if @md.seg_names.is_a?(Array) \ - and not @md.seg_names.include?(dob.name) - dob.tags=[dob.name,dob.tags].flatten if dob.name !~/^\d+$/ - @md.seg_names << dob.name - end - end - if dob.ln==4 \ - and not dob.name #if still no segment name, provide a numerical one - pf='_' #pg='' #may use e.g. '' or '~' or '_' - segn_auto="#{pf}#{art_filename_auto.to_s}" - if @md.seg_names.is_a?(Array) \ - and not @md.seg_names.include?(segn_auto) - dob.name=segn_auto - dob.tags=[dob.name,dob.tags].flatten if dob.name !~/^\d+$/ #check whether will work across file types with stop signs - @md.seg_names << segn_auto - else puts 'segment name (numbering) error' - end - art_filename_auto+=1 - end - if dob.ln==4 \ - and not dob.name #should not occur - puts "e r r o r -\t#{__FILE__}::#{__LINE__}\n#{dob.inspect}" - end - end - if (dob.is ==:heading \ - || dob.is ==:heading_insert) \ - && dob.ln==4 - @seg=dob.name - end - @tuned_file << if dob.is==:heading \ - && (@md.pagenew || @md.pagebreak || @md.pageline) - m=dob.ln.to_s - dob_tmp=[] - if @md.pagenew.inspect =~/#{m}/ - dob_tmp << SiSU_DAL_DocumentStructure::ObjectLayout.new.break(Hx[:br_page_new]) << dob - elsif @md.pagebreak.inspect =~/#{m}/ - dob_tmp << SiSU_DAL_DocumentStructure::ObjectLayout.new.break(Hx[:br_page]) << dob - elsif @md.pageline.inspect =~/#{m}/ - dob_tmp << SiSU_DAL_DocumentStructure::ObjectLayout.new.break(Hx[:br_page_line]) << dob - end - unless dob_tmp.length > 0; dob - else dob_tmp - end - else dob - end - if defined? dob.ocn \ - and dob.ocn - @segname=((dob.is==:heading || dob.is==:heading_insert) && dob.ln==4 && (defined? dob.name)) \ - ? (dob.name) - : @segname - tags["#{dob.ocn}"]={ segname: @segname } - ocn_html_seg[dob.ocn]=if (dob.is==:heading || dob.is==:heading_insert) - if dob.ln =~/[1-3]/ - { seg: nil, level: dob.ln } - else #elsif dob.ln =~/[4-6]/ - { seg: @seg, level: dob.ln } - end - else - { seg: @seg, level: nil } - end - end - dob.tags=dob.tags.uniq if defined? dob.tags - if defined? dob.tags \ - and dob.tags.length > 0 - #@segname=((dob.is=='heading'|| dob.is=='heading_insert') && dob.ln==4 && (defined? dob.name)) \ - #? (dob.name) \ - #: @segname - dob.tags.each do |y| - tags[y]={ ocn: dob.ocn.to_s, segname: @segname } - end - end - dob - end - ocn_html_seg.each_with_index do |ocn,i| - if ocn \ - and ocn[:level].to_s=~/[1-3]/ - (1..4).each do |x| - if ocn_html_seg[i+x] and ocn_html_seg[i+x][:level]==4 - ocn[:seg]=ocn_html_seg[i+x][:seg] - end - end - end - end - if @md.seg_names.length > 0 - @md.set_heading_seg=true - end - tuned_file=@tuned_file.flatten - [tuned_file,tags,ocn_html_seg] - end - def set_heading_top(data) #% make sure no false positives - unless @md.set_heading_top - if (@md.opt.act[:verbose_plus][:set]==:on \ - or @md.opt.act[:maintenance][:set]==:on) - puts "\tdocument contains no top level heading, (will have to manufacture one)" - end - @tuned_file=[] - data.each do |t_o| - unless @md.set_heading_top - if t_o !~/^(?:#{Rx[:meta]}|@\S+:)\s/m \ - and t_o !~/\A\s*\Z/m - @md.set_heading_top=true - if defined? @md.title \ - and @md.title \ - and defined? @md.title.full \ - and defined? @md.creator \ - and @md.creator - head=@md.title.main ? ([@lv='1',@obj=@md.title.main]) : ([@lv='1',@obj='[no title provided]']) - @tuned_file << head - end - end - end - @tuned_file << t_o - end - @tuned_file=@tuned_file.flatten - end - end - def set_heading_seg(data) #% make sure no false positives - unless @md.set_heading_seg - if (@md.opt.act[:verbose_plus][:set]==:on \ - or @md.opt.act[:maintenance][:set]==:on) - puts "\tdocument contains no segment level, (will have to manufacture one)" - end - @tuned_file=[] - data.each do |dob| - unless @md.set_heading_seg - if defined? dob.ln and dob.ln.to_s !~/^[123]/m \ - and dob.obj !~/\A\s*\Z/m \ - and dob.is !=:layout - @md.set_heading_seg=true - head=@md.title.main \ - ? (dob.ln,dob.name,dob.obj=4,'seg',@md.title.main) - : (dob.ln,dob.name,dob.obj=4,'seg','[segment]') - @tuned_file << head - end - end - @tuned_file << dob - end - @tuned_file=@tuned_file.flatten - end - end - def set_header_title(data) #% make sure no false positives - unless @md.set_header_title - if (@md.opt.act[:verbose_plus][:set]==:on \ - or @md.opt.act[:maintenance][:set]==:on) - puts "\t no document title provided, (will have to manufacture one)" - end - @tuned_file=[] - data.each do |t_o| - unless @md.set_header_title - if t_o !~/^%{1,2}\s/m \ - and t_o !~/\A\s*\Z/m - @tuned_file << "#{Mx[:meta_o]}title#{Mx[:meta_c]} #{@md.heading_seg_first}" - @md.title.main=@md.heading_seg_first - @md.set_header_title=true - end - end - @tuned_file << t_o - end - @tuned_file=@tuned_file.flatten - end - end - end -end -__END__ diff --git a/lib/sisu/v5/dal_syntax.rb b/lib/sisu/v5/dal_syntax.rb deleted file mode 100644 index 1e1d8542..00000000 --- a/lib/sisu/v5/dal_syntax.rb +++ /dev/null @@ -1,631 +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: Syntax for markup, input markup syntaxes, determined here - -=end -module SiSU_DAL_Syntax - class Words - def initialize(line,md,mkp) - @line,@md,@mkp=line,md,mkp - end - end - class Markup - def initialize(md='',data='') - @md,@data=md,data - @vz=SiSU_Viz::Defaults.new - @data_new=[] - url_and_stub=SiSU_Env::InfoEnv.new.url - @output_url="#{url_and_stub.remote}" - @env=SiSU_Env::InfoEnv.new - emph_set=if defined? @md.emphasis_set_to \ - and not @md.emphasis_set_to.nil? - @md.emphasis_set_to - else @env.markup_emphasis - end - @emph=case emph_set - when /bold/ - emph_italics=false - { o: Mx[:fa_bold_o], c: Mx[:fa_bold_c] } - when /italics/ - emph_italics=true - { o: Mx[:fa_italics_o], c: Mx[:fa_italics_c] } - when /underscore/ - emph_italics=false - { o: Mx[:fa_underscore_o], c: Mx[:fa_underscore_c] } - else p __LINE__.to_s + '::' + __FILE__ - end - @http_m=%r{\{.+?\}https?://\S+|https?:\S+|:\S+|\.\.\/\S+|#\S+|\S+?\.png\b|[*]~\S+|^#{Mx[:meta_o]}.+|#{Mx[:gr_o]}(?:code|block|group|alt|verse)(?:-end)?#{Mx[:gr_c]}|#{Mx[:fa_o]}:br#{Mx[:fa_c]}} - @manmkp_ital=emph_italics \ - ? '[i/*]\\{.+?\\}[i/*]' - : '[i/]\\{.+?\\}[i/]' - tail_m_ital=%q{(?:\s|[.,;:?!'")]|~\^|~\\\{\s|$)} - tail_m_bold=%{(?:(?:#{Mx[:fa_italics_c]})?(?:\s|[.,;:?!'")]|~\^|~\\\{\s|$))?} - bold_line=%{^!_\s.+?(?:#{Mx[:br_line]}|\n|$)} - #ital_line=%{^/_\s.+?(?:#{Mx[:br_line]}|\n|$)} #not implemented - @line_scan_ital=if defined? @md.italics_match_list[:str] - /#{@http_m}|#{bold_line}|#{@manmkp_ital}#{tail_m_ital}|#{@md.italics_match_list[:str]}#{tail_m_ital}|\S+|\n/i - elsif defined? @vz.markup_make_italic[:str] - /#{@http_m}|#{bold_line}|#{@manmkp_ital}#{tail_m_ital}|#{@vz.markup_make_italic[:str]}#{tail_m_ital}|\S+|\n/i - end - @manmkp_bold=emph_italics \ - ? '^!_\s.+?(?:\n|$)|[!b]\\{.+?\\}[*!b]|[*!][a-zA-Z0-9\-_]+[!]' - : '^!_\s.+?(?:\n|$)|[*!b]\\{.+?\\}[*!b]|[*!][a-zA-Z0-9\-_]+[*!]' - @line_scan_bold=if (defined? @md.bold_match_list[:str] \ - and @md.bold_match_list[:str]) \ - and (defined? @vz.markup_make_bold[:str] \ - and @vz.markup_make_bold[:str]) - /#{@http_m}|#{bold_line}|(?:#{@manmkp_bold}|#{@md.bold_match_list[:str]}|#{@vz.markup_make_bold[:str]})#{tail_m_bold}|\S+|\n/i - elsif defined? @md.bold_match_list[:str] \ - and @md.bold_match_list[:str] - /#{@http_m}|#{bold_line}|(?:#{@manmkp_bold}|#{@md.bold_match_list[:str]})#{tail_m_bold}|\S+|\n/i - elsif defined? @vz.markup_make_bold[:str] \ - and @vz.markup_make_bold[:str] - /#{@http_m}|#{bold_line}|(?:#{@manmkp_bold}|#{@vz.markup_make_bold[:str]})#{tail_m_bold}|\S+|\n/i - end - end - def songsheet - @data=@data.compact - @data.each do |dob| - dob=breaks(dob) - dob=if @md.sem_tag then sem(dob) else dob end #revisit - dob=line_actions(dob) - dob=paragraph_set(dob) - dob=substitutions(dob) - dob=wordlist_italics(dob) - dob=wordlist_bold(dob) - dob=bodymarkup(dob) - @data_new << dob unless dob.nil? - end - @data_new - end - def sem(dob) #revisit - dob=SiSU_Sem::Tags.new(dob,@md).rm.all - end - def breaks(dob) - if dob.is !=:meta \ - && dob.is !=:comment \ - && dob.is !=:code \ - && dob.is !=:table - dob.obj=dob.obj.gsub(/^-\\\\-\s*$/,"#{Mx[:br_page]}"). - gsub(/^=\\\\=\s*$/,"#{Mx[:br_page_new]}"). - gsub(/ \\\\(?: |$)/,"#{Mx[:br_line]}"). - gsub(/(?:<:?pb>)/,"#{Mx[:br_page]}"). # depreciated - gsub(/(?:<:?pn>)/,"#{Mx[:br_page_new]}"). # depreciated - gsub(/(?:<:?br>|
)/,"#{Mx[:br_line]}"). # depreciated - gsub(/(?:^-\.\.-\s*$)/,"#{Mx[:br_page_line]}") - end - dob - end - def wordlist_italics(dob) - dob=dob.dup - if (defined? @md.italics_match_list[:str] \ - and @md.italics_match_list[:str]) \ - or (defined? @vz.markup_make_italic[:str] \ - and @vz.markup_make_italic[:str]) - dob.obj=if dob.is !=:meta \ - && dob.is !=:heading \ - && dob.is !=:heading_insert \ - && dob.is !=:code \ - && dob.is !=:comment - word=dob.obj.scan(@line_scan_ital) - word=word.flatten.compact - line_array=[] - word.each do |w| - unless /#{@manmkp_ital}|#{@http_m}/.match(w) - if defined? @md.italics_match_list[:regx] \ - and @md.italics_match_list[:regx] - w=w.gsub(@md.italics_match_list[:regx], - "#{Mx[:fa_italics_o]}\\1#{Mx[:fa_italics_c]}") - elsif defined? @vz.markup_make_italic \ - and @vz.markup_make_italic - w=w.gsub(@vz.markup_make_italic, - "#{Mx[:fa_italics_o]}\\1#{Mx[:fa_italics_c]}") - else w - end - end - line_array << w - end - line_array.join(' ') - else dob.obj - end - end - dob - end - def embolden(given) - given=given.gsub(/^!_\s+((?:\{|#{Mx[:lnk_o]})(?:~^ )?.+?(?:\}|#{Mx[:lnk_o]})https?:\/\/\S+.*?)([#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:br_nl]}])/, - "#{Mx[:fa_bold_o]} \\1 #{Mx[:fa_bold_c]}\\2"). - gsub(/^!_\s+((?:\{|#{Mx[:lnk_o]})(?:~^ )?.+?(?:\}|#{Mx[:lnk_o]})https?:\/\/\S+.*)/, - "#{Mx[:fa_bold_o]} \\1 #{Mx[:fa_bold_c]}"). - gsub(/(?:^!_|^#{Mx[:lv_o]}[7-9]:\S*?#{Mx[:lv_c]})\s*(.+?)([#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:br_nl]}])/, - "#{Mx[:fa_bold_o]}\\1#{Mx[:fa_bold_c]}\\2"). - gsub(/(?:^!_|^#{Mx[:lv_o]}[7-9]:\S*?#{Mx[:lv_c]})\s*(.+?)\s+((?:[*]~\S+\s*)+)/, - "#{Mx[:fa_bold_o]}\\1#{Mx[:fa_bold_c]}\\2"). - gsub(/(?:^!_|^#{Mx[:lv_o]}[7-9]:\S*?#{Mx[:lv_c]})\s*(.+?)\s*([~-]#)$/, - "#{Mx[:fa_bold_o]}\\1#{Mx[:fa_bold_c]}\\2"). - gsub(/(?:^!_\s+|^#{Mx[:lv_o]}[7-9]:\S*?#{Mx[:lv_c]}\s*)(.*)?\s*$/, - "#{Mx[:fa_bold_o]}\\1#{Mx[:fa_bold_c]}") - end - def italicise(given) - given=given.gsub(/^\/_\s*(.+?)([#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:br_nl]}])/, - "#{Mx[:fa_italics_o]}\\1#{Mx[:fa_italics_c]}\\2"). - gsub(/^\/_\s*(.+?)\s+((?:[*]~\S+\s*)+)/, - "#{Mx[:fa_italics_o]}\\1#{Mx[:fa_italics_c]}\\2"). - gsub(/^\/_\s*(.+?)\s*([~-]#)$/, - "#{Mx[:fa_italics_o]}\\1#{Mx[:fa_italics_c]}\\2"). - gsub(/^\/_\s+(.*)?\s*$/, - "#{Mx[:fa_italics_o]}\\1#{Mx[:fa_italics_c]}") - end - def line_actions(dob) - dob.obj=if (dob.is !=:heading \ - && dob.is !=:heading_insert \ - && dob.is !=:comment \ - && dob.is !=:meta) \ - and dob.obj =~ /^!_\s+/ - embolden(dob.obj) - elsif dob.obj =~ /^\/_\s+/ - italicise(dob.obj) - else dob.obj - end - dob - end - def paragraph_set(dob) - dob.obj=if dob.is !=:meta \ - && dob.is !=:heading \ - && dob.is !=:heading_insert \ - && dob.is !=:code \ - && dob.is !=:comment \ - && dob.is !=:table - dob.obj.gsub(/\n/m,' '). - gsub(/ \s+/m,' ') - else dob.obj - end - dob - end - def substitutions(dob) - dob=dob.dup - dob=if defined? @md.substitution_match_list[:match_and_replace] \ - and @md.substitution_match_list[:match_and_replace].is_a?(Array) - dob=if dob.is !=:meta \ - && dob.is !=:heading_insert \ - && dob.is !=:code \ - && dob.is !=:comment \ - && dob.is !=:table - if dob.obj =~/#{@md.substitution_match_list[:matches]}/ - @md.substitution_match_list[:match_and_replace].each do |x| - dob.obj=if x[:case_s]==:i - dob.obj.gsub(/#{x[:match]}/mi,x[:replace]) - else - dob.obj.gsub(/#{x[:match]}/m,x[:replace]) - end - end - end - dob - else dob - end - dob - else dob - end - end - def wordlist_bold(dob) - dob=dob.dup - if (defined? @md.bold_match_list[:str] \ - and @md.bold_match_list[:str]) \ - or (defined? @vz.markup_make_bold[:str] \ - and @vz.markup_make_bold[:str]) - dob.obj=if dob.is !=:meta \ - && dob.is !=:heading \ - && dob.is !=:heading_insert \ - && dob.is !=:code \ - && dob.is !=:comment \ - && dob.is !=:table - line_array=[] - word=dob.obj.scan(@line_scan_bold) - word=word.flatten.compact - word.each do |w| - unless /#{@manmkp_bold}|#{@http_m}/.match(w) - if defined? @md.bold_match_list[:regx] \ - and @md.bold_match_list[:regx] #document header: @bold: [bold word list] - w=w.gsub(@md.bold_match_list[:regx],"#{Mx[:fa_bold_o]}\\1#{Mx[:fa_bold_c]}") - elsif defined? @vz.markup_make_bold \ - and @vz.markup_make_bold #defaults adjusted bold word list - w=w.gsub(@vz.markup_make_bold,"#{Mx[:fa_bold_o]}\\1#{Mx[:fa_bold_c]}") - end - else - w=if w =~ /(?:^!_|^#{Mx[:lv_o]}[7-9]:\S*?#{Mx[:lv_c]})\s+/ - embolden(w) #bold paragraph/emphasize #may wish to remove think about 7{ 8{ conversion not satisfactory, as information is lost! - elsif w =~/^\/_\s+/ - italicise(w) - else w - end - end - line_array << w - end - line_array.join(' ') - else dob.obj - end - else - dob.obj=if dob.is==:heading \ - and dob.ln.to_s =~/[7-9]/ - embolden(dob.obj) - else dob.obj - end - end - dob - end - def fontface_lines(dob,leader) - while (dob.obj =~/#{Mx[:br_nl]}/ \ - and dob.obj =~/(?:#{leader})([*!\/_#])\{(.+?)\}\1/m) \ - and $2 =~/#{Mx[:br_nl]}/ - dob=if dob.obj =~/#{Mx[:br_nl]}/ \ - and dob.obj =~/(#{leader})([*!\/_#])\{(.+?)\}\2/m - lead,fce,txt=$1,$2,$3 - dob=if txt =~/#{Mx[:br_nl]}/ - lead_break=if dob.obj =~/^#{Mx[:br_nl]}/ - dob.obj=dob.obj.sub(/^#{Mx[:br_nl]}/,'') - Mx[:br_nl] - else '' - end - txt="#{lead_break}#{fce}\{" + txt.split(Mx[:br_nl]).join("\}#{fce}#{Mx[:br_nl]}#{fce}\{") + "\}#{fce}" - dob.obj=dob.obj.sub(/(?:^|#{Mx[:gl_c]}|\s+|['"]|[#{Mx[:nbsp]}#{Mx[:fa_o_c]}#{Mx[:fa_c]}#{Mx[:lnk_o]}#{Mx[:br_nl]}#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:tc_c]}#{Mx[:tc_p]}]|[\(\[\{]|\>)([*!\/_#])\{.+?\}\1/m,"#{lead}#{txt}") - dob - else dob - end - end - dob - end - dob - end - def fontface(dob) - leader=/^|#{Mx[:gl_c]}|\s+|['"]|[#{Mx[:nbsp]}#{Mx[:fa_o_c]}#{Mx[:fa_c]}#{Mx[:lnk_o]}#{Mx[:br_nl]}#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:tc_c]}#{Mx[:tc_p]}]|[\(\[\{]|[、。]|\>/ - dob=fontface_lines(dob,leader) - dob.obj=dob.obj.gsub(/(#{leader})\*\{(.+?)\}\*/m, - "\\1#{@emph[:o]}\\2#{@emph[:c]}"). #emphasis - gsub(/(#{leader})!\{(.+?)\}!/m, - "\\1#{Mx[:fa_bold_o]}\\2#{Mx[:fa_bold_c]}"). #bold - gsub(/(#{leader})\/\{(.+?)\}\//m, - "\\1#{Mx[:fa_italics_o]}\\2#{Mx[:fa_italics_c]}"). #italics - gsub(/(#{leader})_\{(.+?)\}_/m, - "\\1#{Mx[:fa_underscore_o]}\\2#{Mx[:fa_underscore_c]}"). #underscore - gsub(/(#{leader})#\{(.+?)\}#/m, - "\\1#{Mx[:fa_monospace_o]}\\2#{Mx[:fa_monospace_c]}"). #monospace - gsub(/(^|#{Mx[:gl_c]}|\s+|['"]|[#{Mx[:nbsp]}#{Mx[:fa_o_c]}#{Mx[:fa_c]}]|\(|\>)\"\{(.+?)\}\"/m, - "\\1#{Mx[:fa_cite_o]}\\2#{Mx[:fa_c_o]}cite#{Mx[:fa_c]}"). #cite /blockquote? - gsub(/(^|[^\\])\^\{(.+?)\}\^/m, - "\\1#{Mx[:fa_superscript_o]}\\2#{Mx[:fa_superscript_c]}"). #superscript - gsub(/(^|[^\\]),\{(.+?)\},/m, - "\\1#{Mx[:fa_subscript_o]}\\2#{Mx[:fa_subscript_c]}"). #subscript - gsub(/(^|#{Mx[:gl_c]}|\s+|['"]|#{Mx[:nbsp]}|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)\+\{(.+?)\}\+/m, - "\\1#{Mx[:fa_insert_o]}\\2#{Mx[:fa_insert_c]}"). #inserted text - gsub(/(^|#{Mx[:gl_c]}|\s+|['"]|#{Mx[:nbsp]}|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)-\{(.+?)\}-/m, - "\\1#{Mx[:fa_strike_o]}\\2#{Mx[:fa_strike_c]}"). #strikethrough - deleted text - gsub(/(^|#{Mx[:gl_c]}|\s+|['"]|#{Mx[:nbsp]}|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>|\d+)\^(\S+?)\^/, - "\\1#{Mx[:fa_superscript_o]}\\2#{Mx[:fa_superscript_c]}") #superscript single word, watch digit added - dob - end - def bodymarkup(dob) - # << http://www.jus.uio.no/sisu/sisu_markup_table/markup >> - # See: data/sisu/sample/document_samples_sisu_markup/ - ## fontface - # *{emphasis}* e{emphasis}e emphasis - # !{bold text}! b{bold}b bold text - # _{underline}_ u{underline}u underline - # /{italics}/ i{italics}i italics - # "{citation}" c{citation}c citation #blockquote? - # ^{superscript}^ superscript - # ,{subscript}, subscript - # +{inserted text}+ inserted text - # -{deleted text}- deleted text - # #{monospace text}# - # - # {url address}:url - # {image.png}imageurl - # {image.png}png - # ~{endnote}~ - # !_ #bold/emphasise paragraph - # _" #blockquote paragraph - # _1 <:i1> #indent paragraph 1 step - # _2 <:i2> #indent paragraph 2 steps - # _3 <:i3> #indent paragraph 3 steps - # _4 <:i4> #indent paragraph 4 steps - # _* #bullet (list) ● - # _1* #bullet (list) indented - # _1* #bullet (list) indented - # # #numbered (list) level 1 - # _# #numbered (list) level 2 - dob=dob.dup - if dob.is !=:meta \ - && dob.is !=:comment \ - && dob.is !=:code \ - && dob.is !=:table - line_array=[] - word=dob.obj.scan(/\S+|\n/) #unless line =~/^(?:#{Mx[:meta_o]}|%+\s)/ #visit - if word - word.each do |w| # _ - / # | : ! ^ ~ - unless w =~/~\{|\}~|~\[|\]~|^\^~|~\^|\*~\S+|~#|\{t?~|\{table|https?:\/\/\S+/ # do something earlier about table!! - w=w.gsub(/\\?~/,"#{Mx[:gl_o]}#126#{Mx[:gl_c]}") #escaped special character - end - w=w.gsub(/^\<$/,"#{Mx[:gl_o]}#lt#{Mx[:gl_c]}").gsub(/^\>$/,"#{Mx[:gl_o]}#gt#{Mx[:gl_c]}") #escaped special character - line_array << w - end - dob.obj=line_array.join(' ') - dob.obj=dob.obj.strip - end - dob.obj=dob.obj.gsub(/^([*#-.]{1,12})$/,'\1 ~#'). #ocn off for these paragraph separators - gsub(/~\{(.+?)\}~/m,Mx[:en_a_o] + '\1' + Mx[:en_a_c]). - gsub(/~\[([^*+].+?)\]~/m,Mx[:en_b_o] + '* \1' + Mx[:en_b_c]). #default if markup does not specify - gsub(/~\[(.+?)\]~/m,Mx[:en_b_o] + '\1' + Mx[:en_b_c]) - if dob.is ==:heading \ - and dob.ln ==1 - dob.obj=dob.obj.gsub(/\s*@title\b/," #{@md.title.full}") - dob.obj=if defined? @md.creator.author \ - and @md.creator.author - dob.obj.gsub(/\s+(?:@creator|@author)/,",#{Mx[:br_line]}#{@md.creator.author}") - else dob.obj.gsub(/\s+(?:@creator|@author)/,'') - end - end - if defined? @md.title \ - and @md.title \ - and defined? @md.title.full \ - and defined? @md.creator \ - and @md.creator - if dob.is ==:heading - dob.obj=dob.obj.gsub(/^\s*@title\s*$/,@md.title.full) if dob.lv =~/1/ - dob.obj=if dob.lv =~/[23]/ \ - and defined? @md.creator.author \ - and @md.creator.author - dob.obj.gsub(/^\s*(?:(by\s+)?(?:@creator|@author))\s*$/,"\\1#{@md.creator.author}") - else dob.obj.gsub(/^\s*(?:(by\s+)?(?:@creator|@author))\s*$/,'\1') - end - end - end - dob.obj=dob.obj.gsub(/<(https?:\/\/\S+?)>/,'< \1 >'). #catch problem markup - gsub(/<:=(\S+?)>/,'{ c_\1.png 14x14 }image'). - gsub(//,'<:\1>'). #escaped special character - gsub(/ /,"#{Mx[:nbsp]}"). #escaped special character - gsub(/\\~/,"#{Mx[:gl_o]}#126#{Mx[:gl_c]}"). #escaped special character - gsub(/\\\{/,"#{Mx[:gl_o]}#123#{Mx[:gl_c]}"). #escaped special character - gsub(/\\\}/,"#{Mx[:gl_o]}#125#{Mx[:gl_c]}"). #escaped special character - gsub(/\\\<>/,"#{Mx[:gl_o]}#gt#{Mx[:gl_c]}#{Mx[:gl_o]}#gt#{Mx[:gl_c]}"). #escaped special character - gsub(/\\\/,"#{Mx[:gl_o]}#gt#{Mx[:gl_c]}"). #escaped special character - gsub(/\\\_/,"#{Mx[:gl_o]}#095#{Mx[:gl_c]}"). #escaped special character - gsub(/\\\-/,"#{Mx[:gl_o]}#045#{Mx[:gl_c]}"). #escaped special character - gsub(/\\\+/,"#{Mx[:gl_o]}#043#{Mx[:gl_c]}"). #escaped special character - gsub(/\\\//,"#{Mx[:gl_o]}#047#{Mx[:gl_c]}"). #escaped special character - gsub(/\\\#/,"#{Mx[:gl_o]}#035#{Mx[:gl_c]}"). #escaped special character - gsub(/\\\&/,"#{Mx[:gl_o]}#038#{Mx[:gl_c]}"). #& #escaped special character - gsub(/\\\|/,"#{Mx[:gl_o]}#124#{Mx[:gl_c]}"). #not really a sisu special character but made available as possibility - gsub(/\\\:/,"#{Mx[:gl_o]}#058#{Mx[:gl_c]}"). #not really a sisu special character but made available as possibility - gsub(/\\\!/,"#{Mx[:gl_o]}#033#{Mx[:gl_c]}"). #not really a sisu special character but made available as possibility - gsub(/\\\^/,"#{Mx[:gl_o]}#094#{Mx[:gl_c]}"). #not really a sisu special character but made available as possibility - gsub(/\\\,/,"#{Mx[:gl_o]}#044#{Mx[:gl_c]}"). #not really a sisu special character but made available as possibility - gsub(/\\\\/,"#{Mx[:gl_o]}#092#{Mx[:gl_c]}"). #escaped special character - gsub(/\\\*/,"#{Mx[:gl_o]}#042#{Mx[:gl_c]}"). #escaped special character - gsub(/\\\!/,"#{Mx[:gl_o]}#033#{Mx[:gl_c]}") #escaped special character - if dob.obj=~/(?:https?:|ftp:|\{([^{}]+?)\}(?:#|:|[.]{1,2}\/))\S+/m - if dob.obj=~/(?:^|[#{Mx[:gl_c]}#{Mx[:nbsp]} ])\{~\^ (?:.+?)\s*\}(?:(?:https?:|ftp:|:|[.]{1,2}\/)\S+?)\s*#{Mx[:en_a_o]}(.+?)#{Mx[:en_a_c]}/m - dob.obj=dob.obj.gsub(/(^|[#{Mx[:gl_c]}#{Mx[:nbsp]} ])\{~\^ ([^}]+?)\s*\}((?:https?:|ftp:|:|[.]{1,2}\/)\S+?)\s*#{Mx[:en_a_o]}(.+?)#{Mx[:en_a_c]}/m, - "\\1#{Mx[:lnk_o]}\\2#{Mx[:lnk_c]}\\3 #{Mx[:en_a_o]}\\3 \\4#{Mx[:en_a_c]}") # watch - end - if dob.obj=~/(?:^|[#{Mx[:gl_c]}#{Mx[:nbsp]} ])\{~\^ (?:.+?)\s*\}(?:(?:https?:|ftp:|:|[.]{1,2}\/)\S+?)([;,.]?)(?=\s|[#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:br_nl]}]|$)/m - dob.obj=dob.obj.gsub(/(^|[#{Mx[:gl_c]}#{Mx[:nbsp]} ])\{~\^ (.+?)\s*\}((?:https?:|ftp:|:|[.]{1,2}\/)\S+?)([;,.]?)(?=\s|[#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:br_nl]}]|$)/m, - "\\1#{Mx[:lnk_o]}\\2#{Mx[:lnk_c]}\\3\\4 #{Mx[:en_a_o]}\\3#{Mx[:en_a_c]} ") - end - dob.obj=dob.obj.gsub(/(^|[^#])\{\s*([^{}]+?)\s*\}((?:https?:|:|[.]{2}\/|#)\S+?)(?=\s|[#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:br_nl]}#{Mx[:en_a_o]}#{Mx[:en_b_o]}]|$)/, - "\\1#{Mx[:lnk_o]}\\2#{Mx[:lnk_c]}\\3"). #linked (text or image, however text cannot include modified face, e.g. bold, ital, underline) - gsub(/(^|[#{Mx[:gl_c]}#{Mx[:lnk_c]}#{Mx[:en_a_o]}#{Mx[:en_b_o]}(\s])((?:https?|ftp):\/\/\S+?\.[^>< ]+?)([,.;'"]?)(?=[\s#{Mx[:en_a_c]}#{Mx[:en_b_c]}#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:br_nl]}]|$)/m, - %{\\1#{Mx[:url_o]}\\2#{Mx[:url_c]}\\3}). - gsub(/#{Mx[:lnk_c]}#(\S+?[^>< ]+?)([()\[\]]*[,.;:!?'"]{0,2})(?=[\s#{Mx[:en_a_c]}#{Mx[:en_b_c]}#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:br_nl]}]|$)/m, - %{#{Mx[:lnk_c]}#{Mx[:rel_o]}\\1#{Mx[:rel_c]}\\2}). - gsub(/#{Mx[:lnk_c]}:(\S+?[^>< ]+?)([()\[\]]*[,.;:!?'"]{0,2})(?=[\s#{Mx[:en_a_c]}#{Mx[:en_b_c]}#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:br_nl]}]|$)/m, - %{#{Mx[:lnk_c]}#{Mx[:rel_o]}:\\1#{Mx[:rel_c]}\\2}). - gsub(/#{Mx[:lnk_c]}[.]{2}\/(\S+?[^>< ]+?)([()\[\]]*[,.;:!?'"]{0,2})(?=[\s#{Mx[:en_a_c]}#{Mx[:en_b_c]}#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:br_nl]}]|$)/m, - %{#{Mx[:lnk_c]}#{Mx[:rel_o]}:\\1#{Mx[:rel_c]}\\2}) - end - if dob.obj=~/_(?:https?|ftp):\S+/m # _http://url #CHECK - dob.obj=dob.obj.gsub(/(^|[#{Mx[:gl_c]}#{Mx[:lnk_c]}#{Mx[:en_a_o]}#{Mx[:en_b_o]}(\s])(_(?:https?|ftp):\/\/\S+?\.[^>< ]+?)([,.;'"]?)(?=[\s#{Mx[:en_a_c]}#{Mx[:en_b_c]}#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:br_nl]}]|$)/m, - %{\\1#{Mx[:url_o]}\\2#{Mx[:url_c]}\\3}) - end - dob=fontface(dob) - dob.obj=dob.obj.gsub(/<[:e]\s+(.+?)!?>/, - "#{Mx[:en_a_o]}\\1#{Mx[:en_a_c]}"). #not tested - gsub(/(^|#{Mx[:br_nl]})\s*_\*\s*/, - "\\1#{Mx[:gl_bullet]}"). #bullets, shortcut - gsub(/=\{(.+?)\}/, - "#{Mx[:idx_o]}\\1#{Mx[:idx_c]}"). - gsub(/^\s*_([1-9])\*\s*/, - "#{Mx[:pa_o]}:i\\1:\\1#{Mx[:pa_c]}#{Mx[:gl_bullet]}"). #bullets, shortcut - gsub(/^\s*_([1-9])\s+/, - "#{Mx[:pa_o]}:i\\1:\\1#{Mx[:pa_c]}"). #indent - gsub(/^\s*_([1-9])!\s+(.+?)\s*$/, - "#{Mx[:pa_o]}:i\\1:\\1#{Mx[:pa_c]}#{Mx[:fa_bold_o]}\\2#{Mx[:fa_bold_c]} "). #indent bold - gsub(/^\s*__([1-9])\s+/, - "#{Mx[:pa_o]}:i0:\\1#{Mx[:pa_c]}"). #hang - gsub(/^\s*__([1-9])!\s+(.+?)\s*$/, - "#{Mx[:pa_o]}:i0:\\1#{Mx[:pa_c]}#{Mx[:fa_bold_o]}\\2#{Mx[:fa_bold_c]} "). #hangdef - gsub(/^\s*_([0-9])_([0-9])\s+/, - "#{Mx[:pa_o]}:i\\1:\\2#{Mx[:pa_c]}"). #hang - gsub(/^\s*_([0-9])_([0-9])!\s+(.+?)\s*$/, - "#{Mx[:pa_o]}:i\\1:\\2#{Mx[:pa_c]}#{Mx[:fa_bold_o]}\\3#{Mx[:fa_bold_c]} "). #hangdef - gsub(/<:hi>/,"#{Mx[:fa_hilite_o]}"). #''). # bright yellow rgb(255,255,0) pale yellow rgb(255,255,200) - gsub(/<:\/hi>/,"#{Mx[:fa_hilite_c]}"). #''). - gsub(/(#{Mx[:gr_o]}verse#{Mx[:gr_c]}.+)/m,"\\1\n"). - gsub(/[ ]+($)/,'\1'). - gsub(/\{\s*(.+?)\s*\}(https?:\S+?)([;,.]?)(?=\s|[#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:br_nl]}#{Mx[:en_a_o]}#{Mx[:en_b_o]}]|$)/, - "#{Mx[:lnk_o]}\\1#{Mx[:lnk_c]}#{Mx[:url_o]}\\2#{Mx[:url_c]}\\3"). #any remaining linked text or image - gsub(/\{\s*(.+?)\s*\}(#{Mx[:url_o]}\S+?#{Mx[:url_c]})/, - "#{Mx[:lnk_o]}\\1#{Mx[:lnk_c]}\\2"). #any remaining linked text or image - gsub(/(^|\s)([a-zA-Z0-9._-]+\@\S+?\.[a-zA-Z0-9._-]+)/,"\\1#{Mx[:url_o]}\\2#{Mx[:url_c]}"). - gsub(/(^|[ ])\{\s*(.+?)\s*\}(\S+?)([;,.]?)(?=\s|[#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:br_nl]}#{Mx[:en_a_o]}#{Mx[:en_b_o]}]|$)/, - "\\1#{Mx[:lnk_o]}\\2#{Mx[:lnk_c]}\\3\\4"). #any remaining linked text or image - gsub(/\{\s*(.+?)\s*\}#([a-zA-Z0-9][a-zA-Z0-9_-]*)([;,.]?)(?=\s|[#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:br_nl]}#{Mx[:en_a_o]}#{Mx[:en_b_o]}]|$)/, - "#{Mx[:lnk_o]}\\1#{Mx[:lnk_c]}#{Mx[:rel_o]}\\2#{Mx[:rel_c]}\\3"). #any remaining linked text or image, check need - gsub(/\{\s*(.+?)\s*\}(#{Mx[:rel_o]}\S+?#{Mx[:rel_c]})/, - "#{Mx[:lnk_o]}\\1#{Mx[:lnk_c]}\\2"). #any remaining linked text or image, check need - gsub(/\{\s*(.+?)\s*\}(image)/, - "#{Mx[:lnk_o]}\\1#{Mx[:lnk_c]}\\2") #linked image - elsif dob.is==:table - dob=fontface(dob) - elsif dob.is ==:code - dob.obj=dob.obj.gsub(/#{Mx[:meta_o]}(\S+?)#{Mx[:meta_c]}\s*/,'@\1: '). - gsub(/(^|#{Mx[:gl_c]}|\s)<(br(?: \/)?)>([\s,.]|$)/,'\1<\2>\3') #convert

back, clumsy - if dob.number_ - codeline=[] - ln=1 - dob.obj.split(/#{Mx[:gr_o]}codeline#{Mx[:gr_c]}||\n/).each_with_index do |cl,i| - unless i == 0 - cl=cl.gsub(Mx[:br_nl],'') - w=3-ln.to_s.length - cl = "#{ln}#{Mx[:nbsp]*w}#{Mx[:vline]}#{cl}#{Mx[:br_nl]}" - ln +=1 - end - codeline << cl - end - codeline= codeline.join("") - dob.obj=codeline - else - dob.obj=dob.obj.gsub(/#{Mx[:gr_o]}codeline#{Mx[:gr_c]}/,"\n") - end - dob - else # @\S+?: - end - dob - end - def tech #script markup planned to be more strict for technical documents - # *{emphasis}* e{emphasis}e emphasis - # !{bold text}! b{bold}b bold text - # _{underline}_ u{underline}u underline - # /{italics}/ i{italics}i italics - # "{citation}" c{citation}c citation - # ^{superscript}^ superscript - # ,{subscript}, subscript - # +{inserted text}+ inserted text - # -{deleted text}- deleted text - # #{monospace text}# - # {url address}:url - # {image.png}imageurl - # {image.png}png - # ~{endnote}~ - # +1 - # +2 - puts 'tech' - @data.each do |line| - line=line.gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|[\(\[]|\>)e\{(.+?)\}e/, - "\\1#{@emph[:o]}\\2#{@emph[:c]}"). #emphasis - gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|[\(\[]|\>)b\{(.+?)\}b/, - "\\1#{Mx[:fa_bold_o]}\\2#{Mx[:fa_bold_c]}"). #bold - gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|[\(\[]|\>)u\{(.+?)\}u/, - "\\1#{Mx[:fa_underscore_o]}\\2#{Mx[:fa_underscore_c]}"). #underscore - gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|[\(\[]|\>)c\{(.+?)\}c/, - "\\1#{Mx[:fa_cite_o]}\\2#{Mx[:fa_c_o]}cite#{Mx[:fa_c]}"). #cite - gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|[\(\[]|\>)i\{(.+?)\}i/, - "\\1#{Mx[:fa_italics_o]}\\2#{Mx[:fa_italics_c]}"). #italics - gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|[\(\[]|\>)!\{(.+?)\}!/, - "\\1#{Mx[:fa_bold_o]}\\2#{Mx[:fa_bold_c]}"). #bold - gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|[\(\[]|\>)\*\{(.+?)\}\*/, - "\\1#{@emph[:o]}\\2#{@emph[:c]}"). #emphasis - gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|[\(\[]|\>)_\{(.+?)\}_/, - "\\1#{Mx[:fa_underscore_o]}\\2#{Mx[:fa_underscore_c]}"). #underscore - gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|[\(\[]|\(|\>)\/\{(.+?)\}\//, - "\\1#{Mx[:fa_italics_o]}\\2#{Mx[:fa_italics_c]}"). #italics - gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)\"\{(.+?)\}\"/, - "\\1#{Mx[:fa_cite_o]}\\2#{Mx[:fa_c_o]}cite#{Mx[:fa_c]}"). - gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)\^\{(.+?)\}\^/, - "\\1#{Mx[:fa_superscript_o]}\\2#{Mx[:fa_superscript_c]}"). - gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)9\{(.+?)\}9/, - "\\1#{Mx[:fa_superscript_o]}\\2#{Mx[:fa_superscript_c]}"). - gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>),\{(.+?)\},/, - "\\1#{Mx[:fa_subscript_o]}\\2#{Mx[:fa_subscript_c]}"). - gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)6\{(.+?)\}6/, - "\\1#{Mx[:fa_subscript_o]}\\2#{Mx[:fa_subscript_c]}"). - gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)\+\{(.+?)\}\+/, - "\\1#{Mx[:fa_insert_o]}\\2#{Mx[:fa_insert_c]}"). - gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)v\{(.+?)\}v/, - "\\1#{Mx[:fa_insert_o]}\\2#{Mx[:fa_insert_c]}"). - gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)-\{(.+?)\}-/, - "\\1#{Mx[:fa_strike_o]}\\2#{Mx[:fa_strike_c]}"). - gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)x\{(.+?)\}x/, - "\\1#{Mx[:fa_strike_o]}\\2#{Mx[:fa_strike_c]}"). - gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)\*(\S+?)\*/, - "\\1#{@emph[:o]}\\2#{@emph[:c]}"). #emphasise single word, watch - gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)\!(\S+?)\!/, - "\\1#{Mx[:fa_bold_o]}\\2#{Mx[:fa_bold_c]}"). #bold single word, watch - gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)\/([\(\)a-zA-Z0-9']+?)\/([ ,.;:'"~$]|[^a-zA-Z0-9])/, - "\\1#{Mx[:fa_italics_o]}\\2#{Mx[:fa_italics_c]}\\3"). #italics single word, watch - gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)_(\S+?)_/, - "\\1#{Mx[:fa_underscore_o]}\\2#{Mx[:fa_underscore_c]}"). #underscore single word, watch - gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)\^(\S+?)\^/, - "\\1#{Mx[:fa_superscript_o]}\\2#{Mx[:fa_superscript_c]}"). #check #superscript single word, watch digit added - gsub(/^\s*_\([1-9]\)\(\*\+\)\s*/, - "#{Mx[:pa_o]}:i\\1#{Mx[:pa_c]}#{Mx[:fa_o]}\\2#{Mx[:fa_c_o]}"). #bullets, shortcut - gsub(/^\s*_\([1-9]\)\s+/, - "#{Mx[:pa_o]}:i\\1#{Mx[:pa_c]}"). #watch - gsub(/^\s*__\([1-9]\)\s+/, - "#{Mx[:pa_o]}:h\\1#{Mx[:pa_c]}"). #watch - #line.gsub(/^\s*__\([1-9]\)!\s+/, - # "#{Mx[:pa_o]}:hd\\1#{Mx[:pa_c]}"). #watch - gsub(/#{Mx[:br_line]}\s*_[12]\s+/, - "#{Mx[:br_line]} ") #indent used in endnotes, not implemented, replace when ready with: line.gsub(/(?:
|
)\s*_([12])\s+/,'
<:i\1> ') - end - @data - end - end -end -__END__ diff --git a/lib/sisu/v5/db_import.rb b/lib/sisu/v5/db_import.rb index 6edb0f99..147f27df 100644 --- a/lib/sisu/v5/db_import.rb +++ b/lib/sisu/v5/db_import.rb @@ -121,8 +121,8 @@ module SiSU_DbImport @@dl ||=SiSU_Env::InfoEnv.new.digest.length end def marshal_load - require_relative 'dal' # dal.rb - @dal_array=SiSU_DAL::Source.new(@opt).get # dal file drawn here + require_relative 'ao' # ao.rb + @dal_array=SiSU_AO::Source.new(@opt).get # dal file drawn here if (@opt.act[:verbose][:set]==:on \ || @opt.act[:verbose_plus][:set]==:on \ || @opt.act[:maintenance][:set]==:on) diff --git a/lib/sisu/v5/git.rb b/lib/sisu/v5/git.rb index 92322b7c..447117ca 100644 --- a/lib/sisu/v5/git.rb +++ b/lib/sisu/v5/git.rb @@ -62,7 +62,7 @@ module SiSU_Git require_relative 'param' # param.rb require_relative 'sysenv' # sysenv.rb - require_relative 'dal' # dal.rb + require_relative 'ao' # ao.rb class Source def initialize(opt) @opt=opt @@ -93,7 +93,7 @@ module SiSU_Git video: git_path_fnb + '/' + Gt[:sisupod] + '/' + Gt[:video], conf: git_path_fnb + '/' + Gt[:sisupod] + '/' + Gt[:conf] } - SiSU_DAL::Source.new(@opt).read # -m + SiSU_AO::Source.new(@opt).read # -m end def create_file_structure_git make_dir_fnb @@ -192,7 +192,7 @@ module SiSU_Git if composite_src \ and not @opt.act[:dal][:set]==:on ##SiSU_Assemble::Composite.new(@opt).read - #SiSU_DAL::Source.new(@opt).read # -m + #SiSU_AO::Source.new(@opt).read # -m "#{@env.processing_path.composite_file}/#{@opt.fnb}.ssm.sst" elsif composite_src "#{@env.processing_path.composite_file}/#{@opt.fnb}.ssm.sst" diff --git a/lib/sisu/v5/html_format.rb b/lib/sisu/v5/html_format.rb index c087f1ec..3a20ef67 100644 --- a/lib/sisu/v5/html_format.rb +++ b/lib/sisu/v5/html_format.rb @@ -904,7 +904,7 @@ WOK @lnk_url =t_o[:lnk_url] || nil @lnk_txt =t_o[:lnk_txt] || nil @format =t_o[:format] || nil - elsif t_o.class.inspect =~/^(?:#<)?SiSU_DAL_DocumentStructure/ + elsif t_o.class.inspect =~/^(?:#<)?SiSU_AO_DocumentStructure/ @dob=t_o if defined? t_o.is @named=nametags_seg(@dob) @txt=((defined? t_o.obj) ? t_o.obj : nil) diff --git a/lib/sisu/v5/hub.rb b/lib/sisu/v5/hub.rb index c158f214..c6545c1d 100644 --- a/lib/sisu/v5/hub.rb +++ b/lib/sisu/v5/hub.rb @@ -286,8 +286,8 @@ module SiSU require_relative 'composite' # composite.rb #pre-processing SiSU_Assemble::Composite.new(@opt).read end - require_relative 'dal' # -m dal.rb - SiSU_DAL::Source.new(@opt).read + require_relative 'ao' # -m ao.rb + SiSU_AO::Source.new(@opt).read end end if @opt.act[:qrcode][:set]==:on #% --qrcode, -Q diff --git a/lib/sisu/v5/manpage.rb b/lib/sisu/v5/manpage.rb index 44180819..8f721fd2 100644 --- a/lib/sisu/v5/manpage.rb +++ b/lib/sisu/v5/manpage.rb @@ -61,7 +61,7 @@ =end module SiSU_Manpage - require_relative 'dal' # dal.rb + require_relative 'ao' # ao.rb require_relative 'sysenv' # sysenv.rb include SiSU_Env include SiSU_Param @@ -100,7 +100,7 @@ module SiSU_Manpage || @opt.act[:maintenance][:set]==:on) SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],@opt.fns,"#{@md.file.output_path.manpage.dir}/#{@md.file.base_filename.manpage}").flow end - @dal_array=SiSU_DAL::Source.new(@opt).get # dal file drawn here + @dal_array=SiSU_AO::Source.new(@opt).get # dal file drawn here SiSU_Manpage::Source::Scroll.new(@md,@dal_array).songsheet rescue SiSU_Errors::Rescued.new($!,$@,@opt.cmd,@opt.fns).location do diff --git a/lib/sisu/v5/odf.rb b/lib/sisu/v5/odf.rb index 3e83e1cf..b64c8ebe 100644 --- a/lib/sisu/v5/odf.rb +++ b/lib/sisu/v5/odf.rb @@ -62,7 +62,7 @@ module SiSU_ODF require_relative 'particulars' # particulars.rb include SiSU_Particulars - require_relative 'dal' # dal.rb + require_relative 'ao' # ao.rb require_relative 'sysenv' # sysenv.rb include SiSU_Env include SiSU_Viz diff --git a/lib/sisu/v5/particulars.rb b/lib/sisu/v5/particulars.rb index 000748ff..d06afc12 100644 --- a/lib/sisu/v5/particulars.rb +++ b/lib/sisu/v5/particulars.rb @@ -66,7 +66,7 @@ module SiSU_Particulars include SiSU_Env require_relative 'param' # param.rb include SiSU_Param - require_relative 'dal' # dal.rb + require_relative 'ao' # ao.rb class CombinedSingleton include Singleton def get_all(opt) @@ -152,7 +152,7 @@ module SiSU_Particulars attr_accessor :opt,:dal_array def set_dal(opt) begin - @dal_array=SiSU_DAL::Source.new(opt).get + @dal_array=SiSU_AO::Source.new(opt).get self rescue SiSU_Errors::Rescued.new($!,$@,opt.cmd,opt.fnl).location do @@ -162,7 +162,7 @@ module SiSU_Particulars end def set_sst_idx(opt) begin - @sst_idx=SiSU_DAL::Source.new(opt).get_idx_sst + @sst_idx=SiSU_AO::Source.new(opt).get_idx_sst self rescue SiSU_Errors::Rescued.new($!,$@,opt.cmd,opt.fnl).location do @@ -172,7 +172,7 @@ module SiSU_Particulars end def set_raw_idx(opt) begin - @raw_idx=SiSU_DAL::Source.new(opt).get_idx_raw + @raw_idx=SiSU_AO::Source.new(opt).get_idx_raw self rescue SiSU_Errors::Rescued.new($!,$@,opt.cmd,opt.fnl).location do @@ -182,7 +182,7 @@ module SiSU_Particulars end def set_html_idx(opt) begin - @html_idx=SiSU_DAL::Source.new(opt).get_idx_html + @html_idx=SiSU_AO::Source.new(opt).get_idx_html self rescue SiSU_Errors::Rescued.new($!,$@,opt.cmd,opt.fnl).location do @@ -192,7 +192,7 @@ module SiSU_Particulars end def set_xhtml_idx(opt) begin - @xhtml_idx=SiSU_DAL::Source.new(opt).get_idx_xhtml + @xhtml_idx=SiSU_AO::Source.new(opt).get_idx_xhtml self rescue SiSU_Errors::Rescued.new($!,$@,opt.cmd,opt.fnl).location do @@ -204,7 +204,7 @@ module SiSU_Particulars def set_nametags_map(opt) begin opt=@md ? @md : opt - @nametags_map=SiSU_DAL::Source.new(opt).get_map_nametags + @nametags_map=SiSU_AO::Source.new(opt).get_map_nametags self rescue if @md @@ -221,7 +221,7 @@ module SiSU_Particulars attr_accessor :ocn_htmlseg_map def set_ocn_htmlseg_map(opt) begin - @ocn_htmlseg_map=SiSU_DAL::Source.new(@md).get_map_ocn_htmlseg + @ocn_htmlseg_map=SiSU_AO::Source.new(@md).get_map_ocn_htmlseg self rescue SiSU_Errors::Rescued.new($!,$@,opt.cmd,opt.fnl).location do diff --git a/lib/sisu/v5/plaintext.rb b/lib/sisu/v5/plaintext.rb index 49c198e7..8585ad9d 100644 --- a/lib/sisu/v5/plaintext.rb +++ b/lib/sisu/v5/plaintext.rb @@ -61,7 +61,7 @@ =end module SiSU_Plaintext - require_relative 'dal' # dal.rb + require_relative 'ao' # ao.rb require_relative 'sysenv' # sysenv.rb include SiSU_Env require_relative 'plaintext_format' # plaintext_format.rb @@ -99,7 +99,7 @@ module SiSU_Plaintext SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],@opt.fns,"#{md.file.output_path.txt.dir}/#{md.file.base_filename.txt}").flow end end - dal_array=SiSU_DAL::Source.new(@opt).get # dal file drawn here + dal_array=SiSU_AO::Source.new(@opt).get # dal file drawn here wrap_width=if defined? md.make.plaintext_wrap \ and md.make.plaintext_wrap md.make.plaintext_wrap diff --git a/lib/sisu/v5/po4a.rb b/lib/sisu/v5/po4a.rb index 64f2c18d..43ff51e9 100644 --- a/lib/sisu/v5/po4a.rb +++ b/lib/sisu/v5/po4a.rb @@ -61,7 +61,7 @@ =end module SiSU_Po4a - require_relative 'dal' # dal.rb + require_relative 'ao' # ao.rb require_relative 'sysenv' # sysenv.rb include SiSU_Env require_relative 'composite' # composite.rb @@ -101,7 +101,7 @@ module SiSU_Po4a end md=SiSU_Param::Parameters.new(@opt).get src[:files].each do |fn| - SiSU_DAL::Source.new(@opt,fn).read # -m + SiSU_AO::Source.new(@opt,fn).read # -m env=SiSU_Env::InfoEnv.new(@opt.fns) m=/((.+?)(?:\~\w\w(?:_\w\w)?)?)\.((?:-|ssm\.)?sst|ssm|ssi)$/ #watch added match for sss @fnn,@fnb,@fnt=fn[m,1],fn[m,2],fn[m,3] @@ -126,7 +126,7 @@ module SiSU_Po4a if @opt.fns =~/\S+?~#{@lang_regx}\.ss[mti]/ \ or @opt.f_pth[:lng] !=@opt.lng_base opt_lang_trn_fn=fn - @dal_array_lang_translation=SiSU_DAL::Source.new(@opt,opt_lang_trn_fn).get # dal file drawn here + @dal_array_lang_translation=SiSU_AO::Source.new(@opt,opt_lang_trn_fn).get # dal file drawn here opt_lang_src_fn=if fn =~/\S+?~\S{2}(?:_\S{2})?\.ss[mti]/ fn.gsub(/(\S+?)~\S{2}(?:_\S{2})?(\.ss[mti])/,'\1\2') #check i else fn @@ -141,14 +141,14 @@ module SiSU_Po4a else nil end if FileTest.file?("#{srcdir}/#{opt_lang_src_fn}") - @dal_array_lang_src=SiSU_DAL::Source.new(@@opt_src,opt_lang_src_fn).get # dal file drawn here + @dal_array_lang_src=SiSU_AO::Source.new(@@opt_src,opt_lang_src_fn).get # dal file drawn here else puts "no identified source document" exit end Dir.chdir(transdir) if transdir else - @dal_array_lang_src=SiSU_DAL::Source.new(@opt,fn).get # dal file drawn here + @dal_array_lang_src=SiSU_AO::Source.new(@opt,fn).get # dal file drawn here @dal_array_lang_translation=nil end wrap_width=if defined? md.make.plaintext_wrap \ diff --git a/lib/sisu/v5/sst_do_inline_footnotes.rb b/lib/sisu/v5/sst_do_inline_footnotes.rb index 836d0d29..f03c1c34 100644 --- a/lib/sisu/v5/sst_do_inline_footnotes.rb +++ b/lib/sisu/v5/sst_do_inline_footnotes.rb @@ -67,8 +67,8 @@ module SiSU_ConvertFootnotes include SiSU_Env require_relative 'param' # param.rb include SiSU_Param - require_relative 'dal_syntax' # dal_syntax.rb - include SiSU_DAL_Syntax + require_relative 'ao_syntax' # ao_syntax.rb + include SiSU_AO_Syntax require_relative 'i18n' # i18n.rb class Instantiate < SiSU_Param::Parameters::Instructions @@flag={} #Beware!! diff --git a/lib/sisu/v5/sst_to_s_xml_sax.rb b/lib/sisu/v5/sst_to_s_xml_sax.rb index d6767595..a3fbde9f 100644 --- a/lib/sisu/v5/sst_to_s_xml_sax.rb +++ b/lib/sisu/v5/sst_to_s_xml_sax.rb @@ -68,7 +68,7 @@ module SiSU_SimpleXML_ModelSax include SiSU_Param require_relative 'sysenv' # sysenv.rb include SiSU_Env - require_relative 'dal_doc_str' # dal_doc_str.rb + require_relative 'ao_doc_str' # ao_doc_str.rb require_relative 'shared_xml' # shared_xml.rb include SiSU_XML_Munge require_relative 'shared_sem' # shared_sem.rb @@ -276,7 +276,7 @@ WOK (0..6).each { |x| @cont[x]=@level[x]=false } (4..6).each { |x| @xml_contents_close[x]='' } @data.each do |para| - data << SiSU_DAL_DocumentStructureExtract::Structure.new(@md,para).structure #takes on Mx marks + data << SiSU_AO_DocumentStructureExtract::Structure.new(@md,para).structure #takes on Mx marks end data.each do |para| if para !~/^\s*(?:%+ |<:code>)/ diff --git a/lib/sisu/v5/sysenv.rb b/lib/sisu/v5/sysenv.rb index d4079f8c..19031711 100644 --- a/lib/sisu/v5/sysenv.rb +++ b/lib/sisu/v5/sysenv.rb @@ -142,7 +142,7 @@ module SiSU_Env PROCESSING_PATH=:processing_path PROCESSING_DIR_TMP_ROOT=:processing_dir_tmp_root PROCESSING_PATH_TMP_BASE=:processing_path_tmp_base - PROCESSING_DAL=:processing_dal + PROCESSING_AO=:processing_dal PROCESSING_TUNE=:processing_tune PROCESSING_LATEX=:processing_latex PROCESSING_TEXINFO=:processing_texinfo @@ -186,7 +186,7 @@ module SiSU_Env PROCESSING_PATH => processing_pth, PROCESSING_DIR_TMP_ROOT => prcss_dir_tmp_root, PROCESSING_PATH_TMP_BASE => processing_pth, - PROCESSING_DAL => 'dal', + PROCESSING_AO => 'ao', PROCESSING_TUNE => 'tune', PROCESSING_LATEX => 'tex', PROCESSING_TEXINFO => 'texinfo', diff --git a/lib/sisu/v5/texpdf.rb b/lib/sisu/v5/texpdf.rb index 2dc3e860..df089d31 100644 --- a/lib/sisu/v5/texpdf.rb +++ b/lib/sisu/v5/texpdf.rb @@ -81,8 +81,8 @@ module SiSU_TeX require_relative 'sysenv' # sysenv.rb include SiSU_Env include SiSU_Viz - require_relative 'dal' # dal.rb - include SiSU_DAL + require_relative 'ao' # ao.rb + include SiSU_AO include SiSU_TeX def initialize(opt) @opt=opt @@ -126,7 +126,7 @@ module SiSU_TeX $flag=@md.opt.cmd #introduced to pass 0 for no object citation numbers... to texpdf_format directories #% needed needs to be reprogrammed !!! - dal_array=SiSU_DAL::Source.new(@opt).get # dal file drawn here + dal_array=SiSU_AO::Source.new(@opt).get # dal file drawn here SiSU_TeX::Source::LaTeXcreate.new(@particulars).songsheet dal_array='' pwd=Dir.pwd @@ -1042,7 +1042,7 @@ module SiSU_TeX file[:landscape].puts morph,"\n" end end - elsif morph.class.inspect =~ /SiSU_DAL_DocumentStructure/ \ + elsif morph.class.inspect =~ /SiSU_AO_DocumentStructure/ \ and morph.tmp \ and morph.tmp.is_a?(String) if morph.is !=:code \ diff --git a/lib/sisu/v5/wikispeak.rb b/lib/sisu/v5/wikispeak.rb index da8fc9fa..eab2336d 100644 --- a/lib/sisu/v5/wikispeak.rb +++ b/lib/sisu/v5/wikispeak.rb @@ -60,7 +60,7 @@ =end module SiSU_Wikispeak - require_relative 'dal' # dal.rb + require_relative 'ao' # ao.rb require_relative 'sysenv' # sysenv.rb include SiSU_Env include SiSU_Param @@ -90,7 +90,7 @@ module SiSU_Wikispeak || @opt.act[:maintenance][:set]==:on) SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],@opt.fns,"#{@env.path.output_tell}/#{@md.fnb}/#{@md.fn[:wiki]}").flow end - @dal_array=SiSU_DAL::Source.new(@opt).get # dal file drawn here + @dal_array=SiSU_AO::Source.new(@opt).get # dal file drawn here SiSU_Wikispeak::Source::Scroll.new(@dal_array,@md).songsheet rescue SiSU_Errors::Rescued.new($!,$@,@opt.cmd,@opt.fns).location do diff --git a/lib/sisu/v5/xml_dom.rb b/lib/sisu/v5/xml_dom.rb index f6d86883..36a0dae1 100644 --- a/lib/sisu/v5/xml_dom.rb +++ b/lib/sisu/v5/xml_dom.rb @@ -66,7 +66,7 @@ module SiSU_XML_DOM include SiSU_Particulars require_relative 'sysenv' # sysenv.rb include SiSU_Env - require_relative 'dal' # dal.rb + require_relative 'ao' # ao.rb require_relative 'shared_xml' # shared_xml.rb include SiSU_XML_Munge require_relative 'xml_format' # xml_format.rb diff --git a/lib/sisu/v5/xml_scaffold_structure_collapsed.rb b/lib/sisu/v5/xml_scaffold_structure_collapsed.rb index a90207ff..8f14ea54 100644 --- a/lib/sisu/v5/xml_scaffold_structure_collapsed.rb +++ b/lib/sisu/v5/xml_scaffold_structure_collapsed.rb @@ -62,7 +62,7 @@ module SiSU_XML_Scaffold_Structure_Collapse require_relative 'particulars' # particulars.rb include SiSU_Particulars - require_relative 'dal' # dal.rb + require_relative 'ao' # ao.rb require_relative 'sysenv' # sysenv.rb include SiSU_Env class Source diff --git a/lib/sisu/v5/xml_scaffold_structure_sisu.rb b/lib/sisu/v5/xml_scaffold_structure_sisu.rb index 64173566..12e1088a 100644 --- a/lib/sisu/v5/xml_scaffold_structure_sisu.rb +++ b/lib/sisu/v5/xml_scaffold_structure_sisu.rb @@ -62,7 +62,7 @@ module SiSU_XML_Scaffold_Structure_Sisu require_relative 'particulars' # particulars.rb include SiSU_Particulars - require_relative 'dal' # dal.rb + require_relative 'ao' # ao.rb require_relative 'sysenv' # sysenv.rb include SiSU_Env class Source -- cgit v1.2.3 From 3d4ec6deee066dec01b9445f9b54f844d9443aae Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Mon, 2 Dec 2013 23:59:06 -0500 Subject: v5: some renaming to ao from dal continued --- lib/sisu/v5/air.rb | 6 +- lib/sisu/v5/ao.rb | 158 ++++++++++++------------ lib/sisu/v5/ao_hash_digest.rb | 4 +- lib/sisu/v5/concordance.rb | 4 +- lib/sisu/v5/conf.rb | 12 +- lib/sisu/v5/db_import.rb | 14 +-- lib/sisu/v5/digests.rb | 32 ++--- lib/sisu/v5/epub.rb | 4 +- lib/sisu/v5/epub_concordance.rb | 4 +- lib/sisu/v5/git.rb | 2 +- lib/sisu/v5/html.rb | 4 +- lib/sisu/v5/hub.rb | 8 +- lib/sisu/v5/manpage.rb | 4 +- lib/sisu/v5/odf.rb | 6 +- lib/sisu/v5/options.rb | 18 ++- lib/sisu/v5/param.rb | 4 +- lib/sisu/v5/particulars.rb | 12 +- lib/sisu/v5/plaintext.rb | 4 +- lib/sisu/v5/po4a.rb | 10 +- lib/sisu/v5/prog_text_translation.rb | 4 +- lib/sisu/v5/relaxng.rb | 4 +- lib/sisu/v5/shared_sisupod_source.rb | 2 +- lib/sisu/v5/sisupod_make.rb | 2 +- lib/sisu/v5/sst_do_inline_footnotes.rb | 44 +++---- lib/sisu/v5/sst_to_s_xml_sax.rb | 4 +- lib/sisu/v5/sysenv.rb | 134 ++++++++++---------- lib/sisu/v5/texinfo.rb | 2 +- lib/sisu/v5/texpdf.rb | 6 +- lib/sisu/v5/texpdf_format.rb | 4 +- lib/sisu/v5/urls.rb | 4 +- lib/sisu/v5/wikispeak.rb | 4 +- lib/sisu/v5/xhtml.rb | 8 +- lib/sisu/v5/xml_dom.rb | 8 +- lib/sisu/v5/xml_sax.rb | 8 +- lib/sisu/v5/xml_scaffold_structure_collapsed.rb | 4 +- lib/sisu/v5/xml_scaffold_structure_sisu.rb | 4 +- 36 files changed, 276 insertions(+), 280 deletions(-) (limited to 'lib') diff --git a/lib/sisu/v5/air.rb b/lib/sisu/v5/air.rb index cd5c2f68..a6636fe9 100644 --- a/lib/sisu/v5/air.rb +++ b/lib/sisu/v5/air.rb @@ -62,7 +62,7 @@ module SiSU_Air require_relative 'particulars' # particulars.rb class Source - @@dal_array=[] + @@ao_array=[] @@fns=nil def initialize(opt) @opt=opt @@ -70,7 +70,7 @@ module SiSU_Air @particulars=SiSU_Particulars::Combined.new(opt) #@env=@particulars.env #@md=@particulars.md - #@dal_array=@particulars.dal_array + #@ao_array=@particulars.ao_array end def read end @@ -78,7 +78,7 @@ module SiSU_Air def print puts @particulars.md.inspect puts @particulars.env.inspect - puts @particulars.dal_array + puts @particulars.ao_array end end end diff --git a/lib/sisu/v5/ao.rb b/lib/sisu/v5/ao.rb index 00484ff9..7c367980 100644 --- a/lib/sisu/v5/ao.rb +++ b/lib/sisu/v5/ao.rb @@ -89,7 +89,7 @@ module SiSU_AO end end class Source #{cf.meta}").txt_grey + SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"ao -> #{cf.meta}").txt_grey end end - dal.each {|s| dal_array << s} + ao.each {|s| ao_array << s} if @opt.act[:maintenance][:set]==:on - dal_array.each do |obj| + ao_array.each do |obj| if defined? obj.parent if defined? obj.ln if defined? obj.node @@ -317,19 +317,19 @@ module SiSU_AO end end end - dal_array + ao_array end def read_fnm - dal=[] - dal=(FileTest.file?(@fnm)) \ - ? (File.open(@fnm,'r:utf-8'){ |f| dal=Marshal.load(f)}) - : SiSU_AO::Source.new(@opt).create_dal + ao=[] + ao=(FileTest.file?(@fnm)) \ + ? (File.open(@fnm,'r:utf-8'){ |f| ao=Marshal.load(f)}) + : SiSU_AO::Source.new(@opt).create_ao end def read_fnc - dal=[] - dal=(FileTest.file?(@fnc)) \ - ? (File.open(@fnc,'r:utf-8'){ |f| dal=Marshal.load(f)}) - : SiSU_AO::Source.new(@opt).create_dal + ao=[] + ao=(FileTest.file?(@fnc)) \ + ? (File.open(@fnc,'r:utf-8'){ |f| ao=Marshal.load(f)}) + : SiSU_AO::Source.new(@opt).create_ao end def read_idx_sst m=[] @@ -439,21 +439,21 @@ module SiSU_AO end end else - hard="#{@dir.processing_path.dal}/#{@md.fns}.meta" + hard="#{@dir.processing_path.ao}/#{@md.fns}.meta" File.unlink(hard) if FileTest.file?(hard) - hard="#{@dir.processing_path.dal}/#{@md.fns}.txt" + hard="#{@dir.processing_path.ao}/#{@md.fns}.txt" File.unlink(hard) if FileTest.file?(hard) - hard="#{@dir.processing_path.dal}/#{@md.fns}.debug.txt" + hard="#{@dir.processing_path.ao}/#{@md.fns}.debug.txt" File.unlink(hard) if FileTest.file?(hard) end end def make_marshal_content - marshal_dal=@make.marshal.dal_content - File.open(marshal_dal,'w'){|f| Marshal.dump(@data,f)} if @data.is_a?(Array) + marshal_ao=@make.marshal.ao_content + File.open(marshal_ao,'w'){|f| Marshal.dump(@data,f)} if @data.is_a?(Array) end def make_marshal_metadata - marshal_dal=@make.marshal.dal_metadata - File.open(marshal_dal,'w'){|f| Marshal.dump(@data,f)} if @data.is_a?(Array) + marshal_ao=@make.marshal.ao_metadata + File.open(marshal_ao,'w'){|f| Marshal.dump(@data,f)} if @data.is_a?(Array) end def idx_html_hard_output if @md.book_idx \ @@ -464,33 +464,33 @@ module SiSU_AO @data.each {|s| filename_meta.puts s.strip + "\n" unless s.strip.empty?} end else - hard_idx_html="#{@dir.processing_path.dal}/#{@md.fns}.idx.html" + hard_idx_html="#{@dir.processing_path.ao}/#{@md.fns}.idx.html" File.unlink(hard_idx_html) if FileTest.file?(hard_idx_html) end end def make_marshal_idx_sst_html_seg - marshal_dal=@make.marshal.dal_idx_sst_rel_html_seg - File.open(marshal_dal,'w'){|f| Marshal.dump(@data,f)} if @data.is_a?(Array) + marshal_ao=@make.marshal.ao_idx_sst_rel_html_seg + File.open(marshal_ao,'w'){|f| Marshal.dump(@data,f)} if @data.is_a?(Array) end def make_marshal_idx_sst_rel - marshal_dal=@make.marshal.dal_idx_sst_rel - File.open(marshal_dal,'w'){|f| Marshal.dump(@data,f)} if @data.is_a?(Array) + marshal_ao=@make.marshal.ao_idx_sst_rel + File.open(marshal_ao,'w'){|f| Marshal.dump(@data,f)} if @data.is_a?(Array) end def make_marshal_idx_html - marshal_dal=@make.marshal.dal_idx_html - File.open(marshal_dal,'w'){|f| Marshal.dump(@data,f)} if @data.is_a?(Array) + marshal_ao=@make.marshal.ao_idx_html + File.open(marshal_ao,'w'){|f| Marshal.dump(@data,f)} if @data.is_a?(Array) end def make_marshal_idx_xhtml - marshal_dal=@make.marshal.dal_idx_xhtml - File.open(marshal_dal,'w'){|f| Marshal.dump(@data,f)} if @data.is_a?(Array) + marshal_ao=@make.marshal.ao_idx_xhtml + File.open(marshal_ao,'w'){|f| Marshal.dump(@data,f)} if @data.is_a?(Array) end def make_marshal_map_nametags - marshal_dal=@make.marshal.dal_map_nametags - File.open(marshal_dal,'w'){|f| Marshal.dump(@data,f)} if @data.is_a?(Hash) + marshal_ao=@make.marshal.ao_map_nametags + File.open(marshal_ao,'w'){|f| Marshal.dump(@data,f)} if @data.is_a?(Hash) end def make_marshal_map_name_ocn_htmlseg - marshal_dal=@make.marshal.dal_map_ocn_htmlseg - File.open(marshal_dal,'w'){|f| Marshal.dump(@data,f)} if @data.is_a?(Hash) + marshal_ao=@make.marshal.ao_map_ocn_htmlseg + File.open(marshal_ao,'w'){|f| Marshal.dump(@data,f)} if @data.is_a?(Hash) end end class Make @@ -505,17 +505,17 @@ module SiSU_AO def song reset data=@data - data=SiSU_AO_Insertions::Insertions.new(@md,data).expand_insertions? # dal_expand_insertions.rb - data=SiSU_AO_MiscArrangeText::SI.new(@md,data).prepare_text # dal_misc_arrange.rb - data,metadata=SiSU_AO_DocumentStructureExtract::Build.new(@md,data).identify_parts # dal_doc_str.rb - data=SiSU_AO_Syntax::Markup.new(@md,data).songsheet # dal_syntax.rb - data,endnote_array=SiSU_AO_CharacterCheck::Check.new(data).character_check_and_oldstyle_endnote_array # dal_character_check.rb - data=SiSU_AO_Images::Images.new(@md,data).images # dal_images.rb - data,tags_map,ocn_html_seg_map=SiSU_AO_Numbering::Numbering.new(@md,data).numbering_song # dal_numbering.rb - data,book_index_rel,book_index_rel_html_seg,html_idx,xhtml_idx=SiSU_AO_BookIndex::BookIndex.new(@md,data,@env).indexing_song if @md.book_idx # dal_idx.rb - data=SiSU_AO_Endnotes::Endnotes.new(@md,data,endnote_array).endnotes # dal_endnotes.rb + data=SiSU_AO_Insertions::Insertions.new(@md,data).expand_insertions? # ao_expand_insertions.rb + data=SiSU_AO_MiscArrangeText::SI.new(@md,data).prepare_text # ao_misc_arrange.rb + data,metadata=SiSU_AO_DocumentStructureExtract::Build.new(@md,data).identify_parts # ao_doc_str.rb + data=SiSU_AO_Syntax::Markup.new(@md,data).songsheet # ao_syntax.rb + data,endnote_array=SiSU_AO_CharacterCheck::Check.new(data).character_check_and_oldstyle_endnote_array # ao_character_check.rb + data=SiSU_AO_Images::Images.new(@md,data).images # ao_images.rb + data,tags_map,ocn_html_seg_map=SiSU_AO_Numbering::Numbering.new(@md,data).numbering_song # ao_numbering.rb + data,book_index_rel,book_index_rel_html_seg,html_idx,xhtml_idx=SiSU_AO_BookIndex::BookIndex.new(@md,data,@env).indexing_song if @md.book_idx # ao_idx.rb + data=SiSU_AO_Endnotes::Endnotes.new(@md,data,endnote_array).endnotes # ao_endnotes.rb outputdata=data - if (@md.opt.act[:dal][:set]==:on \ + if (@md.opt.act[:ao][:set]==:on \ || @md.opt.act[:maintenance][:set]==:on) SiSU_AO::Output.new(@fn,@md,outputdata).hard_output SiSU_AO::Output.new(@fn,@md,outputdata).make_marshal_content diff --git a/lib/sisu/v5/ao_hash_digest.rb b/lib/sisu/v5/ao_hash_digest.rb index 70deee80..e1cc840c 100644 --- a/lib/sisu/v5/ao_hash_digest.rb +++ b/lib/sisu/v5/ao_hash_digest.rb @@ -96,7 +96,7 @@ module SiSU_AO_Hash end end @tuned_file=@tuned_file.flatten - #use md5 or to create hash of each dal object including ocn, & add into to each dal object + #use md5 or to create hash of each ao object including ocn, & add into to each ao object end def endnote_digest(data) t_o_bit=[] @@ -143,7 +143,7 @@ module SiSU_AO_Hash end t_o #KEEP intact end - def strip_clean_extra_spaces(s) # dal output tuned + def strip_clean_extra_spaces(s) # ao output tuned s=s.dup s=s.gsub(/[ ]+([,.;:?](?:$|\s))/,'\1') unless s =~/#{Mx[:en_a_o]}|#{Mx[:en_b_o]}/ s=s.gsub(/ [ ]+/,' '). diff --git a/lib/sisu/v5/concordance.rb b/lib/sisu/v5/concordance.rb index 3ad394c7..8c675e36 100644 --- a/lib/sisu/v5/concordance.rb +++ b/lib/sisu/v5/concordance.rb @@ -202,7 +202,7 @@ WOK def initialize(particulars) @particulars=particulars begin - @env,@md,@dal_array=particulars.env,particulars.md,particulars.dal_array + @env,@md,@ao_array=particulars.env,particulars.md,particulars.ao_array @file=SiSU_Env::FileOp.new(@md) @freq=Hash.new(0) @dp=@@dp ||=SiSU_Env::InfoEnv.new.digest.pattern @@ -256,7 +256,7 @@ WOK def map_para @seg,ocn=nil,nil @word_map={} - @dal_array.each do |line| + @ao_array.each do |line| if defined? line.ocn \ and line.ocn.to_s =~/\d/ if (line.is ==:heading \ diff --git a/lib/sisu/v5/conf.rb b/lib/sisu/v5/conf.rb index 9418ff21..57e9614b 100644 --- a/lib/sisu/v5/conf.rb +++ b/lib/sisu/v5/conf.rb @@ -161,7 +161,7 @@ module SiSU_Initialize end def trang_rnc_model_output_sax s=@suffix - rnc_src=@env.processing_path.dal + '/sax.' + s[:rnc] + rnc_src=@env.processing_path.ao + '/sax.' + s[:rnc] rnc_file=@path[:rnc] + '/' + @rxng.rnc_name.output_sax rng_file=@path[:rng] + '/' + @rxng.rng_name.output_sax xsd_file=@path[:xsd] + '/' + @rxng.xsd_name.output_sax @@ -183,7 +183,7 @@ module SiSU_Initialize end def trang_rnc_model_output_dom s=@suffix - rnc_src=@env.processing_path.dal + '/dom.' + s[:rnc] + rnc_src=@env.processing_path.ao + '/dom.' + s[:rnc] rnc_file=@path[:rnc] + '/' + @rxng.rnc_name.output_dom rng_file=@path[:rng] + '/' + @rxng.rng_name.output_dom xsd_file=@path[:xsd] + '/' + @rxng.xsd_name.output_dom @@ -205,7 +205,7 @@ module SiSU_Initialize end def trang_rnc_model_output_xhtml s=@suffix - rnc_src=@env.processing_path.dal + '/xhtml.' + s[:rnc] + rnc_src=@env.processing_path.ao + '/xhtml.' + s[:rnc] rnc_file=@path[:rnc] + '/' + @rxng.rnc_name.output_xhtml rng_file=@path[:rng] + '/' + @rxng.rng_name.output_xhtml xsd_file=@path[:xsd] + '/' + @rxng.xsd_name.output_xhtml @@ -226,7 +226,7 @@ module SiSU_Initialize end end def trang_rnc_model_input_sax - rnc_file=@env.processing_path.dal + '/sax.rnc' + rnc_file=@env.processing_path.ao + '/sax.rnc' dtd_file=@path[:xsd] + '/' + @rxng.rng_name.input_sax rnc=File.new(rnc_file,'w') rnc << @rxng.rnc_model_output_sax @@ -235,7 +235,7 @@ module SiSU_Initialize schema.relaxng(@opt.cmd) end def trang_rnc_model_input_dom - rnc_file=@env.processing_path.dal + '/dom.rnc' + rnc_file=@env.processing_path.ao + '/dom.rnc' dtd_file=@path[:xsd] + '/' + @rxng.rng_name.input_dom rnc=File.new(rnc_file,'w') rnc << @rxng.rnc_model_output_dom @@ -244,7 +244,7 @@ module SiSU_Initialize schema.relaxng(@opt.cmd) end def trang_rnc_model_input_node - rnc_file=@env.processing_path.dal + '/node.rnc' + rnc_file=@env.processing_path.ao + '/node.rnc' dtd_file=@path[:xsd] + '/' + @rxng.rng_name.input_node rnc=File.new(rnc_file,'w') rnc << @rxng.rnc_model_input_node diff --git a/lib/sisu/v5/db_import.rb b/lib/sisu/v5/db_import.rb index 147f27df..8a8cc13d 100644 --- a/lib/sisu/v5/db_import.rb +++ b/lib/sisu/v5/db_import.rb @@ -76,7 +76,7 @@ module SiSU_DbImport @opt,@conn,@file_maint,@sql_type=opt,conn,file_maint,sql_type @cX=SiSU_Screen::Ansi.new(@opt.act[:color_state][:set]).cX @env=SiSU_Env::InfoEnv.new(@opt.fns) - @dal="#{@env.processing_path.dal}" + @dal="#{@env.processing_path.ao}" @fnb=if @opt.fns.empty? \ or @opt.cmd.empty? '' @@ -121,8 +121,8 @@ module SiSU_DbImport @@dl ||=SiSU_Env::InfoEnv.new.digest.length end def marshal_load - require_relative 'ao' # ao.rb - @dal_array=SiSU_AO::Source.new(@opt).get # dal file drawn here + require_relative 'ao' # ao.rb + @ao_array=SiSU_AO::Source.new(@opt).get # ao file drawn here if (@opt.act[:verbose][:set]==:on \ || @opt.act[:verbose_plus][:set]==:on \ || @opt.act[:maintenance][:set]==:on) @@ -142,8 +142,8 @@ module SiSU_DbImport if not file_exist t_d=[] # transaction_data t_d << db_import_metadata - t_d << db_import_documents(@dal_array) - t_d << db_import_urls(@dal_array,@fnc) #import OID on/off + t_d << db_import_documents(@ao_array) + t_d << db_import_urls(@ao_array,@fnc) #import OID on/off t_d=t_d.flatten if (@opt.act[:verbose_plus][:set]==:on \ || @opt.act[:maintenance][:set]==:on) @@ -283,12 +283,12 @@ module SiSU_DbImport tuple=t.tuple tuple end - def db_import_documents(dal_array) #% import documents - populate main database table, import into substantive database tables (tuple) + def db_import_documents(ao_array) #% import documents - populate main database table, import into substantive database tables (tuple) begin @col[:tid]=@@id_t @en,@en_ast,@en_pls,@tuple_array=[],[],[],[] @col[:en_a],@col[:en_z]=nil,nil - dal_array.each do |data| + ao_array.each do |data| data.obj.gsub!(/#{Mx[:fa_bold_o]}(.+?)#{Mx[:fa_bold_c]}/,'\1') data.obj.gsub!(/#{Mx[:fa_italics_o]}(.+?)#{Mx[:fa_italics_c]}/,'\1') data.obj.gsub!(/#{Mx[:fa_underscore_o]}(.+?)#{Mx[:fa_underscore_c]}/,'\1') diff --git a/lib/sisu/v5/digests.rb b/lib/sisu/v5/digests.rb index e142ff11..0afa7378 100644 --- a/lib/sisu/v5/digests.rb +++ b/lib/sisu/v5/digests.rb @@ -75,7 +75,7 @@ module SiSU_DigestView end def read begin - @env,@md,@dal_array=@particulars.env,@particulars.md,@particulars.dal_array + @env,@md,@ao_array=@particulars.env,@particulars.md,@particulars.ao_array unless @opt.act[:quiet][:set]==:on tool=(@opt.act[:verbose][:set]==:on \ || @opt.act[:verbose_plus][:set]==:on \ @@ -107,7 +107,7 @@ module SiSU_DigestView @@description,@@ds[:digests],@@ds[:tree],@@ds[:summary],@@sc_info=[],[],[],[],[] def initialize(particulars) #data='',md='') @particulars=particulars - @data,@env,@md=@particulars.dal_array,@particulars.env,@particulars.md + @data,@env,@md=@particulars.ao_array,@particulars.env,@particulars.md SiSU_Env::FileOp.new(@md).mkdir @@dg ||=@env.digest.type @@dl ||=@env.digest.length @@ -120,7 +120,7 @@ module SiSU_DigestView def songsheet @@description,@@ds[:digests],@@ds[:tree],@@ds[:summary],@@sc_info=[],[],[],[],[] message_digest - dal_structure + ao_structure supplementary output end @@ -132,11 +132,11 @@ module SiSU_DigestView puts f if @md.opt.act[:verbose_plus][:set]==:on @@ds[:digests] << f + "\n" end - def dal_structure_tree(f,e='') + def ao_structure_tree(f,e='') puts f + e.to_s if @md.opt.act[:verbose_plus][:set]==:on @@ds[:tree] << f << e end - def dal_structure_summary(f,e='') + def ao_structure_summary(f,e='') puts f + e.to_s if @md.opt.act[:verbose_plus][:set]==:on @@ds[:summary] << f << e end @@ -302,7 +302,7 @@ module SiSU_DigestView description("Document Digests\n") description(a) end - def dal_structure + def ao_structure data=@data endnotes=nil data.each do |t_o| @@ -330,8 +330,8 @@ module SiSU_DigestView end l=Hash.new(0) ocn=nil - dal_structure_tree("------------\n") - dal_structure_tree("document structure[*]\n") + ao_structure_tree("------------\n") + ao_structure_tree("document structure[*]\n") data.each do |t_o| if t_o.is==:heading x=case t_o.ln @@ -351,11 +351,11 @@ module SiSU_DigestView end end ocn=t_o.ocn if defined? t_o.ocn and t_o.is !=:heading_insert - dal_structure_tree("#{x}\n") if x and not x.empty? + ao_structure_tree("#{x}\n") if x and not x.empty? end - dal_structure_tree(" [*] heading levels\n") - dal_structure_summary("------------\n") - dal_structure_summary("document structure[*]\n") + ao_structure_tree(" [*] heading levels\n") + ao_structure_summary("------------\n") + ao_structure_summary("document structure[*]\n") [0,1,2,3,4,5,6].each do |y| v=case y when 1; ':A' @@ -365,11 +365,11 @@ module SiSU_DigestView when 5; '2 ' when 6; '3 ' end - dal_structure_summary("#{v} = #{l[y]}\n") if l[y] > 0 + ao_structure_summary("#{v} = #{l[y]}\n") if l[y] > 0 end - dal_structure_summary("objects (ocn) = #{ocn}\n") - dal_structure_summary("endnotes = #{endnotes}\n") - dal_structure_summary(" [*] number of headers (@) and of each heading level (:A to :C and 1 to 3)\n") + ao_structure_summary("objects (ocn) = #{ocn}\n") + ao_structure_summary("endnotes = #{endnotes}\n") + ao_structure_summary(" [*] number of headers (@) and of each heading level (:A to :C and 1 to 3)\n") end def supplementary if defined? @md.sc_number \ diff --git a/lib/sisu/v5/epub.rb b/lib/sisu/v5/epub.rb index 969debe2..5f4957aa 100644 --- a/lib/sisu/v5/epub.rb +++ b/lib/sisu/v5/epub.rb @@ -149,8 +149,8 @@ module SiSU_EPUB def tuned_file_instructions @tell=SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set]) directories - dal_array=@particulars.dal_array # dal file drawn here - @tuned_file_array=SiSU_EPUB_Tune::Tune.new(dal_array,@md).songsheet + ao_array=@particulars.ao_array # ao file drawn here + @tuned_file_array=SiSU_EPUB_Tune::Tune.new(ao_array,@md).songsheet @tuned_file_array end end diff --git a/lib/sisu/v5/epub_concordance.rb b/lib/sisu/v5/epub_concordance.rb index 628435f2..ab5b272a 100644 --- a/lib/sisu/v5/epub_concordance.rb +++ b/lib/sisu/v5/epub_concordance.rb @@ -156,7 +156,7 @@ WOK @particulars=particulars begin @vz=SiSU_Viz::Defaults.new - @env,@md,@dal_array=particulars.env,particulars.md,particulars.dal_array + @env,@md,@ao_array=particulars.env,particulars.md,particulars.ao_array @path="#{@env.processing_path.epub}" @freq=Hash.new(0) @rxp_lv1=/^#{Mx[:lv_o]}1:/ #fix Mx[:lv_o] @@ -214,7 +214,7 @@ WOK def map_para @seg,toy=nil,nil @word_map={} - @dal_array.each do |line| + @ao_array.each do |line| if defined? line.ocn if (line.is ==:heading \ || line.is ==:heading_insert) \ diff --git a/lib/sisu/v5/git.rb b/lib/sisu/v5/git.rb index 447117ca..7a69a187 100644 --- a/lib/sisu/v5/git.rb +++ b/lib/sisu/v5/git.rb @@ -190,7 +190,7 @@ module SiSU_Git def locate_parse_file composite_src=@opt.fns=~/\.ssm$/ ? true : false if composite_src \ - and not @opt.act[:dal][:set]==:on + and not @opt.act[:ao][:set]==:on ##SiSU_Assemble::Composite.new(@opt).read #SiSU_AO::Source.new(@opt).read # -m "#{@env.processing_path.composite_file}/#{@opt.fnb}.ssm.sst" diff --git a/lib/sisu/v5/html.rb b/lib/sisu/v5/html.rb index f1abe6c0..7a1c4b60 100644 --- a/lib/sisu/v5/html.rb +++ b/lib/sisu/v5/html.rb @@ -162,8 +162,8 @@ module SiSU_HTML end def tuned_file_instructions @tell=SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set]) - dal_array=@particulars.dal_array # dal file drawn here - tuned_file_array=SiSU_HTML_Tune::Tune.new(dal_array,@md).songsheet + ao_array=@particulars.ao_array # ao file drawn here + tuned_file_array=SiSU_HTML_Tune::Tune.new(ao_array,@md).songsheet tuned_file_array end end diff --git a/lib/sisu/v5/hub.rb b/lib/sisu/v5/hub.rb index c6545c1d..9390d517 100644 --- a/lib/sisu/v5/hub.rb +++ b/lib/sisu/v5/hub.rb @@ -280,7 +280,7 @@ module SiSU Dir.chdir(@opt.pth) #watch end @env=SiSU_Env::InfoEnv.new(@opt.fns) - if @opt.act[:dal][:set]==:on #% --dal, -m + if @opt.act[:ao][:set]==:on #% --ao --dal, -m unless @opt.act[:po4a][:set]==:on # --po4a, -P if @opt.fno =~ /\.ssm$/ require_relative 'composite' # composite.rb #pre-processing @@ -529,7 +529,7 @@ module SiSU SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],' ' + File.dirname(__FILE__)).grey end end - if @opt.act[:dal][:set]==:on \ + if @opt.act[:ao][:set]==:on \ or @opt.act[:maintenance][:set]==:on #% --maintenance, -m for -C path={} path[:css]=@@env.path.output + '/_sisu/css' @@ -581,7 +581,7 @@ module SiSU if @opt.act[:webrick][:set]==:on #% --webrick, -W webrick SiSU::Operations.new(@opt).webrick end - if @opt.act[:dal][:set]==:on + if @opt.act[:ao][:set]==:on @retry_count= -1 begin @get_s,@get_p,@get_pl=[],[],[] @@ -633,7 +633,7 @@ module SiSU and @opt.mod.join(';') =~/--(?:createdb|init(?:ialize)?|create(?:all)?|createtables|recreate|drop(?:all))/) :false else - (@opt.act[:dal][:set]==:on \ + (@opt.act[:ao][:set]==:on \ || @opt.act[:manpage][:set]==:on \ || @opt.act[:texinfo][:set]==:on \ || @opt.act[:txt][:set]==:on \ diff --git a/lib/sisu/v5/manpage.rb b/lib/sisu/v5/manpage.rb index 8f721fd2..905cf87f 100644 --- a/lib/sisu/v5/manpage.rb +++ b/lib/sisu/v5/manpage.rb @@ -100,8 +100,8 @@ module SiSU_Manpage || @opt.act[:maintenance][:set]==:on) SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],@opt.fns,"#{@md.file.output_path.manpage.dir}/#{@md.file.base_filename.manpage}").flow end - @dal_array=SiSU_AO::Source.new(@opt).get # dal file drawn here - SiSU_Manpage::Source::Scroll.new(@md,@dal_array).songsheet + @ao_array=SiSU_AO::Source.new(@opt).get # ao file drawn here + SiSU_Manpage::Source::Scroll.new(@md,@ao_array).songsheet rescue SiSU_Errors::Rescued.new($!,$@,@opt.cmd,@opt.fns).location do __LINE__.to_s + ':' + __FILE__ diff --git a/lib/sisu/v5/odf.rb b/lib/sisu/v5/odf.rb index b64c8ebe..c865b0cb 100644 --- a/lib/sisu/v5/odf.rb +++ b/lib/sisu/v5/odf.rb @@ -81,7 +81,7 @@ module SiSU_ODF end def read begin - @md,@env,@dal_array=@particulars.md,@particulars.env,@particulars.dal_array + @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 \ @@ -115,7 +115,7 @@ module SiSU_ODF @@docstart=true @@fns=nil def initialize(particulars) - @md,@env,@dal_array=particulars.md,particulars.env,particulars.dal_array + @md,@env,@ao_array=particulars.md,particulars.env,particulars.ao_array @vz=SiSU_Viz::Defaults.new @tab="\t" @brace_url=SiSU_Viz::Defaults.new.url_decoration @@ -125,7 +125,7 @@ module SiSU_ODF def songsheet begin pre - @data=markup(@dal_array) + @data=markup(@ao_array) publish ensure unless (@md.opt.act[:verbose_plus][:set]==:on \ diff --git a/lib/sisu/v5/options.rb b/lib/sisu/v5/options.rb index 7203f8b2..650105fa 100644 --- a/lib/sisu/v5/options.rb +++ b/lib/sisu/v5/options.rb @@ -496,7 +496,7 @@ module SiSU_Commandline when /^--(?:color-toggle)$/; c=c+'c' when /^--(?:color-off)$/; c=c+'k' when /^--(?:conf|config|configure|init|initialize|init-site)$/; c=c+'CC' - when /^--(?:dal?|machine|abstraction|abs)$/; c=c+'m' + when /^--(?:ao|dal?|machine|abstraction|abs)$/; c=c+'m' when /^--(?:txt|text|plaintext)$/; c=c+'t' when /^--(?:html)$/; c=c+'h' when /^--(?:html-scroll|html-seg)$/; c=c+'H' @@ -552,12 +552,12 @@ module SiSU_Commandline if cmd !~/[mn]/ extra+=if cmd =~/[abegHhIiLNOoPpQTtwXxyz]/ \ and cmd !~/[mn]/ - 'm' #% add dal + 'm' #% add ao elsif ((cmd =~/[Dd]/ \ or (mod.inspect =~/--(?:(?:sq)?lite|pg(?:sql)?)/)) \ and mod.inspect !~/(?:remove|(?:(?:re)?create(?:all)?|dropall|drop)$)/) \ and cmd !~/[mn]/ - 'm' #% add dal + 'm' #% add ao else '' end end @@ -883,10 +883,6 @@ module SiSU_Commandline || mod.inspect =~/"--texinfo"/) \ ? { bool: true, set: :on } : { bool: false, set: :na } - act[:fictionbook]=(cmd =~/f/ \ - || mod.inspect =~/"--fictionbook"/) \ - ? { bool: true, set: :on } - : { bool: false, set: :na } act[:psql]=(cmd =~/D/ \ || mod.inspect =~/"--pg"|"--pgsql"/) \ ? { bool: true, set: :on } @@ -964,8 +960,8 @@ module SiSU_Commandline act[:help]=(mod.inspect =~/"--help/) \ ? { bool: true, set: :on } : { bool: false, set: :na } - act[:dal]=if (cmd =~/m/ \ - || mod.inspect =~/"--dal"/) + act[:ao]=if (cmd =~/m/ \ + || mod.inspect =~/"--ao"|"--dal"/) { bool: true, set: :on } elsif (act[:txt][:set]==:on \ || act[:xhtml][:set]==:on \ @@ -992,14 +988,14 @@ module SiSU_Commandline #if cmd !~/[mn]/ # extra+=if cmd =~/[abegHhIiLNOoPpQTtwXxyz]/ \ # and cmd !~/[mn]/ - # 'm' #% add dal + # 'm' #% add ao #elsif (act[:txt][:set]==:on \ # { bool: true, set: :on } # elsif ((cmd =~/[Dd]/ \ # or (mod.inspect =~/--(?:(?:sq)?lite|pg(?:sql)?)/)) \ # and mod.inspect !~/(?:remove|(?:(?:re)?create(?:all)?|dropall|drop)$)/) \ # and cmd !~/[mn]/ - # 'm' #% add dal + # 'm' #% add ao else { bool: false, set: :na } end diff --git a/lib/sisu/v5/param.rb b/lib/sisu/v5/param.rb index e8144a5e..d01f39e2 100644 --- a/lib/sisu/v5/param.rb +++ b/lib/sisu/v5/param.rb @@ -86,7 +86,7 @@ module SiSU_Param end SiSU_Param::Instantiate.new.param_instantiate @env=SiSU_Env::InfoEnv.new(@fns) - @pstorefile="#{@env.processing_path.dal}/#{@fns}.pstore" + @pstorefile="#{@env.processing_path.ao}/#{@fns}.pstore" end def get if @opt.f_pth \ @@ -1406,7 +1406,7 @@ module SiSU_Param end def store begin - pstorefile="#{@env.processing_path.dal}/#{@md.fns}.pstore" + pstorefile="#{@env.processing_path.ao}/#{@md.fns}.pstore" File.unlink(pstorefile) if FileTest.file?(pstorefile) if (@md.opt.act[:verbose_plus][:set]==:on \ || @md.opt.act[:maintenance][:set]==:on) diff --git a/lib/sisu/v5/particulars.rb b/lib/sisu/v5/particulars.rb index d06afc12..beeaf429 100644 --- a/lib/sisu/v5/particulars.rb +++ b/lib/sisu/v5/particulars.rb @@ -73,7 +73,7 @@ module SiSU_Particulars set_env(opt) set_file(opt) set_md(opt) - set_dal(opt) #needs @md + set_ao(opt) #needs @md end def get_env(opt) set_env(opt) @@ -84,8 +84,8 @@ module SiSU_Particulars def get_md(opt) set_md(opt) end - def get_dal_array(opt) - set_dal(opt) #needs @md + def get_ao_array(opt) + set_ao(opt) #needs @md end def get_env_md(opt) set_env(opt) @@ -149,10 +149,10 @@ module SiSU_Particulars end end end - attr_accessor :opt,:dal_array - def set_dal(opt) + attr_accessor :opt,:ao_array + def set_ao(opt) begin - @dal_array=SiSU_AO::Source.new(opt).get + @ao_array=SiSU_AO::Source.new(opt).get self rescue SiSU_Errors::Rescued.new($!,$@,opt.cmd,opt.fnl).location do diff --git a/lib/sisu/v5/plaintext.rb b/lib/sisu/v5/plaintext.rb index 8585ad9d..57838342 100644 --- a/lib/sisu/v5/plaintext.rb +++ b/lib/sisu/v5/plaintext.rb @@ -99,7 +99,7 @@ module SiSU_Plaintext SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],@opt.fns,"#{md.file.output_path.txt.dir}/#{md.file.base_filename.txt}").flow end end - dal_array=SiSU_AO::Source.new(@opt).get # dal file drawn here + ao_array=SiSU_AO::Source.new(@opt).get # ao file drawn here wrap_width=if defined? md.make.plaintext_wrap \ and md.make.plaintext_wrap md.make.plaintext_wrap @@ -109,7 +109,7 @@ module SiSU_Plaintext else 78 end #wrap_width=(defined? md.make.plaintext_wrap) ? md.make.plaintext_wrap : 78 - SiSU_Plaintext::Source::Scroll.new(md,dal_array,wrap_width).songsheet + SiSU_Plaintext::Source::Scroll.new(md,ao_array,wrap_width).songsheet rescue SiSU_Errors::Rescued.new($!,$@,@opt.cmd,@opt.fns).location do __LINE__.to_s + ':' + __FILE__ diff --git a/lib/sisu/v5/po4a.rb b/lib/sisu/v5/po4a.rb index 43ff51e9..217f2975 100644 --- a/lib/sisu/v5/po4a.rb +++ b/lib/sisu/v5/po4a.rb @@ -126,7 +126,7 @@ module SiSU_Po4a if @opt.fns =~/\S+?~#{@lang_regx}\.ss[mti]/ \ or @opt.f_pth[:lng] !=@opt.lng_base opt_lang_trn_fn=fn - @dal_array_lang_translation=SiSU_AO::Source.new(@opt,opt_lang_trn_fn).get # dal file drawn here + @ao_array_lang_translation=SiSU_AO::Source.new(@opt,opt_lang_trn_fn).get # ao file drawn here opt_lang_src_fn=if fn =~/\S+?~\S{2}(?:_\S{2})?\.ss[mti]/ fn.gsub(/(\S+?)~\S{2}(?:_\S{2})?(\.ss[mti])/,'\1\2') #check i else fn @@ -141,15 +141,15 @@ module SiSU_Po4a else nil end if FileTest.file?("#{srcdir}/#{opt_lang_src_fn}") - @dal_array_lang_src=SiSU_AO::Source.new(@@opt_src,opt_lang_src_fn).get # dal file drawn here + @ao_array_lang_src=SiSU_AO::Source.new(@@opt_src,opt_lang_src_fn).get # ao file drawn here else puts "no identified source document" exit end Dir.chdir(transdir) if transdir else - @dal_array_lang_src=SiSU_AO::Source.new(@opt,fn).get # dal file drawn here - @dal_array_lang_translation=nil + @ao_array_lang_src=SiSU_AO::Source.new(@opt,fn).get # ao file drawn here + @ao_array_lang_translation=nil end wrap_width=if defined? md.make.plaintext_wrap \ and md.make.plaintext_wrap @@ -159,7 +159,7 @@ module SiSU_Po4a env.plaintext_wrap else 78 end - SiSU_Po4a::Source::Scroll.new(fn,@dal_array_lang_src,@dal_array_lang_translation,@@md_src,@@md_trn,wrap_width).songsheet + SiSU_Po4a::Source::Scroll.new(fn,@ao_array_lang_src,@ao_array_lang_translation,@@md_src,@@md_trn,wrap_width).songsheet end rescue SiSU_Errors::Rescued.new($!,$@,@opt.cmd,@opt.fns).location do diff --git a/lib/sisu/v5/prog_text_translation.rb b/lib/sisu/v5/prog_text_translation.rb index 8425a109..ae166d23 100644 --- a/lib/sisu/v5/prog_text_translation.rb +++ b/lib/sisu/v5/prog_text_translation.rb @@ -473,7 +473,7 @@ module SiSU_Translate 'Document (RCS/CVS) number' end def last_generated - 'Document (dal) last generated' + 'Document (ao) last generated' end def sisu_version 'Generated by' @@ -1324,7 +1324,7 @@ module SiSU_Translate 'Numero di revisione (RCS/CVS)' end def last_generated - 'Data di ultima generazione (dal metaverse)' + 'Data di ultima generazione (ao metaverse)' end def sisu_version 'Generato da' diff --git a/lib/sisu/v5/relaxng.rb b/lib/sisu/v5/relaxng.rb index f6426f54..ef632308 100644 --- a/lib/sisu/v5/relaxng.rb +++ b/lib/sisu/v5/relaxng.rb @@ -327,9 +327,9 @@ element-external_space = } RELAXNG end - def rnc_sisu_object_dal + def rnc_sisu_object_ao @relaxng =< #{@md.fns}.fn").txt_red unless @md.opt.act[:quiet][:set]==:on - dal.each {|s| dal_array << "#{s.strip}\n\n" unless s.strip.empty?} - dal_array + ao.each {|s| ao_array << "#{s.strip}\n\n" unless s.strip.empty?} + ao_array else SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set],'*WARN* no footnote conversion done, problem with source file','to override use --convert=footnote-force (this is not advised)').warn unless @md.opt.act[:quiet][:set]==:on '' end end def read_fnm - dal=[] - dal=(FileTest.file?(@fnm)) \ - ? (File.open(@fnm){ |f| dal=Marshal.load(f)}) - : (SiSU_ConvertFootnotes::Source.new(@opt).create_dal) #watch + ao=[] + ao=(FileTest.file?(@fnm)) \ + ? (File.open(@fnm){ |f| ao=Marshal.load(f)}) + : (SiSU_ConvertFootnotes::Source.new(@opt).create_ao) #watch end end class Output @@ -189,7 +189,7 @@ module SiSU_ConvertFootnotes def song reset data=@data - @metafile="#{@env.processing_path.dal}/#{@md.fns}.meta" + @metafile="#{@env.processing_path.ao}/#{@md.fns}.meta" SiSU_Env::CreateFile.new(@md.fns) data=data.join.split("\n\n") data_new=[] @@ -458,7 +458,7 @@ module SiSU_ConvertFootnotes end end end - def strip_clean_extra_spaces(s) # dal output tuned + def strip_clean_extra_spaces(s) # ao output tuned s=s.dup s=s.gsub(/[ ]+([,.;:?](?:$|\s))/,'\1') s=s.gsub(/ [ ]+/,' ') @@ -482,4 +482,4 @@ module SiSU_ConvertFootnotes end __END__ @particulars=SiSU_Particulars::CombinedSingleton.instance.get_all(opt) -dal_array=@particulars.dal_array # dal file drawn here +ao_array=@particulars.ao_array # ao file drawn here diff --git a/lib/sisu/v5/sst_to_s_xml_sax.rb b/lib/sisu/v5/sst_to_s_xml_sax.rb index a3fbde9f..09fecc9e 100644 --- a/lib/sisu/v5/sst_to_s_xml_sax.rb +++ b/lib/sisu/v5/sst_to_s_xml_sax.rb @@ -109,9 +109,9 @@ module SiSU_SimpleXML_ModelSax end end def read_fnm - dal=[] + ao=[] if FileTest.file?("#{Dir.pwd}/#{@opt.fns}") - dal=IO.readlines("#{Dir.pwd}/#{@opt.fns}","\n\n") + ao=IO.readlines("#{Dir.pwd}/#{@opt.fns}","\n\n") else STDERR.puts 'Error' end end diff --git a/lib/sisu/v5/sysenv.rb b/lib/sisu/v5/sysenv.rb index 19031711..344a88d3 100644 --- a/lib/sisu/v5/sysenv.rb +++ b/lib/sisu/v5/sysenv.rb @@ -142,7 +142,7 @@ module SiSU_Env PROCESSING_PATH=:processing_path PROCESSING_DIR_TMP_ROOT=:processing_dir_tmp_root PROCESSING_PATH_TMP_BASE=:processing_path_tmp_base - PROCESSING_AO=:processing_dal + PROCESSING_AO=:processing_ao PROCESSING_TUNE=:processing_tune PROCESSING_LATEX=:processing_latex PROCESSING_TEXINFO=:processing_texinfo @@ -2161,7 +2161,7 @@ WOK ? ("#{root_dir}/#{user}/#{stub_pwd}") : ("#{root_dir}/#{stub_pwd}") # see defaults[:processing_path] end - def processing_sisupod(opt=nil) #processing directory, used/needed for sisu work files, has sub-directories (dal,tex etc) + def processing_sisupod(opt=nil) #processing directory, used/needed for sisu work files, has sub-directories (ao,tex etc) @opt=opt def paths processing_path_usr="#{root_dir}/#{user}" @@ -2195,7 +2195,7 @@ WOK end self end - def processing #processing directory, used/needed for sisu work files, has sub-directories (dal,tex etc) + def processing #processing directory, used/needed for sisu work files, has sub-directories (ao,tex etc) unless FileTest.directory?(root_dir) FileUtils::mkdir_p(root_dir) File.chmod(0777,root_dir) @@ -2219,11 +2219,11 @@ WOK end processing end - def dal + def ao pth=if defined? @rc['processing']['dal'] \ and @rc['processing']['dal'].is_a?(String) "#{processing}/#{@rc['processing']['dal']}" - else "#{processing}/#{defaults[:processing_dal]}" + else "#{processing}/#{defaults[:processing_ao]}" end FileUtils::mkdir_p(pth) unless FileTest.directory?(pth) pth @@ -2238,7 +2238,7 @@ WOK pth end def composite_file - pth=processing_path.dal #"#{processing}/composite" + pth=processing_path.ao #"#{processing}/composite" FileUtils::mkdir_p(pth) unless FileTest.directory?(pth) pth end @@ -2978,51 +2978,51 @@ WOK ? (SiSU_Env::InfoEnv.new(@opt.fns)) : (SiSU_Env::InfoEnv.new('dummy.sst'))) ft=[] - if @opt.act[:dal][:set]==:on + if @opt.act[:ao][:set]==:on @md=SiSU_Param::Parameters.new(@opt).get if @md \ and defined? @md.fn \ and @md.fn # used for by_language_code? - if @md.opt.act[:html][:set]==:on #% --html, -h -H + if @md.opt.act[:html][:set]==:on #% --html, -h -H ft << @md.fn[:html] end - if @md.opt.act[:concordance][:set]==:on #% --concordance, -w + if @md.opt.act[:concordance][:set]==:on #% --concordance, -w ft << @md.fn[:concordance] end - if @md.opt.act[:manifest][:set]==:on #% --manifest, -y + if @md.opt.act[:manifest][:set]==:on #% --manifest, -y ft << @md.fn[:manifest] end - if @md.opt.act[:txt][:set]==:on #% --txt, -t -a + if @md.opt.act[:txt][:set]==:on #% --txt, -t -a ft << @md.fn[:plain] end - if @md.opt.act[:xhtml][:set]==:on #% --xhtml, -b xhtml + if @md.opt.act[:xhtml][:set]==:on #% --xhtml, -b xhtml ft << @md.fn[:xhtml] end - if @md.opt.act[:epub][:set]==:on #% --epub, -e + if @md.opt.act[:epub][:set]==:on #% --epub, -e ft << @md.fn[:epub] end - if @md.opt.act[:manpage][:set]==:on #% --manpage, -i + if @md.opt.act[:manpage][:set]==:on #% --manpage, -i ft << @md.fn[:manpage] end - if @md.opt.act[:hash_digests][:set]==:on #% --hash-digests, -N digest tree + if @md.opt.act[:hash_digests][:set]==:on #% --hash-digests, -N digest tree ft << @md.fn[:digest] end - if @md.opt.act[:odt][:set]==:on #% --odt, -o opendocument + if @md.opt.act[:odt][:set]==:on #% --odt, -o opendocument ft << @md.fn[:odf] end - if @md.opt.act[:pdf][:set]==:on #% --pdf-l --pdf, -p latex/ texpdf + if @md.opt.act[:pdf][:set]==:on #% --pdf-l --pdf, -p latex/ texpdf ft << @md.fn[:pdf_l] << @md.fn[:pdf_p] end if @md.opt.act[:share_source][:set]==:on ft << @md.fns end - if @md.opt.act[:sisupod][:set]==:on #% --sisupod, -S make sisupod + if @md.opt.act[:sisupod][:set]==:on #% --sisupod, -S make sisupod ft << @md.fn[:sisupod] end - if @md.opt.act[:xml_sax][:set]==:on #% --xml-sax, -x xml sax type + if @md.opt.act[:xml_sax][:set]==:on #% --xml-sax, -x xml sax type ft << @md.fn[:sax] end - if @md.opt.act[:xml_dom][:set]==:on #% --xml-dom, -X xml dom type + if @md.opt.act[:xml_dom][:set]==:on #% --xml-dom, -X xml dom type ft << @md.fn[:dom] end if @md.opt.act[:xml_scaffold_structure_sisu][:set]==:on #% --xml-scaffold --xml-scaffold-sisu @@ -3033,46 +3033,46 @@ WOK end @fnb=@md.fnb else # still needed where/when param is not parsed - if @opt.act[:html][:set]==:on #% --html, -h -H + if @opt.act[:html][:set]==:on #% --html, -h -H ft << '.html' << '.html.??' end - if @opt.act[:concordance][:set]==:on #% --concordance, -w + if @opt.act[:concordance][:set]==:on #% --concordance, -w ft << 'concordance.html' << '??.concordance.html' << 'concordance.??.html' end - if @opt.act[:manifest][:set]==:on #% --manifest, -y + if @opt.act[:manifest][:set]==:on #% --manifest, -y ft << 'sisu_manifest.html' << '??.sisu_manifest.html' << 'sisu_manifest.??.html' end - if @opt.act[:txt][:set]==:on #% --txt, -t -a + if @opt.act[:txt][:set]==:on #% --txt, -t -a ft << 'plain.txt' << '??.plain.txt' << 'plain.??.txt' end - if @opt.act[:xhtml][:set]==:on #% --xhtml, -b xhtml + if @opt.act[:xhtml][:set]==:on #% --xhtml, -b xhtml ft << 'scroll.xhtml' << '??.scroll.xhtml' << 'scroll.??.xhtml' end - if @opt.act[:epub][:set]==:on #% --epub, -e + if @opt.act[:epub][:set]==:on #% --epub, -e ft << @fnb << '.epub' end - if @opt.act[:manpage][:set]==:on #% --manpage, -i + if @opt.act[:manpage][:set]==:on #% --manpage, -i ft << '.1' << '??.man.1' << 'man.??.1' end - if @opt.act[:hash_digests][:set]==:on #% --hash-digests, -N digest tree + if @opt.act[:hash_digests][:set]==:on #% --hash-digests, -N digest tree ft << 'digest.txt' << '??.digest.txt' << 'digest.??.txt' end - if @opt.act[:odt][:set]==:on #% --odt, -o opendocument + if @opt.act[:odt][:set]==:on #% --odt, -o opendocument ft << 'opendocument.odt' << '??.opendocument.odt' << 'opendocument.??.odt' end - if @opt.act[:pdf][:set]==:on #% --pdf-l --pdf, -p latex/ texpdf + if @opt.act[:pdf][:set]==:on #% --pdf-l --pdf, -p latex/ texpdf ft << 'landscape.pdf' << 'portrait.pdf' << '.pdf' end if @opt.act[:share_source][:set]==:on ft << '.sst' << '.ssi' << '.ssm' end - if @opt.act[:sisupod][:set]==:on #% --sisupod, -S make sisupod + if @opt.act[:sisupod][:set]==:on #% --sisupod, -S make sisupod ft << '.zip' end - if @opt.act[:xml_sax][:set]==:on #% --xml-sax, -x xml sax type + if @opt.act[:xml_sax][:set]==:on #% --xml-sax, -x xml sax type ft << 'sax.xml' << '??.sax.xml' << 'sax.??.xml' end - if @opt.act[:xml_dom][:set]==:on #% --xml-dom, -X xml dom type + if @opt.act[:xml_dom][:set]==:on #% --xml-dom, -X xml dom type ft << 'dom.xml' << '??.dom.xml' << 'dom.??.xml' end if @opt.act[:xml_scaffold_structure_sisu][:set]==:on #% --xml-scaffold --xml-scaffold-sisu @@ -3139,16 +3139,16 @@ WOK def remove_output if @opt.act[:maintenance][:set] == :on m=InfoFile.new(@opt.fnc) - tell=SiSU_Screen::Ansi.new(@opt.cmd,@opt.fns, 'remove maintenance files from: ' + @env.processing_path.dal) + tell=SiSU_Screen::Ansi.new(@opt.cmd,@opt.fns, 'remove maintenance files from: ' + @env.processing_path.ao) tell.warn unless @opt.cmd =~/q/ - deletion(m.marshal.dal_content) - deletion(m.marshal.dal_idx_sst_rel_html_seg) - deletion(m.dal_idx_sst_rel) - deletion(m.dal_idx_html) - deletion(m.dal_idx_xhtml) - deletion(m.dal_metadata) - deletion(m.dal_map_nametags) - deletion(m.dal_map_ocn_htmlseg) + deletion(m.marshal.ao_content) + deletion(m.marshal.ao_idx_sst_rel_html_seg) + deletion(m.ao_idx_sst_rel) + deletion(m.ao_idx_html) + deletion(m.ao_idx_xhtml) + deletion(m.ao_metadata) + deletion(m.ao_map_nametags) + deletion(m.ao_map_ocn_htmlseg) deletion(m.html_tune) end md=SiSU_Param::Parameters.new(@opt).get @@ -3378,7 +3378,7 @@ WOK end def rsync def document - f=(@opt.act[:dal][:set]==:on) \ + f=(@opt.act[:ao][:set]==:on) \ ? SiSU_Env::FileOp.new(@md) : nil if f @@ -3704,29 +3704,29 @@ WOK FileUtils::mkdir_p(path) unless FileTest.directory?(path) end def marshal - def dal_content - "#{@env.processing_path.dal}/#{@fns}.content.rbm" + def ao_content + "#{@env.processing_path.ao}/#{@fns}.content.rbm" end - def dal_idx_sst_rel_html_seg - "#{@env.processing_path.dal}/#{@fns}.idx_sst.rbm" + def ao_idx_sst_rel_html_seg + "#{@env.processing_path.ao}/#{@fns}.idx_sst.rbm" end - def dal_idx_sst_rel #used by tex & odf - "#{@env.processing_path.dal}/#{@fns}.idx_raw.rbm" + def ao_idx_sst_rel #used by tex & odf + "#{@env.processing_path.ao}/#{@fns}.idx_raw.rbm" end - def dal_idx_html - "#{@env.processing_path.dal}/#{@fns}.idx_html.rbm" + def ao_idx_html + "#{@env.processing_path.ao}/#{@fns}.idx_html.rbm" end - def dal_idx_xhtml - "#{@env.processing_path.dal}/#{@fns}.idx_xhtml.rbm" + def ao_idx_xhtml + "#{@env.processing_path.ao}/#{@fns}.idx_xhtml.rbm" end - def dal_metadata - "#{@env.processing_path.dal}/#{@fns}.metadata.rbm" + def ao_metadata + "#{@env.processing_path.ao}/#{@fns}.metadata.rbm" end - def dal_map_nametags - "#{@env.processing_path.dal}/#{@fns}.map_name_tags.rbm" + def ao_map_nametags + "#{@env.processing_path.ao}/#{@fns}.map_name_tags.rbm" end - def dal_map_ocn_htmlseg - "#{@env.processing_path.dal}/#{@fns}.map_ocn_htmlseg.rbm" + def ao_map_ocn_htmlseg + "#{@env.processing_path.ao}/#{@fns}.map_ocn_htmlseg.rbm" end def html_tune "#{@env.processing_path.tune}/#{@fns}.marshal_tune" @@ -3741,8 +3741,8 @@ WOK end def mkdir #check moved from FileOp, existing mkdir def processing - def dal - FileUtils::mkdir_p(@env.processing_path.dal) unless FileTest.directory?(@env.processing_path.dal) + def ao + FileUtils::mkdir_p(@env.processing_path.ao) unless FileTest.directory?(@env.processing_path.ao) end def tune FileUtils::mkdir_p(@env.processing_path.tune) unless FileTest.directory?(@env.processing_path.tune) @@ -4255,7 +4255,7 @@ WOK FileUtils::mkdir_p(output_path.base.dir) unless FileTest.directory?(output_path.base.dir) FileUtils::mkdir_p("#{output_path.base.dir}/#{@md.fnb}") unless FileTest.directory?("#{output_path.base.dir}/#{@md.fnb}") FileUtils::mkdir_p("#{output_path.base.dir}/#{@env.path.style}") unless FileTest.directory?("#{output_path.base.dir}/#{@env.path.style}") - FileUtils::mkdir_p(@env.processing_path.dal) unless FileTest.directory?(@env.processing_path.dal) + FileUtils::mkdir_p(@env.processing_path.ao) unless FileTest.directory?(@env.processing_path.ao) FileUtils::mkdir_p(@env.processing_path.tune) unless FileTest.directory?(@env.processing_path.tune) end def path_rel_links @@ -6130,17 +6130,17 @@ WOK File.new('/tmp/errorlog.sisu','w+') end def file_txt - File.new("#{@env.processing_path.dal}/#{@fns}.txt",'w+') + File.new("#{@env.processing_path.ao}/#{@fns}.txt",'w+') end def file_debug - File.new("#{@env.processing_path.dal}/#{@fns}.debug.txt",'w+') + File.new("#{@env.processing_path.ao}/#{@fns}.debug.txt",'w+') end def metaverse def file_meta - File.new("#{@env.processing_path.dal}/#{@fns}.meta",'w+') + File.new("#{@env.processing_path.ao}/#{@fns}.meta",'w+') end def file_meta_idx_html - File.new("#{@env.processing_path.dal}/#{@fns}.idx.html",'w+') + File.new("#{@env.processing_path.ao}/#{@fns}.idx.html",'w+') end self end @@ -6148,7 +6148,7 @@ WOK File.new("#{Dir.pwd}/#{@fns}.fn",'w+') end def meta - "#{@env.processing_path.dal}/#{@fns}.meta" + "#{@env.processing_path.ao}/#{@fns}.meta" end def file_semantic filename_semantic="./semantic.yaml" diff --git a/lib/sisu/v5/texinfo.rb b/lib/sisu/v5/texinfo.rb index 623cee2d..2e92268a 100644 --- a/lib/sisu/v5/texinfo.rb +++ b/lib/sisu/v5/texinfo.rb @@ -116,7 +116,7 @@ module SiSU_TexInfo : SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'TexInfo',tool).green_title_hi @md=SiSU_Param::Parameters.new(@opt).get directories - @marshalfile=SiSU_Env::InfoFile.new(@opt.fns).marshal.dal_content + @marshalfile=SiSU_Env::InfoFile.new(@opt.fns).marshal.ao_content if FileTest.file?(@marshalfile)==true File.open(@marshalfile) { |f| @@tuned_file=Marshal.load(f)} #tell.meta_verse_skipped if @opt.cmd =~/[vVM]/ diff --git a/lib/sisu/v5/texpdf.rb b/lib/sisu/v5/texpdf.rb index df089d31..bf72a1a6 100644 --- a/lib/sisu/v5/texpdf.rb +++ b/lib/sisu/v5/texpdf.rb @@ -126,9 +126,9 @@ module SiSU_TeX $flag=@md.opt.cmd #introduced to pass 0 for no object citation numbers... to texpdf_format directories #% needed needs to be reprogrammed !!! - dal_array=SiSU_AO::Source.new(@opt).get # dal file drawn here + ao_array=SiSU_AO::Source.new(@opt).get # ao file drawn here SiSU_TeX::Source::LaTeXcreate.new(@particulars).songsheet - dal_array='' + ao_array='' pwd=Dir.pwd SiSU_TeX::Source::LaTeXtoPdf.new(@md,@particulars.env).latexrun_selective Dir.chdir(pwd) @@ -339,7 +339,7 @@ module SiSU_TeX @particulars=particulars @md=@particulars.md @env=SiSU_Env::InfoEnv.new(@md.fns) #@env=@particulars.env - @data=@particulars.dal_array # dal file drawn here + @data=@particulars.ao_array # ao file drawn here @st={ tex: {} } @tex_ml=SiSU_TeX_Pdf::UseTeX.new(@md) @vz=SiSU_Viz::Defaults.new diff --git a/lib/sisu/v5/texpdf_format.rb b/lib/sisu/v5/texpdf_format.rb index b20105af..556de8a6 100644 --- a/lib/sisu/v5/texpdf_format.rb +++ b/lib/sisu/v5/texpdf_format.rb @@ -168,7 +168,7 @@ module SiSU_TeX_Pdf end rows_new << r end - table=rows_new.join #@dob[:dal].obj=rows.join + table=rows_new.join #@dob[:ao].obj=rows.join ocn_display(@dob) + start_table + table + " #{end_table}\n\\end{tiny}" else '' end @@ -213,7 +213,7 @@ module SiSU_TeX_Pdf end rows_new << r end - table=rows_new.join #@dob[:dal].obj=rows.join + table=rows_new.join #@dob[:ao].obj=rows.join ocn_display(@dob) + start_table + table + " #{end_table}\n\\end{tiny}" else '' end diff --git a/lib/sisu/v5/urls.rb b/lib/sisu/v5/urls.rb index a7b53985..9b2f1937 100644 --- a/lib/sisu/v5/urls.rb +++ b/lib/sisu/v5/urls.rb @@ -105,7 +105,7 @@ module SiSU_Urls 'h --html (HTML scroll)'=>@fn[:doc], 'I --texinfo (Info file)'=>'info', 'i --manpage (manpage)'=>'manpage', - 'm --dal (Document Abstraction)'=>'dal', + 'm --ao (Document Abstraction)'=>'ao', 'N --hash-digests (Digests md5/sha256)'=>@fn[:digest], 'o --odt (ODF:ODT - Open Document)'=>@fn[:odf], 'p --pdf (PDF landscape)'=>@fn[:pdf_l], @@ -249,7 +249,7 @@ module SiSU_Urls if x =~/^m/ \ and @opt.cmd=~/m/ \ and x=~/^[#{opt.cmd}]/ - SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"-#{x}","#{@prog.text_editor} #{@env.processing_path.dal}/#{@opt.fns}.meta").maintenance + SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"-#{x}","#{@prog.text_editor} #{@env.processing_path.ao}/#{@opt.fns}.meta").maintenance end if x=~/^([hw])/ \ and @opt.cmd=~/[hw]/ \ diff --git a/lib/sisu/v5/wikispeak.rb b/lib/sisu/v5/wikispeak.rb index eab2336d..65e87c13 100644 --- a/lib/sisu/v5/wikispeak.rb +++ b/lib/sisu/v5/wikispeak.rb @@ -90,8 +90,8 @@ module SiSU_Wikispeak || @opt.act[:maintenance][:set]==:on) SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],@opt.fns,"#{@env.path.output_tell}/#{@md.fnb}/#{@md.fn[:wiki]}").flow end - @dal_array=SiSU_AO::Source.new(@opt).get # dal file drawn here - SiSU_Wikispeak::Source::Scroll.new(@dal_array,@md).songsheet + @ao_array=SiSU_AO::Source.new(@opt).get # ao file drawn here + SiSU_Wikispeak::Source::Scroll.new(@ao_array,@md).songsheet rescue SiSU_Errors::Rescued.new($!,$@,@opt.cmd,@opt.fns).location do __LINE__.to_s + ':' + __FILE__ diff --git a/lib/sisu/v5/xhtml.rb b/lib/sisu/v5/xhtml.rb index 03ba0134..995316b1 100644 --- a/lib/sisu/v5/xhtml.rb +++ b/lib/sisu/v5/xhtml.rb @@ -82,7 +82,7 @@ module SiSU_XHTML end def read begin - @env,@md,@dal_array=@particulars.env,@particulars.md,@particulars.dal_array + @env,@md,@ao_array=@particulars.env,@particulars.md,@particulars.ao_array unless @opt.act[:quiet][:set]==:on tool=if (@opt.act[:verbose_plus][:set]==:on \ || @opt.act[:maintenance][:set]==:on) @@ -113,7 +113,7 @@ module SiSU_XHTML private class Songsheet def initialize(particulars) - @env,@md,@dal_array,@particulars=particulars.env,particulars.md,particulars.dal_array,particulars + @env,@md,@ao_array,@particulars=particulars.env,particulars.md,particulars.ao_array,particulars @file=SiSU_Env::FileOp.new(@md) end def song @@ -140,7 +140,7 @@ module SiSU_XHTML require_relative 'css' # css.rb @@xml={ body: [], sisu: [], open: [], close: [], head: [] } def initialize(particulars) - @env,@md,@dal_array=particulars.env,particulars.md,particulars.dal_array + @env,@md,@ao_array=particulars.env,particulars.md,particulars.ao_array @vz=SiSU_Viz::Defaults.new @tab="\t" @trans=SiSU_XML_Munge::Trans.new(@md) @@ -148,7 +148,7 @@ module SiSU_XHTML end def songsheet pre - @data=markup(@dal_array) + @data=markup(@ao_array) post publish end diff --git a/lib/sisu/v5/xml_dom.rb b/lib/sisu/v5/xml_dom.rb index 36a0dae1..6a2d7505 100644 --- a/lib/sisu/v5/xml_dom.rb +++ b/lib/sisu/v5/xml_dom.rb @@ -83,7 +83,7 @@ module SiSU_XML_DOM end def read begin - @env,@md,@dal_array=@particulars.env,@particulars.md,@particulars.dal_array + @env,@md,@ao_array=@particulars.env,@particulars.md,@particulars.ao_array unless @opt.act[:quiet][:set]==:on tool=if (@opt.act[:verbose_plus][:set]==:on \ || @opt.act[:maintenance][:set]==:on) @@ -114,7 +114,7 @@ module SiSU_XML_DOM private class Songsheet def initialize(particulars) - @env,@md,@dal_array,@particulars=particulars.env,particulars.md,particulars.dal_array,particulars + @env,@md,@ao_array,@particulars=particulars.env,particulars.md,particulars.ao_array,particulars @file=SiSU_Env::FileOp.new(@md) end def songsheet @@ -140,14 +140,14 @@ module SiSU_XML_DOM require_relative 'shared_xhtml' # decide use, whether xml rather than xhtml @@xml={ body: [], open: [], close: [], head: [], sc: [] } def initialize(particulars) - @env,@md,@dal_array=particulars.env,particulars.md,particulars.dal_array + @env,@md,@ao_array=particulars.env,particulars.md,particulars.ao_array @vz=SiSU_Viz::Defaults.new @trans=SiSU_XML_Munge::Trans.new(@md) @sys=SiSU_Env::SystemCall.new end def songsheet pre - @data=markup(@dal_array) + @data=markup(@ao_array) post publish end diff --git a/lib/sisu/v5/xml_sax.rb b/lib/sisu/v5/xml_sax.rb index f9741ec1..a53abdd6 100644 --- a/lib/sisu/v5/xml_sax.rb +++ b/lib/sisu/v5/xml_sax.rb @@ -82,7 +82,7 @@ module SiSU_XML_SAX end def read begin - @env,@md,@dal_array=@particulars.env,@particulars.md,@particulars.dal_array + @env,@md,@ao_array=@particulars.env,@particulars.md,@particulars.ao_array unless @opt.act[:quiet][:set]==:on tool=if (@opt.act[:verbose_plus][:set]==:on \ || @opt.act[:maintenance][:set]==:on) @@ -114,7 +114,7 @@ module SiSU_XML_SAX private class Songsheet def initialize(particulars) - @env,@md,@dal_array,@particulars=particulars.env,particulars.md,particulars.dal_array,particulars + @env,@md,@ao_array,@particulars=particulars.env,particulars.md,particulars.ao_array,particulars @file=SiSU_Env::FileOp.new(@md) end def song @@ -141,14 +141,14 @@ module SiSU_XML_SAX require_relative 'shared_xhtml' # decide use, whether xml rather than xhtml @@xml={ body: [], open: [], close: [], head: [] } def initialize(particulars) - @env,@md,@dal_array=particulars.env,particulars.md,particulars.dal_array + @env,@md,@ao_array=particulars.env,particulars.md,particulars.ao_array @vz=SiSU_Viz::Defaults.new @trans=SiSU_XML_Munge::Trans.new(@md) @sys=SiSU_Env::SystemCall.new end def songsheet pre - @data=markup(@dal_array) + @data=markup(@ao_array) post publish end diff --git a/lib/sisu/v5/xml_scaffold_structure_collapsed.rb b/lib/sisu/v5/xml_scaffold_structure_collapsed.rb index 8f14ea54..9a095f4b 100644 --- a/lib/sisu/v5/xml_scaffold_structure_collapsed.rb +++ b/lib/sisu/v5/xml_scaffold_structure_collapsed.rb @@ -73,8 +73,8 @@ module SiSU_XML_Scaffold_Structure_Collapse end def read begin - @md,@dal_array=@particulars.md,@particulars.dal_array - SiSU_XML_Scaffold_Structure_Collapse::Source::Scroll.new(@dal_array,@md).songsheet + @md,@ao_array=@particulars.md,@particulars.ao_array + SiSU_XML_Scaffold_Structure_Collapse::Source::Scroll.new(@ao_array,@md).songsheet rescue SiSU_Errors::Rescued.new($!,$@,@opt.cmd,@opt.fns).location do __LINE__.to_s + ':' + __FILE__ diff --git a/lib/sisu/v5/xml_scaffold_structure_sisu.rb b/lib/sisu/v5/xml_scaffold_structure_sisu.rb index 12e1088a..2848187f 100644 --- a/lib/sisu/v5/xml_scaffold_structure_sisu.rb +++ b/lib/sisu/v5/xml_scaffold_structure_sisu.rb @@ -73,8 +73,8 @@ module SiSU_XML_Scaffold_Structure_Sisu end def read begin - @md,@dal_array=@particulars.md,@particulars.dal_array - SiSU_XML_Scaffold_Structure_Sisu::Source::Scroll.new(@dal_array,@md).songsheet + @md,@ao_array=@particulars.md,@particulars.ao_array + SiSU_XML_Scaffold_Structure_Sisu::Source::Scroll.new(@ao_array,@md).songsheet rescue SiSU_Errors::Rescued.new($!,$@,@opt.cmd,@opt.fns).location do __LINE__.to_s + ':' + __FILE__ -- cgit v1.2.3 From 6c3930e1c1faeee50dcde7991b7e8d63a746805c Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Tue, 3 Dec 2013 00:10:52 -0500 Subject: v5: some file renaming related to: shared files & epub, odf:odt, plaintext --- lib/sisu/v5/concordance.rb | 4 +- lib/sisu/v5/db_import.rb | 2 +- lib/sisu/v5/dbi.rb | 2 +- lib/sisu/v5/dbi_discrete.rb | 2 +- lib/sisu/v5/epub.rb | 769 ----------- lib/sisu/v5/epub_concordance.rb | 324 ----- lib/sisu/v5/epub_format.rb | 2236 -------------------------------- lib/sisu/v5/epub_segments.rb | 543 -------- lib/sisu/v5/epub_tune.rb | 333 ----- lib/sisu/v5/html_format.rb | 2 +- lib/sisu/v5/html_lite_shared.rb | 325 +++++ lib/sisu/v5/html_scroll.rb | 2 +- lib/sisu/v5/html_segments.rb | 2 +- lib/sisu/v5/html_shared.rb | 68 + lib/sisu/v5/hub.rb | 18 +- lib/sisu/v5/manpage.rb | 4 +- lib/sisu/v5/odf.rb | 820 ------------ lib/sisu/v5/odf_format.rb | 671 ---------- lib/sisu/v5/plaintext.rb | 576 -------- lib/sisu/v5/plaintext_format.rb | 104 -- lib/sisu/v5/share_src.rb | 102 -- lib/sisu/v5/share_src_kdissert.rb | 90 -- lib/sisu/v5/shared_html.rb | 68 - lib/sisu/v5/shared_html_lite.rb | 325 ----- lib/sisu/v5/shared_sisupod_source.rb | 312 ----- lib/sisu/v5/shared_txt.rb | 236 ---- lib/sisu/v5/shared_xhtml.rb | 68 - lib/sisu/v5/shared_xml.rb | 721 ---------- lib/sisu/v5/sisupod_make.rb | 167 --- lib/sisu/v5/sitemaps.rb | 2 +- lib/sisu/v5/src_kdissert_share.rb | 90 ++ lib/sisu/v5/src_share.rb | 102 ++ lib/sisu/v5/src_shared.rb | 312 +++++ lib/sisu/v5/src_sisupod_make.rb | 167 +++ lib/sisu/v5/sst_to_s_xml_sax.rb | 4 +- lib/sisu/v5/txt_plain.rb | 576 ++++++++ lib/sisu/v5/txt_shared.rb | 242 ++++ lib/sisu/v5/wikispeak.rb | 4 +- lib/sisu/v5/xhtml.rb | 6 +- lib/sisu/v5/xhtml_epub2.rb | 769 +++++++++++ lib/sisu/v5/xhtml_epub2_concordance.rb | 324 +++++ lib/sisu/v5/xhtml_epub2_format.rb | 2236 ++++++++++++++++++++++++++++++++ lib/sisu/v5/xhtml_epub2_segments.rb | 543 ++++++++ lib/sisu/v5/xhtml_epub2_tune.rb | 333 +++++ lib/sisu/v5/xhtml_shared.rb | 68 + lib/sisu/v5/xml_dom.rb | 6 +- lib/sisu/v5/xml_fictionbook.rb | 305 ----- lib/sisu/v5/xml_odf_odt.rb | 820 ++++++++++++ lib/sisu/v5/xml_odf_odt_format.rb | 671 ++++++++++ lib/sisu/v5/xml_sax.rb | 6 +- lib/sisu/v5/xml_shared.rb | 751 +++++++++++ 51 files changed, 8430 insertions(+), 8803 deletions(-) delete mode 100644 lib/sisu/v5/epub.rb delete mode 100644 lib/sisu/v5/epub_concordance.rb delete mode 100644 lib/sisu/v5/epub_format.rb delete mode 100644 lib/sisu/v5/epub_segments.rb delete mode 100644 lib/sisu/v5/epub_tune.rb create mode 100644 lib/sisu/v5/html_lite_shared.rb create mode 100644 lib/sisu/v5/html_shared.rb delete mode 100644 lib/sisu/v5/odf.rb delete mode 100644 lib/sisu/v5/odf_format.rb delete mode 100644 lib/sisu/v5/plaintext.rb delete mode 100644 lib/sisu/v5/plaintext_format.rb delete mode 100644 lib/sisu/v5/share_src.rb delete mode 100644 lib/sisu/v5/share_src_kdissert.rb delete mode 100644 lib/sisu/v5/shared_html.rb delete mode 100644 lib/sisu/v5/shared_html_lite.rb delete mode 100644 lib/sisu/v5/shared_sisupod_source.rb delete mode 100644 lib/sisu/v5/shared_txt.rb delete mode 100644 lib/sisu/v5/shared_xhtml.rb delete mode 100644 lib/sisu/v5/shared_xml.rb delete mode 100644 lib/sisu/v5/sisupod_make.rb create mode 100644 lib/sisu/v5/src_kdissert_share.rb create mode 100644 lib/sisu/v5/src_share.rb create mode 100644 lib/sisu/v5/src_shared.rb create mode 100644 lib/sisu/v5/src_sisupod_make.rb create mode 100644 lib/sisu/v5/txt_plain.rb create mode 100644 lib/sisu/v5/txt_shared.rb create mode 100644 lib/sisu/v5/xhtml_epub2.rb create mode 100644 lib/sisu/v5/xhtml_epub2_concordance.rb create mode 100644 lib/sisu/v5/xhtml_epub2_format.rb create mode 100644 lib/sisu/v5/xhtml_epub2_segments.rb create mode 100644 lib/sisu/v5/xhtml_epub2_tune.rb create mode 100644 lib/sisu/v5/xhtml_shared.rb delete mode 100644 lib/sisu/v5/xml_fictionbook.rb create mode 100644 lib/sisu/v5/xml_odf_odt.rb create mode 100644 lib/sisu/v5/xml_odf_odt_format.rb create mode 100644 lib/sisu/v5/xml_shared.rb (limited to 'lib') diff --git a/lib/sisu/v5/concordance.rb b/lib/sisu/v5/concordance.rb index 8c675e36..3bb313d4 100644 --- a/lib/sisu/v5/concordance.rb +++ b/lib/sisu/v5/concordance.rb @@ -113,8 +113,8 @@ module SiSU_Concordance private class DocTitle include SiSU_Viz - #revisit, both requires (html & shared_xml) needed for stand alone operation (sisu -w [filename]) - require_relative 'shared_xml' # shared_xml.rb + #revisit, both requires (html & xml_shared) needed for stand alone operation (sisu -w [filename]) + require_relative 'xml_shared' # xml_shared.rb require_relative 'html' # html.rb def initialize(particulars) @particulars,@md=particulars,particulars.md diff --git a/lib/sisu/v5/db_import.rb b/lib/sisu/v5/db_import.rb index 8a8cc13d..dc73bbf5 100644 --- a/lib/sisu/v5/db_import.rb +++ b/lib/sisu/v5/db_import.rb @@ -64,7 +64,7 @@ module SiSU_DbImport require_relative 'db_columns' # db_columns.rb require_relative 'db_load_tuple' # db_load_tuple.rb require_relative 'db_sqltxt' # db_sqltxt.rb - require_relative 'shared_html_lite' # shared_html_lite.rb + require_relative 'html_lite_shared' # html_lite_shared.rb require 'sqlite3' class Import < SiSU_DbText::Prepare include SiSU_Param diff --git a/lib/sisu/v5/dbi.rb b/lib/sisu/v5/dbi.rb index e59a09b7..6a40d3ce 100644 --- a/lib/sisu/v5/dbi.rb +++ b/lib/sisu/v5/dbi.rb @@ -66,7 +66,7 @@ module SiSU_DBI include SiSU_Param require_relative 'db_dbi' # db_dbi.rb include SiSU_DbDBI - require_relative 'shared_html_lite' # shared_html_lite.rb + require_relative 'html_lite_shared' # html_lite_shared.rb include SiSU_FormatShared class SQL def initialize(opt) diff --git a/lib/sisu/v5/dbi_discrete.rb b/lib/sisu/v5/dbi_discrete.rb index 957009b1..95fb9ce3 100644 --- a/lib/sisu/v5/dbi_discrete.rb +++ b/lib/sisu/v5/dbi_discrete.rb @@ -66,7 +66,7 @@ module SiSU_DBI_Discrete #% database building include SiSU_Param require_relative 'db_dbi' # db_dbi.rb include SiSU_DbDBI - require_relative 'shared_html_lite' # shared_html_lite.rb + require_relative 'html_lite_shared' # html_lite_shared.rb include SiSU_FormatShared require 'fileutils' include FileUtils::Verbose diff --git a/lib/sisu/v5/epub.rb b/lib/sisu/v5/epub.rb deleted file mode 100644 index 5f4957aa..00000000 --- a/lib/sisu/v5/epub.rb +++ /dev/null @@ -1,769 +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: epub generation, processing - -=end -module SiSU_EPUB - require 'pstore' - require_relative 'particulars' # particulars.rb - include SiSU_Particulars - require_relative 'defaults' # defaults.rb - include SiSU_Viz - require_relative 'xhtml_table' # xhtml_table.rb - require_relative 'epub_format' # epub_format.rb - include SiSU_EPUB_Format - require_relative 'epub_segments' # epub_segments.rb - include SiSU_EPUB_Seg - require_relative 'epub_tune' # epub_tune.rb - include SiSU_EPUB_Tune - require_relative 'epub_concordance' # epub_concordance.rb - class Source - def initialize(opt) - @opt=opt - @particulars=SiSU_Particulars::CombinedSingleton.instance.get_all(opt) - end - def read - songsheet - end - def songsheet - begin - @md=@particulars.md - @fnb=@md.fnb - @env=@particulars.env - 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.epub_viewer} #{@md.file.output_path.epub.dir}/#{@md.file.base_filename.epub}" - : "[#{@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],'EPUB',tool).green_hi_blue - : SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'EPUB',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,"#{@md.file.output_path.epub.dir}/#{@md.file.base_filename.epub}").flow - end - end - @env.processing_path.epub_bld #(@md) - @env.processing_path.epub_cp_images(@md) - data=nil - SiSU_Env::FileOp.new(@md).mkdir.output.epub - @tuned_file_array=SiSU_EPUB::Source::XHTML_Environment.new(@particulars).tuned_file_instructions - data=@tuned_file_array - toc=SiSU_EPUB::Source::Toc.new(@md,data).songsheet - data=@tuned_file_array - SiSU_EPUB::Source::ScrollHeadAndSegToc.new(@md,toc).in_common #watch - SiSU_EPUB::Source::Seg.new(@md,data).songsheet - SiSU_EPUB::Source::Output.new(@md).songsheet - rescue - SiSU_Errors::Rescued.new($!,$@,@opt.cmd,@opt.fns).location do - __LINE__.to_s + ':' + __FILE__ - end - ensure - unless (@opt.act[:verbose_plus][:set]==:on \ - || @opt.act[:maintenance][:set]==:on) - texfiles=Dir["#{@env.processing_path.tune}/#{@opt.fns}*"] - texfiles.each do |f| - if FileTest.file?(f) - File.unlink(f) - end - end - end - SiSU_Env::Clear.new(@opt.cmd,@opt.fns).param_instantiate - @@flag,@@scr,@@seg,@@seg_endnotes,@@seg_subtoc,@@seg_ad={},{},{},{},{},{} - @@seg_total,@@tracker,@@loop_count,@@tablehead,@@number_of_cols=0,0,0,0,0 - @@seg_name,@@seg_name_html,@@seg_subtoc_array,@@seg_endnotes_array,@@segtocband,@@tablefoot=Array.new(7){[]} - @@filename_seg,@@seg_url,@@fn,@@to_lev4,@@get_hash_to,@@get_hash_fn='','','','','','','' - @@is4=@@is3=@@is2=@@is1=@@heading1=@@heading2=@@heading3=@@heading4=0 - end - end - private - class XHTML_Environment - def initialize(particulars) - @particulars=particulars - @md,@env=particulars.md,particulars.env - @vz=SiSU_Viz::Defaults.new - @env,@css=particulars.env,SiSU_Style::CSS.new - end - def directories - SiSU_Env::FileOp.new(@md).mkdir.output.epub - end - def tuned_file_instructions - @tell=SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set]) - directories - ao_array=@particulars.ao_array # ao file drawn here - @tuned_file_array=SiSU_EPUB_Tune::Tune.new(ao_array,@md).songsheet - @tuned_file_array - end - end - class Endnotes - include SiSU_EPUB_Format - def initialize(md,data) - @md,@data=md,data - end - def scroll - @scr_endnotes=[] - @data.each do |dob| - pg=dob.dup - unless pg.is ==:code - if pg.obj =~/(?:#{Mx[:en_a_o]}|#{Mx[:en_b_o]})[\d*+]+ / - endnote_array=[] - if pg.obj=~/#{Mx[:en_a_o]}[\d*+].+?#{Mx[:en_a_c]}/m - endnote_array = pg.obj.scan(/#{Mx[:en_a_o]}[\d*+]+(.+?)#{Mx[:en_a_c]}/m) - end - if pg.obj=~/#{Mx[:en_b_o]}[\d*]+\s.+?#{Mx[:en_b_c]}/m - endnote_array = pg.obj.scan(/#{Mx[:en_b_o]}[\d*]+(.+?)#{Mx[:en_b_c]}/m) - end - if pg.obj=~/#{Mx[:en_b_o]}[\d+]+\s.+?#{Mx[:en_b_c]}/m - endnote_array = pg.obj.scan(/#{Mx[:en_b_o]}[\d+]+(.+?)#{Mx[:en_b_c]}/m) - end - endnote_array.flatten.each do |note| - txt_obj={ txt: note } - format_scroll=SiSU_EPUB_Format::FormatScroll.new(@md,txt_obj) - @scr_endnotes << format_scroll.endnote_body - end - end - end - end - @scr_endnotes - end - end - class Toc - @@toc={ seg: [], seg_mini: [], scr: [], ncx: [], opf: [] } - @@seg_url='' - @@firstseg=nil - def initialize(md=nil,data='') - @md,@data=md,data - @vz=SiSU_Viz::Defaults.new - @epub=SiSU_EPUB_Format::HeadInformation.new(@md) - @tell=SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set]) if @md - @make=SiSU_Env::ProcessingSettings.new(@md) - end - def songsheet #extracts toc for scroll & seg - if (@md.opt.act[:verbose][:set]==:on \ - || @md.opt.act[:verbose_plus][:set]==:on \ - || @md.opt.act[:maintenance][:set]==:on) - SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set],'Toc').txt_grey - end - toc=nil - @@firstseg=nil - @@toc={ seg: [], seg_mini: [], scr: [], ncx: [], opf: [] } - md_opf_a_content,md_opf_a_spine,md_opf_a_guide=[],[],[] - @nav_no=0 - @s_a_no,@s_b_no,@s_c_no,@lv5_no,@lv6_no=0,0,0,0,0 - @@toc[:ncx] << @epub.toc_ncx.open #epub ncx navmap - @@toc[:ncx] << @epub.toc_ncx.head_open << @epub.toc_ncx.head << @epub.toc_ncx.head_close - @@toc[:ncx] << @epub.toc_ncx.doc_title << @epub.toc_ncx.doc_author - @@toc[:ncx] << @epub.toc_ncx.navmap_open - @@toc[:opf] << @epub.metadata_opf.package_open - @@toc[:opf] << @epub.metadata_opf.metadata - @@toc[:opf] << @epub.metadata_opf.manifest_open - @@toc[:seg] << %{
\n
} - @@toc[:scr] << %{
\n
} - if defined? @md.make.cover_image \ - and @md.make.cover_image.is_a?(Hash) \ - and @md.make.cover_image[:cover] =~/\S+/ - md_opf_a_content << @epub.metadata_opf.manifest_cover_image_information(@md) - md_opf_a_spine << @epub.metadata_opf.spine_cover_image - md_opf_a_guide << @epub.metadata_opf.guide_cover_image - end - md_opf_a_content << @epub.metadata_opf.manifest_content_sisu_toc - if @make.build.toc? - md_opf_a_spine << @epub.metadata_opf.spine_sisu_toc - md_opf_a_guide << @epub.metadata_opf.guide_sisu_toc - end - @ncxo=[nil,false,false,false,false,false,false] - @dob_toc2,@dob_toc3=nil,nil - @ncx_cls=[] - @level_a_first_occurrence=true - @data.each do |dob| - if dob.is==:heading \ - || dob.is==:heading_insert - dob_toc=dob.dup - toc=case dob_toc.ln - when 1 - @s_a_no +=1 - lv_name='section_a' + @s_a_no.to_s - @nav_no+=1 - @nav_no2=@nav_no - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[6] - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[5] - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[4] - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[3] - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[2] - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[1] - @ncxo[1],@ncxo[2],@ncxo[3],@ncxo[4],@ncxo[5],@ncxo[6]=true,false,false,false,false,false - @epub.sections(dob_toc,lv_name) - @@toc[:ncx] << @epub.toc_ncx.navpoint(dob_toc,@nav_no,lv_name) if dob_toc - if @level_a_first_occurrence \ - && @make.build.toc? - @nav_no+=1 - @@toc[:ncx] << @epub.toc_ncx.navmap_sisu_toc(@nav_no) #epub ncx navmap, toc - @level_a_first_occurrence=false - end - md_opf_a_content << @epub.metadata_opf.manifest_content(dob_toc,lv_name) - md_opf_a_spine << @epub.metadata_opf.spine(dob_toc,lv_name) - md_opf_a_guide << @epub.metadata_opf.guide(dob_toc,lv_name) - SiSU_EPUB::Source::Toc.new(@md,dob_toc).level_1 - when 2 - @s_b_no +=1 - lv_name='section_b' + @s_b_no.to_s - @nav_no+=1 - @nav_no2=@nav_no - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[6] - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[5] - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[4] - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[3] - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[2] - @ncxo[2],@ncxo[3],@ncxo[4],@ncxo[5],@ncxo[6]=true,false,false,false,false - @epub.sections(dob_toc,lv_name) - @@toc[:ncx] << @epub.toc_ncx.navpoint(dob_toc,@nav_no,lv_name) if dob_toc - md_opf_a_content << @epub.metadata_opf.manifest_content(dob_toc,lv_name) - md_opf_a_spine << @epub.metadata_opf.spine(dob_toc,lv_name) - md_opf_a_guide << @epub.metadata_opf.guide(dob_toc,lv_name) - SiSU_EPUB::Source::Toc.new(@md,dob_toc).level_2 - when 3 - @s_c_no +=1 - lv_name='section_c' + @s_c_no.to_s - @nav_no+=1 - @nav_no3=@nav_no - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[6] - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[5] - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[4] - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[3] - @ncxo[3],@ncxo[4],@ncxo[5],@ncxo[6]=true,false,false,false - @epub.sections(dob_toc,lv_name) - @@toc[:ncx] << @epub.toc_ncx.navpoint(dob_toc,@nav_no,lv_name) if dob_toc - md_opf_a_content << @epub.metadata_opf.manifest_content(dob_toc,lv_name) - md_opf_a_spine << @epub.metadata_opf.spine(dob_toc,lv_name) - md_opf_a_guide << @epub.metadata_opf.guide(dob_toc,lv_name) - SiSU_EPUB::Source::Toc.new(@md,dob_toc).level_3 - when 4 - @ncx_cls=[] - lv_name=dob_toc.name - @nav_no+=1 - @dob_name=dob.name - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[6] - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[5] - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[4] - @ncxo[4],@ncxo[5],@ncxo[6]=true,false,false - @@toc[:ncx] << @epub.toc_ncx.navpoint(dob_toc,@nav_no,lv_name) if dob_toc - md_opf_a_content << @epub.metadata_opf.manifest_content(dob_toc,lv_name) - md_opf_a_spine << @epub.metadata_opf.spine(dob_toc,lv_name) - md_opf_a_guide << @epub.metadata_opf.guide(dob_toc,lv_name) - SiSU_EPUB::Source::Toc.new(@md,dob_toc).level_4 - when 5 - @ncx_cls=[] - hashtag='#o' + dob_toc.ocn.to_s - lv_name=@dob_name - @nav_no+=1 - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[6] - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[5] - @ncxo[5],@ncxo[6]=true,false - @@toc[:ncx] << @epub.toc_ncx.navpoint(dob_toc,@nav_no,lv_name,hashtag) if dob_toc - md_opf_a_content << @epub.metadata_opf.manifest_content(dob_toc,lv_name,hashtag) - md_opf_a_spine << @epub.metadata_opf.spine(dob_toc,lv_name,hashtag) - md_opf_a_guide << @epub.metadata_opf.guide(dob_toc,lv_name,hashtag) - SiSU_EPUB::Source::Toc.new(@md,dob_toc).level_5 - when 6 - @ncx_cls=[] - hashtag='#o' + dob_toc.ocn.to_s - lv_name=@dob_name - @nav_no+=1 - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[6] - @ncxo[6]=true - @@toc[:ncx] << @epub.toc_ncx.navpoint(dob_toc,@nav_no,lv_name,hashtag) if dob_toc - md_opf_a_content << @epub.metadata_opf.manifest_content(dob_toc,lv_name,hashtag) - md_opf_a_spine << @epub.metadata_opf.spine(dob_toc,lv_name,hashtag) - md_opf_a_guide << @epub.metadata_opf.guide(dob_toc,lv_name,hashtag) - SiSU_EPUB::Source::Toc.new(@md,dob_toc).level_6 - else nil - end - toc.each do |k,d| - d.gsub!(/(?:#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]})\s*/m,' ') - end if toc - if @@firstseg.nil? \ - and dob.ln==4 \ - and dob.name =~/\S+/ - @@firstseg=dob.name - end - if toc - begin - @@toc[:seg] << toc[:seg] - @@toc[:scr] << toc[:seg] - rescue - SiSU_Errors::Rescued.new($!,$@,@md.opt.cmd,@md.fns).location do - __LINE__.to_s + ':' + __FILE__ - end - end - end - end - end - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[6] - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[5] - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[4] - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[3] - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[2] - @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[1] - @ncxo[1],@ncxo[2],@ncxo[3],@ncxo[4],@ncxo[5],@ncxo[6]=false,false,false,false,false,false - md_opf_a_content << @epub.metadata_opf.manifest_images(@md.ec[:image]) - @@toc[:seg] << "
\n
" - @@toc[:scr] << "
\n
" - @@toc[:ncx] << @epub.toc_ncx.navmap_close - @@toc[:ncx] << @epub.toc_ncx.close - @@toc[:opf] << md_opf_a_content << @epub.metadata_opf.manifest_close - @@toc[:opf] << @epub.metadata_opf.spine_open << md_opf_a_spine << @epub.metadata_opf.spine_close - @@toc[:opf] << @epub.metadata_opf.guide_open << md_opf_a_guide << @epub.metadata_opf.guide_close - @@toc[:opf] << @epub.metadata_opf.package_close - @@toc[:opf]=@@toc[:opf].flatten - SiSU_EPUB::Source::Output.new(@md,@@toc[:opf]).epub_metadata_opf - SiSU_EPUB::Source::Output.new(@md,@@toc[:ncx]).epub_toc_ncx - @md.firstseg=@@firstseg - @@toc - end - protected - def level_1 - dob=@data - linkname,link=dob.obj.strip,dob.ocn - title=if dob.obj !~/Document Information/ - linkname - else - link='metadata' - %{#{linkname}} - end - toc={} - txt_obj={ txt: title } - format_toc=SiSU_EPUB_Format::FormatToc.new(@md,txt_obj) - toc[:seg]=if dob.name =~/^meta/ \ - and dob.obj =~/Document Information/ #check - format_toc.lev0 - else format_toc.lev1 - end - title=if dob.ocn ==0 - if dob.name =~/^meta/ \ - and dob.obj =~/Document Information/ - %{#{linkname}} - else linkname - end - else - @@toc[:scr] << '
' - link=(dob.ln) \ - ? dob.ln - : '' - %{#{linkname}} - end - txt_obj={ txt: title } - format_toc=SiSU_EPUB_Format::FormatToc.new(@md,txt_obj) - toc[:scr]=if dob.name =~/^meta/ \ - and dob.obj =~/Document Information/ - format_toc.lev0 - else format_toc.lev1 - end - toc - end - def level_2 - dob=@data - linkname,ocn=dob.obj.strip,dob.ocn - if ocn \ - and ocn !~/#/ - p_num=SiSU_EPUB_Format::ParagraphNumber.new(@md,ocn) - end - txt_obj={ txt: linkname } - format_toc=SiSU_EPUB_Format::FormatToc.new(@md,txt_obj) - toc={} - toc[:seg]=format_toc.lev2 - if p_num - title=%{#{p_num.goto}#{linkname}} - txt_obj={ txt: title } - format_toc=SiSU_EPUB_Format::FormatToc.new(@md,txt_obj) - toc[:scr]=format_toc.lev2 - end - toc - end - def level_3 - dob=@data - linkname,ocn=dob.obj.strip,dob.ocn - if ocn \ - and ocn !~/#/ - p_num=SiSU_EPUB_Format::ParagraphNumber.new(@md,ocn) - end - txt_obj={ txt: linkname } - format_toc=SiSU_EPUB_Format::FormatToc.new(@md,txt_obj) - toc={} - toc[:seg]=format_toc.lev3 - if p_num - title=%{#{p_num.goto}#{linkname}} - txt_obj={ txt: title } - format_toc=SiSU_EPUB_Format::FormatToc.new(@md,txt_obj) - toc[:scr]=format_toc.lev3 - end - toc - end - def level_4 - dob=@data - linkname,ocn=dob.obj.strip,dob.ocn - p_num=SiSU_EPUB_Format::ParagraphNumber.new(@md,ocn) if ocn - if dob.ln==4 - seg_link=%{ - #{dob.obj} - } - @@seg_url=dob.name - elsif dob.obj =~/\d+.\d+.\d+.\d+|\d+.\d+.\d+|\d+.\d+|\d+/ - seg_link=dob.obj.gsub(/^(\d+.\d+.\d+.\d+|\d+.\d+.\d+|\d+.\d+|\d+)(.*)/, - %{} + - %{\\1 \\2 }) - end - p_num=SiSU_EPUB_Format::ParagraphNumber.new(@md,ocn) if ocn - txt_obj={ txt: seg_link } - format_toc=SiSU_EPUB_Format::FormatToc.new(@md,txt_obj) - toc={} - toc[:seg]=format_toc.lev4 - title=%{#{p_num.goto}#{linkname}} if p_num - txt_obj={ txt: title } - format_toc=SiSU_EPUB_Format::FormatToc.new(@md,txt_obj) - toc[:scr]=format_toc.lev4 - toc - end - def level_5 - dob=@data - linkname,ocn=dob.obj.strip,dob.ocn - toc={} - if ocn \ - and ocn !~/#/ - p_num=SiSU_EPUB_Format::ParagraphNumber.new(@md,ocn) - lnk_n_txt=%{ - #{linkname} - } - txt_obj={ txt: lnk_n_txt } - format_toc=SiSU_EPUB_Format::FormatToc.new(@md,txt_obj) - toc[:seg]=format_toc.lev5 - title=%{#{p_num.goto}#{linkname}} - txt_obj={ txt: title } - format_toc=SiSU_EPUB_Format::FormatToc.new(@md,txt_obj) - toc[:scr]=format_toc.lev5 - end - toc - end - def level_6 - dob=@data - linkname,ocn=dob.obj.strip,dob.ocn - toc={} - if ocn \ - and ocn !~/#/ - p_num=SiSU_EPUB_Format::ParagraphNumber.new(@md,ocn) - lnk_n_txt=%{ - #{linkname} -} - txt_obj={ txt: lnk_n_txt } - format_toc=SiSU_EPUB_Format::FormatToc.new(@md,txt_obj) - toc[:seg]=format_toc.lev6 - title=%{#{p_num.goto}#{linkname}} - txt_obj={ txt: title } - format_toc=SiSU_EPUB_Format::FormatToc.new(@md,txt_obj) - toc[:scr]=format_toc.lev6 - end - toc - end - end - class ScrollHeadAndSegToc < Toc - def initialize(md='',toc='',links_guide_toc='') - @md,@toc,@links_guide_toc=md,toc,links_guide_toc - @vz=SiSU_Viz::Defaults.new - end - def in_common - toc_shared=[] - segtoc=[] - if (@md.opt.act[:verbose][:set]==:on \ - || @md.opt.act[:verbose_plus][:set]==:on \ - || @md.opt.act[:maintenance][:set]==:on) - SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set],'Scroll & Segtoc').txt_grey - end - format_head_toc=SiSU_EPUB_Format::HeadToc.new(@md) - dochead=format_head_toc.head - dochead=dochead.gsub(/toc\.(html)/,'doc.\1') #kludge - toc_shared << dochead #<< ads.div.major - segtoc << format_head_toc.head #<< ads.div.major - if defined? @md.rights.all \ - and @md.rights.all - rights=format_head_toc.rights.all - rights=SiSU_EPUB_Tune::CleanXHTML.new(rights).clean - end - if defined? @md.notes.prefix_b \ - and @md.notes.prefix_b - prefix_b=format_head_toc.prefix_b - prefix_b=SiSU_EPUB_Tune::CleanXHTML.new(prefix_b).clean - end - tmp_head=nil - doc_title_endnote=@md.title.full.gsub(/(\*+)/,'\1') - tmp_head=doc_title_endnote + "\n" - txt_obj={ txt: tmp_head } - format_txt_obj=SiSU_EPUB_Format::FormatTextObject.new(@md,txt_obj) - toc_shared << format_txt_obj.center_bold - segtoc << format_txt_obj.center_bold - if defined? @md.creator.author \ - and @md.creator.author - creator_endnote=@md.creator.author.gsub(/(\*+)/,%{#{$ep[:hsp]}\\1}) - tmp_head=creator_endnote + "\n" - txt_obj={ txt: tmp_head } - format_txt_obj=SiSU_EPUB_Format::FormatTextObject.new(@md,txt_obj) - toc_shared << format_txt_obj.center_bold - segtoc << format_txt_obj.center_bold - end - tmp_head=nil - if defined? @md.prefix_a \ - and @md.prefix_a - tmp_head ||= %{#{@md.prefix_a}\n} - toc_shared << tmp_head.dup - segtoc << tmp_head.dup - end - tmp_head=nil - toc_shared << @links_guide_toc - if defined? @md.rights.all \ - and @md.rights.all - toc_shared << rights - end - if defined? @md.prefix_b \ - and @md.prefix_b - toc_shared << prefix_b - end - #Table of Contents added/appended here - toc_shared << @toc[:scr] - segtoc << @links_guide_toc - segtoc << @toc[:seg] - if defined? @md.rights.all \ - and @md.rights.all - segtoc << rights - end - if defined? @md.prefix_b \ - and @md.prefix_b - segtoc << prefix_b - end - #Segtoc tail added here - segtoc << format_head_toc.xhtml_close - segtoc=segtoc.flatten.compact #watch - SiSU_EPUB::Source::Output.new(@md).make_cover_image - SiSU_EPUB::Source::Output.new(@md,segtoc).make_segtoc - segtoc=[] - @toc[:scr],@toc[:seg]=[],[] - toc_shared - end - end - class Table < SiSU_XHTML_Table::TableXHTML - end - class Seg < SiSU_EPUB_Seg::Seg - end - class Output - def initialize(md,output='') - @md,@output=md,output - @epub_doc="#{@md.fnb}.epub" - @epub_header=SiSU_EPUB_Format::HeadInformation.new(@md) - @make=SiSU_Env::ProcessingSettings.new(@md) - @make_file=SiSU_Env::CreateFile.new(@md.fns) - end - def songsheet - mimetype - metainf_container - css - images if @md.ec[:image] - #concordance #uncomment to enable inclusion of concordance file - output_zip - end - def mimetype - out=@make_file.epub.mimetype - out<<@epub_header.mimetype - out.close - end - def metainf_container #container.xml file in META-INF directory - out=@make_file.epub.metainf_cont - out<<@epub_header.metainf_container - out.close - end - def css - out=@make_file.epub.xhtml_css - out << SiSU_EPUB_Format::CSS.new.css_epub_xhtml - out.close - end - def epub_toc_ncx - begin - out=@make_file.epub.toc_ncx - @output.each do |para| - unless para =~/\A\s*\Z/ - out.puts para - end - end - out.close - rescue - SiSU_Errors::Rescued.new($!,$@,@md.opt.cmd,@md.fns).location do - __LINE__.to_s + ':' + __FILE__ - end - end - end - def epub_metadata_opf - begin - out=@make_file.epub.metadata - @output.each do |para| - unless para =~/\A\s*\Z/ - out.puts para - end - end - out.close - rescue - SiSU_Errors::Rescued.new($!,$@,@md.opt.cmd,@md.fns).location do - __LINE__.to_s + ':' + __FILE__ - end - end - end - def images - img_pth=@md.env.path.image_source_include - img_src_pth=unless @md.opt.f_pth[:pth] =~/\/\S+?\/sisupod\/\S+?\/sisupod\/doc/ - @md.file.output_path.epub.rel_image - else - pt=/(\/\S+?\/sisupod\/\S+?\/sisupod)\/doc/.match(@md.opt.f_pth[:pth])[1] - pt + '/image' - end - @md.ec[:image].each do |x| - if FileTest.directory?("#{@md.env.processing_path.epub}/#{Ep[:d_oebps]}/image") \ - && FileTest.file?("#{img_src_pth}/#{x}") - FileUtils::cp("#{img_src_pth}/#{x}","#{@md.env.processing_path.epub}/#{Ep[:d_oebps]}/image") - elsif FileTest.directory?("#{@md.env.processing_path.epub}/#{Ep[:d_oebps]}/image") \ - && FileTest.file?("#{img_pth}/#{x}") - FileUtils::cp("#{img_pth}/#{x}","#{@md.env.processing_path.epub}/#{Ep[:d_oebps]}/image") - else STDERR.puts %{\t*WARN* did not find image - "#{x}" in #{img_src_pth} or #{img_pth} [#{__FILE__}:#{__LINE__}]} - end - end - end - def concordance - SiSU_EPUB_Concordance::Source.new(@md.opt).read - end - def output_zip - FileUtils::mkdir_p(@md.file.output_path.epub.dir) unless FileTest.directory?(@md.file.output_path.epub.dir) - if FileTest.directory?(@md.env.processing_path.epub) - pwd=Dir.pwd - Dir.chdir(@md.env.processing_path.epub) - system(" - zip -qXr9D #{@epub_doc} * - ") - FileUtils::mv(@epub_doc, @md.file.place_file.epub.dir) - Dir.chdir(pwd) - unless @md.opt.act[:maintenance][:set]==:on - FileUtils::rm_r(@md.env.processing_path.epub) - end - end - end - def make_cover_image - begin - if @md.make.cover_image? \ - and @md.make.cover_image.is_a?(Hash) \ - and @md.make.cover_image[:cover] =~/\S+/ - filename_xhtml=@make_file.epub.xhtml_cover_image - cover_image=< - - - - Cover - - - - - -
-
- - - -
-
- - -WOK - filename_xhtml.puts cover_image,"\n" - filename_xhtml.close - end - rescue - SiSU_Errors::Rescued.new($!,$@,@md.opt.cmd,@md.fns).location do - __LINE__.to_s + ':' + __FILE__ - end - end - end - def make_segtoc - begin - if @make.build.toc? - filename_xhtml=@make_file.epub.xhtml_index - @output.each do |para| - para=para.strip - unless para =~/\A\s*\Z/ - filename_xhtml.puts para,"\n" - end - end - filename_xhtml.close - end - rescue - SiSU_Errors::Rescued.new($!,$@,@md.opt.cmd,@md.fns).location do - __LINE__.to_s + ':' + __FILE__ - end - end - end - end - end -end -__END__ diff --git a/lib/sisu/v5/epub_concordance.rb b/lib/sisu/v5/epub_concordance.rb deleted file mode 100644 index ab5b272a..00000000 --- a/lib/sisu/v5/epub_concordance.rb +++ /dev/null @@ -1,324 +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: epub concordance file (html concordance, wordmap, linked index - of words in document) - -=end -module SiSU_EPUB_Concordance - require_relative 'particulars' # particulars.rb - include SiSU_Particulars - require_relative 'sysenv' # sysenv.rb - include SiSU_Env - require_relative 'defaults' # defaults.rb - include SiSU_Viz - require_relative 'epub_format' # epub_format.rb - include SiSU_EPUB_Format - class Source - def initialize(opt) - @opt=opt - @particulars=SiSU_Particulars::CombinedSingleton.instance.get_all(opt) - end - def read - begin - @env,@md=@particulars.env,@particulars.md - wordmax=@env.concord_max - unless @md.wc_words.nil? - if @md.wc_words < wordmax - SiSU_EPUB_Concordance::Source::Words.new(@particulars).songsheet - else - SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set],"*WARN* concordance skipped, large document has over #{wordmax} words (#{@md.wc_words})").warn unless @md.opt.act[:quiet][:set]==:on - end - else - SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set],"*WARN* wc (word count) is off, concordance will be processed for all files including those over the max set size of: #{wordmax} words").warn unless @md.opt.act[:quiet][:set]==:on - SiSU_EPUB_Concordance::Source::Words.new(@particulars).songsheet - end - rescue - SiSU_Errors::Rescued.new($!,$@,@md.opt.cmd,@md.fns).location do - __LINE__.to_s + ':' + __FILE__ - end - ensure - end - end - private - class DocTitle - include SiSU_Viz - #revisit, both requires (html & shared_xml) needed for stand alone operation (sisu -w [filename]) - require_relative 'epub' # epub.rb - def initialize(particulars) - @particulars,@md=particulars,particulars.md - @data=SiSU_EPUB::Source::XHTML_Environment.new(particulars).tuned_file_instructions - @vz=SiSU_Viz::Defaults.new - @fnb=@md.fnb - @lex_button=%{SiSU home} - @doc_details =<#{$ep[:hsp]}

#{@md.title.full}

#{@md.creator.author}

-WOK - end - def create - @css=SiSU_Env::CSS_Stylesheet.new(@particulars.md) - format_head_toc=SiSU_EPUB_Format::HeadToc.new(@md) - dochead=format_head_toc.head - < - #{@doc_details} -

Word index links are to html versions of the text the segmented version followed by the scroll (single document) version.
[For segmented text references [T1], [T2] or [T3] appearing without a link, indicates that the word appears in a title (or subtitle) of the text (that is identifiable by the appended object citation number).]

-

(The word listing/index is Case sensitive: Capitalized words appear before lower case)

-

- word (number of occurences)
linked references to word within document
- [if number of occurences exceed number of references - word occurs more than once in at least one reference. Footnote/endnotes are either assigned to the paragraph from which they are referenced or ignored, so it is relevant to check the footnotes referenced from within a paragraph as well.] -

-

- (After the page is fully loaded) you can jump directly to a word by appending a hash (#) and the word to the url for this text, (do not forget that words are case sensitive, and may be listed twice (starting with and without an upper case letter)), #your_word # [#{$ep[:hsp]}http://[web host]/#{@fnb}/concordance.html#your_word#{$ep[:hsp]}] -

-WOK - end - end - class Word - @@word_previous='' - def initialize(word,freq) - @word,@freq=word,freq - end - def html - w=if @word.capitalize==@@word_previous - %{\n

#{@word}

(#{@freq})

\n\t

} - else n=@word.strip.gsub(/\s+/,'_') #also need to convert extended character set to html - %{\n

#{@word}

(#{@freq})

\n\t

} - end - @@word_previous=@word.capitalize - w - end - end - class Words - require_relative 'defaults' # defaults.rb - include SiSU_Viz - require_relative 'epub_format' # epub_format.rb - include SiSU_EPUB_Format - require_relative 'sysenv' # sysenv.rb - include SiSU_Screen - def initialize(particulars) - @particulars=particulars - begin - @vz=SiSU_Viz::Defaults.new - @env,@md,@ao_array=particulars.env,particulars.md,particulars.ao_array - @path="#{@env.processing_path.epub}" - @freq=Hash.new(0) - @rxp_lv1=/^#{Mx[:lv_o]}1:/ #fix Mx[:lv_o] - @rxp_lv2=/^#{Mx[:lv_o]}2:/ #fix Mx[:lv_o] - @rxp_lv3=/^#{Mx[:lv_o]}3:/ #fix Mx[:lv_o] - @rxp_seg=/^#{Mx[:lv_o]}4:(\S+?)#{Mx[:lv_c]}/ - @rxp_title=Regexp.new("^#{Mx[:meta_o]}title#{Mx[:meta_c]}\s*(.+?)\s*$") - @rxp_t1=Regexp.new('^T1') - @rxp_t2=Regexp.new('^T2') - @rxp_t3=Regexp.new('^T3') - @rxp_excluded1=/(?:https?|file|ftp):\/\/\S+/ - @rxp_excluded0=/^(?:#{Mx[:fa_bold_o]}|#{Mx[:fa_italics_o]})?(?:to\d+|\d+| |#{Mx[:br_endnotes]}|EOF|#{Mx[:br_eof]}|thumb_\S+|snap_\S+|_+|-+|[(]?(?:ii+|iv|vi+|ix|xi+|xiv|xv|xvi+|xix|xx)[).]?|\S+?_\S+|[\d_]+\w\S+|[\w\d]{1,2}|\d{1,3}\w?|[0-9a-f]{16,64}|\d{2,3}x\d{2,3}|\S{0,2}sha\d|\S{0,3}\d{4}w\d\d|\b\w\d+|\d_all\b|e\.?g\.?)(?:#{Mx[:fa_bold_c]}|#{Mx[:fa_italics_c]})?$/mi #this regex causes and cures a stack dump in ruby 1.9 !!! - @rgx_splitlist=%r{[—.,;:-]+|#{Mx[:nbsp]}+}mi - @rgx_scanlist=%r{#{Mx[:fa_italics_o]}[a-zA-Z0-9"\s]{2,12}#{Mx[:fa_italics_c]}|#{Mx[:fa_bold_o]}[a-zA-Z0-9"\s]{2,12}#{Mx[:fa_bold_c]}|#{Mx[:url_o]}https?://\S+?#{Mx[:url_c]}|file://\S+|<\S+?>|\w+|[a-zA-Z]+}mi - rescue - SiSU_Errors::Rescued.new($!,$@,@md.opt.cmd,@md.fns).location do - __LINE__.to_s + ':' + __FILE__ - end - end - end - def songsheet - begin - #fix to use - p __LINE__.to_s + ':' + __FILE__ - p "#{@path}/content/#{@md.fn[:epub_concord]}" - p "#{@md.file.output_path.epub.dir}/#{@md.file.base_filename.epub}" - @file_concordance=File.open("#{@path}/content/#{@md.fn[:epub_concord]}",'w') - map_para - rescue - SiSU_Errors::Rescued.new($!,$@,@md.opt.cmd,@md.fns).location do - __LINE__.to_s + ':' + __FILE__ - end - ensure - @file_concordance.close - end - end - protected - def location_scroll(wordlocation,show) - @wordlocation=wordlocation - %{#{@wordlocation}; } - end - def location_seg(wordlocation,show) - @wordlocation,@show=wordlocation,show - @word_location_seg=wordlocation.gsub(/(.+?)\#(\d+)/,"\\1#{Sfx[:epub_xhtml]}#o\\2") unless wordlocation.nil? - case @wordlocation - when @rxp_t1 - %{[H]#{@show}, } - when @rxp_t2 - %{[H]#{@show}, } - when @rxp_t3 - %{[H]#{@show}, } - else %{#{@show}, } - end - end - def map_para - @seg,toy=nil,nil - @word_map={} - @ao_array.each do |line| - if defined? line.ocn - if (line.is ==:heading \ - || line.is ==:heading_insert) \ - && line.ln==4 - @seg=line.name - end - if line.ocn.to_s =~/\d+/ then toy=line.ocn.to_s - end - if toy =~/\d+/ \ - and toy !~/^0$/ - line.obj=line.obj.split(@rgx_splitlist).join(' ') #%take in word or other match - for word in line.obj.scan(@rgx_scanlist) #%take in word or other match - word=word.gsub(/#{Mx[:lnk_o]}|#{Mx[:lnk_c]}|#{Mx[:url_o]}|#{Mx[:url_c]}/,''). - gsub(/#{Mx[:fa_o]}\S+?#{Mx[:fa_o_c]}/,''). - gsub(/#{Mx[:fa_c_o]}\S+?#{Mx[:fa_c]}/,''). - gsub(/#{Mx[:gl_o]}#[a-z]+#{Mx[:gl_c]}/,''). - gsub(/#{Mx[:gl_o]}#[0-9]+#{Mx[:gl_c]}/,''). - gsub(/^\S$/,'') - word=nil if word.empty? - word=nil if word =~@rxp_excluded0 #watch - word=nil if word =~@rxp_excluded1 #watch - word=nil if word =~/^\S$/ - if word - word=word.gsub(/#{Mx[:br_nl]}|#{Mx[:br_line]}/,' '). - gsub(/#{Mx[:fa_o]}[a-z]{1,7}#{Mx[:fa_o_c]}|#{Mx[:fa_c_o]}[a-z]{1,7}#{Mx[:fa_c]}/,''). - gsub(/#{Mx[:mk_o]}(?:[0-9a-f]{32}:[0-9a-f]{32}|[0-9a-f]{64}:[0-9a-f]{64})#{Mx[:mk_c]}/,''). - gsub(/#{Mx[:mk_o]}(?:[0-9a-f]{32}|[0-9a-f]{64})#{Mx[:mk_c]}/,''). - gsub(/#{Mx[:en_a_o]}(?:\d|[*+])*|#{Mx[:en_b_o]}(?:\d|[*+])*|#{Mx[:en_a_c]}|#{Mx[:en_b_c]}/mi,''). - gsub(/#{Mx[:fa_o]}\S+?#{Mx[:fa_o_c]}/,'').gsub(/#{Mx[:fa_c_o]}\S+?#{Mx[:fa_c]}/,''). - gsub(/<\/?\S+?>/,''). - gsub(/^\@+/,''). - strip. - gsub(/#{Mx[:tc_p]}.+/,''). - gsub(/[\.,;:"]$/,''). - gsub(/["]/,''). - gsub(/^\s*[\(]/,''). - gsub(/[\(]\s*$/,''). - gsub(/^(?:See|e\.?g\.?).+/,''). - gsub(/^\s*[.,;:]\s*/,''). - strip. - gsub(/^\(?[a-zA-Z]\)$/,''). - gsub(/^\d+(st|nd|rd|th)$/,''). - gsub(/^(\d+\.?)+$/, ''). - gsub(/#{Mx[:mk_o]}|#{Mx[:mk_c]}/,''). - gsub(/:name#\S+/,''). - gsub(/^\S$/,'') - word=nil if word =~/^\S$/ - word=nil if word =~/^\s*$/ #watch - if word - unless word =~/[A-Z][A-Z]/ \ - or word =~/\w+\s\w+/ - word=word.capitalize - end - @freq[word] +=1 - @word_map[word] ||= [] - if line !~@rxp_lv1 \ - and line !~@rxp_lv2 \ - and line !~@rxp_lv3 - @word_map[word] << location_seg("#{@seg}\##{toy}",toy) - else - @word_map[word] << case line - when @rxp_lv1; location_seg('T1',toy) - when @rxp_lv2; location_seg('T2',toy) - when @rxp_lv3; location_seg('T3',toy) - end - end - end - end - end - end - end - end - seg='' - @file_concordance << SiSU_EPUB_Concordance::Source::DocTitle.new(@particulars).create - alph=%W[A B C D E F G H I J K L M N O P Q R S T U V W X Y Z] - @file_concordance << '

' - alph.each {|x| @file_concordance << %{#{x},#{$ep[:hsp]}}} - @file_concordance << '

' - letter=alph.shift - @file_concordance << %{\n

A

} - for word in @freq.keys.sort! {|a,b| a.downcase<=>b.downcase} - f=/^(\S)/.match(word)[1] - if letter < f.upcase - while letter < f.upcase - if alph.length > 0 - letter=alph.shift - @file_concordance << %{\n

#{letter}

} - else break - end - end - end - keyword=SiSU_EPUB_Concordance::Source::Word.new(word,@freq[word]).html - if keyword !~ @rxp_excluded0 - if @word_map[word][0] =~ /\d+/ - @file_concordance << %{#{keyword}#{seg}#{@word_map[word].uniq.compact.join}} - end - @file_concordance << '

' - end - # special cases endnotes and header levels 1 - 3 - end - credits=@vz.credits_sisu_epub - @file_concordance << %{>#{credits}\n} # footer - end - end - end -end -__END__ diff --git a/lib/sisu/v5/epub_format.rb b/lib/sisu/v5/epub_format.rb deleted file mode 100644 index 1c57cd20..00000000 --- a/lib/sisu/v5/epub_format.rb +++ /dev/null @@ -1,2236 +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: epub formating, css template - -=end -module SiSU_EPUB_Format - include SiSU_Viz - class ParagraphNumber - def initialize(md,ocn) - @md,@ocn=md,ocn.to_s - @ocn ||='' - end - def ocn_display - make=SiSU_Env::ProcessingSettings.new(@md) - if make.build.ocn? - ocn_class='ocn' - if @ocn==nil \ - or @ocn.to_i==0 \ - or @ocn.empty? - %{} - else - @ocn.gsub(/^(\d+|)$/, - %{}) - end - else - %{} - end - end - def name - (@ocn==nil || @ocn.empty?) ? '' : %{} - end - def id #w3c? "tidy" complains about numbers as identifiers ! annoying - (@ocn==nil || @ocn.empty?) ? '' : %{id="o#{@ocn}"} - end - def goto - (@ocn==nil || @ocn.empty?) ? '' : %{} - end - end - class CSS - def css_epub_xhtml - <<-WOK -/* SiSU epub css default stylesheet */ - body { - color: black; - background: #ffffff; - background-color: #ffffff; - } -/* - table { - margin-left: 5%; - display: block; - } - tr { - display: block; - } - th,td { - display: inline; - vertical-align: top; - } -*/ - a:link { - color: #003399; - text-decoration: none; - } - a:visited { - color: #003399; - text-decoration: none; - } - a:hover { - color: #000000; - background-color: #f9f9aa; - } -/* - a:hover { - border-bottom: 2px solid #777777; - background-color: #fff3b6; - } -*/ - a:hover img { - background-color: #ffffff; - } - a:active { - color: #003399; - text-decoration: underline; - } - a.lnkocn:link { - color: #777777; - text-decoration: none; - } - div { - margin-left: 0; - margin-right: 0; - } - div.p { - margin-left: 5%; - margin-right: 1%; - } - - .norm, .bold, .verse, .group, .block, .alt { - line-height: 133%; - margin-left: 0em; - margin-right: 2em; - margin-top: 12px; - margin-bottom: 0px; - padding-left: 0em; - text-indent: 0mm; - } - p, h0, h1, h2, h3, h4, h5, h6 { - display: block; - font-family: verdana, arial, georgia, tahoma, sans-serif, helvetica, times, roman; - font-size: 100%; - font-weight: normal; - line-height: 133%; - text-align: justify; - margin-left: 0em; - margin-right: 2em; - text-indent: 0mm; - margin-top: 0.8em; - margin-bottom: 0.8em; - } - p.norm { } - p.i1 {padding-left: 1em;} - p.i2 {padding-left: 2em;} - p.i3 {padding-left: 3em;} - p.i4 {padding-left: 4em;} - p.i5 {padding-left: 5em;} - p.i6 {padding-left: 6em;} - p.i7 {padding-left: 7em;} - p.i8 {padding-left: 8em;} - p.i9 {padding-left: 9em;} - - p.h0i0 { - padding-left: 0em; - text-indent: 0em; - } - p.h0i1 { - padding-left: 1em; - text-indent: -1em; - } - p.h0i2 { - padding-left: 2em; - text-indent: -2em; - } - p.h0i3 { - padding-left: 3em; - text-indent: -3em; - } - p.h0i4 { - padding-left: 4em; - text-indent: -4em; - } - p.h0i5 { - padding-left: 5em; - text-indent: -5em; - } - p.h0i6 { - padding-left: 6em; - text-indent: -6em; - } - p.h0i7 { - padding-left: 7em; - text-indent: -7em; - } - p.h0i8 { - padding-left: 8em; - text-indent: -8em; - } - p.h0i9 { - padding-left: 9em; - text-indent: -9em; - } - - p.h1i0 { - padding-left: 0em; - text-indent: 1em; - } - p.h1i1 { - padding-left: 1em; - text-indent: 0em; - } - p.h1i2 { - padding-left: 2em; - text-indent: -1em; - } - p.h1i3 { - padding-left: 3em; - text-indent: -2em; - } - p.h1i4 { - padding-left: 4em; - text-indent: -3em; - } - p.h1i5 { - padding-left: 5em; - text-indent: -4em; - } - p.h1i6 { - padding-left: 6em; - text-indent: -5em; - } - p.h1i7 { - padding-left: 7em; - text-indent: -6em; - } - p.h1i8 { - padding-left: 8em; - text-indent: -7em; - } - p.h1i9 { - padding-left: 9em; - text-indent: -8em; - } - - p.h2i0 { - padding-left: 0em; - text-indent: 2em; - } - p.h2i1 { - padding-left: 1em; - text-indent: 1em; - } - p.h2i2 { - padding-left: 2em; - text-indent: 0em; - } - p.h2i3 { - padding-left: 3em; - text-indent: -1em; - } - p.h2i4 { - padding-left: 4em; - text-indent: -2em; - } - p.h2i5 { - padding-left: 5em; - text-indent: -3em; - } - p.h2i6 { - padding-left: 6em; - text-indent: -4em; - } - p.h2i7 { - padding-left: 7em; - text-indent: -5em; - } - p.h2i8 { - padding-left: 8em; - text-indent: -6em; - } - p.h2i9 { - padding-left: 9em; - text-indent: -7em; - } - - p.h3i0 { - padding-left: 0em; - text-indent: 3em; - } - p.h3i1 { - padding-left: 1em; - text-indent: 2em; - } - p.h3i2 { - padding-left: 2em; - text-indent: 1em; - } - p.h3i3 { - padding-left: 3em; - text-indent: 0em; - } - p.h3i4 { - padding-left: 4em; - text-indent: -1em; - } - p.h3i5 { - padding-left: 5em; - text-indent: -2em; - } - p.h3i6 { - padding-left: 6em; - text-indent: -3em; - } - p.h3i7 { - padding-left: 7em; - text-indent: -4em; - } - p.h3i8 { - padding-left: 8em; - text-indent: -5em; - } - p.h3i9 { - padding-left: 9em; - text-indent: -6em; - } - - p.h4i0 { - padding-left: 0em; - text-indent: 4em; - } - p.h4i1 { - padding-left: 1em; - text-indent: 3em; - } - p.h4i2 { - padding-left: 2em; - text-indent: 2em; - } - p.h4i3 { - padding-left: 3em; - text-indent: 1em; - } - p.h4i4 { - padding-left: 4em; - text-indent: 0em; - } - p.h4i5 { - padding-left: 5em; - text-indent: -1em; - } - p.h4i6 { - padding-left: 6em; - text-indent: -2em; - } - p.h4i7 { - padding-left: 7em; - text-indent: -3em; - } - p.h4i8 { - padding-left: 8em; - text-indent: -4em; - } - p.h4i9 { - padding-left: 9em; - text-indent: -5em; - } - - p.h5i0 { - padding-left: 0em; - text-indent: 5em; - } - p.h5i1 { - padding-left: 1em; - text-indent: 4em; - } - p.h5i2 { - padding-left: 2em; - text-indent: 3em; - } - p.h5i3 { - padding-left: 3em; - text-indent: 2em; - } - p.h5i4 { - padding-left: 4em; - text-indent: 1em; - } - p.h5i5 { - padding-left: 5em; - text-indent: 0em; - } - p.h5i6 { - padding-left: 6em; - text-indent: -1em; - } - p.h5i7 { - padding-left: 7em; - text-indent: -2em; - } - p.h5i8 { - padding-left: 8em; - text-indent: -3em; - } - p.h5i9 { - padding-left: 9em; - text-indent: -4em; - } - - p.h6i0 { - padding-left: 0em; - text-indent: 6em; - } - p.h6i1 { - padding-left: 1em; - text-indent: 5em; - } - p.h6i2 { - padding-left: 2em; - text-indent: 4em; - } - p.h6i3 { - padding-left: 3em; - text-indent: 3em; - } - p.h6i4 { - padding-left: 4em; - text-indent: 2em; - } - p.h6i5 { - padding-left: 5em; - text-indent: 1em; - } - p.h6i6 { - padding-left: 6em; - text-indent: 0em; - } - p.h6i7 { - padding-left: 7em; - text-indent: -1em; - } - p.h6i8 { - padding-left: 8em; - text-indent: -2em; - } - p.h6i9 { - padding-left: 9em; - text-indent: -3em; - } - - p.h7i0 { - padding-left: 0em; - text-indent: 7em; - } - p.h7i1 { - padding-left: 1em; - text-indent: 6em; - } - p.h7i2 { - padding-left: 2em; - text-indent: 5em; - } - p.h7i3 { - padding-left: 3em; - text-indent: 4em; - } - p.h7i4 { - padding-left: 4em; - text-indent: 3em; - } - p.h7i5 { - padding-left: 5em; - text-indent: 2em; - } - p.h7i6 { - padding-left: 6em; - text-indent: 1em; - } - p.h7i7 { - padding-left: 7em; - text-indent: 0em; - } - p.h7i8 { - padding-left: 8em; - text-indent: -1em; - } - p.h7i9 { - padding-left: 9em; - text-indent: -2em; - } - - p.h8i0 { - padding-left: 0em; - text-indent: 8em; - } - p.h8i1 { - padding-left: 1em; - text-indent: 7em; - } - p.h8i2 { - padding-left: 2em; - text-indent: 6em; - } - p.h8i3 { - padding-left: 3em; - text-indent: 5em; - } - p.h8i4 { - padding-left: 4em; - text-indent: 4em; - } - p.h8i5 { - padding-left: 5em; - text-indent: 3em; - } - p.h8i6 { - padding-left: 6em; - text-indent: 2em; - } - p.h8i7 { - padding-left: 7em; - text-indent: 1em; - } - p.h8i8 { - padding-left: 8em; - text-indent: 0em; - } - p.h8i9 { - padding-left: 9em; - text-indent: -1em; - } - - p.h9i0 { - padding-left: 0em; - text-indent: 9em; - } - p.h9i1 { - padding-left: 1em; - text-indent: 8em; - } - p.h9i2 { - padding-left: 2em; - text-indent: 7em; - } - p.h9i3 { - padding-left: 3em; - text-indent: 6em; - } - p.h9i4 { - padding-left: 4em; - text-indent: 5em; - } - p.h9i5 { - padding-left: 5em; - text-indent: 4em; - } - p.h9i6 { - padding-left: 6em; - text-indent: 3em; - } - p.h9i7 { - padding-left: 7em; - text-indent: 2em; - } - p.h9i8 { - padding-left: 8em; - text-indent: 1em; - } - p.h9i9 { - padding-left: 9em; - text-indent: 0em; - } - - p.it0 { - margin-left: 0em; - margin-top: 6px; - margin-bottom: 0px; - line-height: 100%; - } - p.it1 { - margin-left: 1em; - margin-top: 0px; - margin-bottom: 0px; - line-height: 100%; - } - p.it2 { - margin-left: 2em; - margin-top: 0px; - margin-bottom: 0px; - line-height: 100%; - } - p.it3 { - margin-left: 3em; - margin-top: 0px; - margin-bottom: 0px; - line-height: 100%; - } - p.it4 { - margin-left: 4em; - margin-top: 0px; - margin-bottom: 0px; - line-height: 100%; - } - p.it5 { - margin-left: 5em; - margin-top: 0px; - margin-bottom: 0px; - line-height: 100%; - } - p.it6 { - margin-left: 6em; - margin-top: 0px; - margin-bottom: 0px; - line-height: 100%; - } - p.it7 { - margin-left: 7em; - margin-top: 0px; - margin-bottom: 0px; - line-height: 100%; - } - p.it8 { - margin-left: 8em; - margin-top: 0px; - margin-bottom: 0px; - line-height: 100%; - } - p.it9 { - margin-left: 9em; - margin-bottom: 0px; - margin-top: 0px; - line-height: 100%; - } - - p.group { } - - p.block { } - - p.alt { } - - p.verse { - margin-bottom: 6px; - } - - p.code { - font-family: inconsolata, andale mono, courier new, courier, monospace; - font-size: 90%; - text-align: left; - background-color: #eeeeee; - } - - p.caption { - text-align: left; - font-size: 80%; - display: inline; - } - - p.endnote { - font-size: 96%; - line-height: 120%; - text-align: left; - margin-right: 2em; - } - p.endnote_indent { - font-size: 96%; - line-height: 120%; - text-align: left; - margin-left: 2em; - margin-right: 2em; - } - - p.center { - text-align: center; - } - p.align_right { - text-align: right; - } - p.bold { - font-weight: bold; - } - p.bold_left { - font-weight: bold; - text-align: left; - } - p.centerbold { - text-align: center; - font-weight: bold; - } - p.em { - font-weight: bold; - font-style: normal; - background: #fff3b6; - } - - p.small { - font-size: 80%; - margin-top: 0px; - margin-bottom: 0px; - margin-right: 6px; - text-align: left; - } - - .tiny, .tiny_left, .tiny_right, .tiny_center { - font-size: 10px; - margin-top: 0px; - margin-bottom: 0px; - color: #777777; - margin-right: 6px; - text-align: left; - } - p.tiny { } - p.tiny_left { - margin-left: 0px; - margin-right: 0px; - text-align: left; - } - p.tiny_right { - margin-right: 1em; - text-align: right; - } - p.tiny_center { - margin-left: 0px; - margin-right: 0px; - text-align: center; - } - - p.concordance_word { - line-height: 150%; - font-weight: bold; - display: inline; - margin-top: 4px; - margin-bottom: 1px; - } - p.concordance_count { - font-size: 80%; - color: #777777; - display: inline; - margin-left: 0em; - } - p.concordance_object { - font-size: 80%; - line-height: 120%; - text-align: left; - margin-left: 3em; - margin-top: 1px; - margin-bottom: 3px; - } - p.book_index_lev1 { - line-height: 100%; - margin-top: 4px; - margin-bottom: 1px; - } - p.book_index_lev2 { - line-height: 100%; - text-align: left; - margin-left: 3em; - margin-top: 1px; - margin-bottom: 3px; - } - - p.quickref { - font-size: 10px; - font-style: italic; - margin-top: 0px; - margin-bottom: 0px; - color: #777777; - margin-right: 5px; - text-align: left; - } - p.bigref { - font-size: 11px; - font-weight: bold; - margin-top: 0px; - margin-bottom: 0px; - color: #777777; - margin-right: 5px; - text-align: center; - } - - p.letter { - font-weight: bold; - font-size: 80%; - margin-left: 0em; - margin-top: 2px; - margin-bottom: 2px; - margin-right: 6px; - text-align: left; - color: white; - background: #880000; - } - - tt { - font-family: inconsolata, andale mono, courier new, courier, monospace; - background-color: #eeeeee; - } - - label.ocn { - width: 2%; - float: right; - top: 0; - font-size: 10px; - margin-top: 0px; - margin-bottom: 5px; - color: #777777; - margin-right: 5px; - text-align: right; - background-color: #ffffff; - } - - table { } - tr { } - th,td { - vertical-align: top; - text-align: left; - } - th { - font-weight: bold; - } - - p.left, th.left, td.left { - text-align: left; - } - p.small_left, th.small_left, td.small_left { - text-align: left; - font-size: 80%; - } - p.right, th.right, td.right { - text-align: right; - } - - #horizontal_links { - background: #eeeeee; - margin-left: 5%; - margin-right: 5%; - } - #horizontal { - margin: 0; - padding: 0 0 0 10px; - border-top: 1px solid #000077; - border-bottom: 1px solid #000077; - } - #horizontal li { - margin: 0 0 0 0; - padding: 0 16px 0 0; - display: inline; - list-style-type: none; - text-align: left; - background: none; - } - #horizontal a { - line-height: 12px; - margin: 0 0 0 0; - text-decoration: none; - color: #000077; - } - #horizontal a.active, #horizontal a:hover { - border-bottom: 2px solid #777777; - padding-bottom: 2px; - color: #000077; - } - #horizontal a:hover { - color: #000077; - } - - #document_versions { - position: absolute; - top: 10mm; - right: 2%; - width: 12%; - float: right; - } - - #vertical_links { - position: absolute; - top: 10mm; - right: 0px; - width: 20%; - background: #dddddd; - float: right; - } - #vertical { - padding: 0 12px 0px 0px; - margin-left: 2%; - margin-right: 2%; - } - #vertical li { - display: block; - list-style-type: none; - } - #vertical a { - line-height: 12px; - text-decoration: none; - color: #000077; - } - #vertical a.active, #vertical a:hover { - border-bottom: 2px solid #777777; - padding-bottom: 2px; - color: #000077; - } - - ul, li { - list-style-type: none; - list-style: none; - padding-left: 20px; - display: block; - font-family: verdana, arial, georgia, tahoma, sans-serif, helvetica, times, roman; - font-weight: normal; - line-height: 150%; - text-align: justify; - text-indent: 0mm; - margin-left: 1em; - margin-right: 2em; - margin-top: 3px; - margin-bottom: 3px; - } - - li { - background: url(../image/bullet_09.png) no-repeat 0px 6px; - } - - ul { - } - li.bullet { margin-left: 0em; } - li.i1 { margin-left: 1em; } - li.i2 { margin-left: 2em; } - li.i3 { margin-left: 3em; } - li.i4 { margin-left: 4em; } - li.i5 { margin-left: 5em; } - li.i6 { margin-left: 6em; } - li.i7 { margin-left: 7em; } - li.i8 { margin-left: 8em; } - li.i9 { margin-left: 9em; } - - li.doc, li.ref, li.refcenter { - margin-top: 0px; - margin-bottom: 0px; - margin-right: 0px; - font-size: 8px; - font-style: normal; - text-align: left; - } - li.doc { - background: url(../image/bullet_09.png) no-repeat 0px 6px; - padding-left: 16px; - margin-left: 10px; - margin-right: 0px; - } - li.ref { - background: none; - padding-left: 0; - margin-left: 0; - color: #777777; - } - li.refcenter { - background: url(../image/bullet_09.png) no-repeat 0px 6px; - padding-left: 20px; - margin-left: 10%; - font-size: 9px; - color: #777777; - text-align: center; - } - li.refbold { - list-style-type: none; - padding-left: 16px; - margin-left: 0; - margin-right: 10mm; - font-weight: bold; - } - - h0, h1, h2, h3, h4, h5, h6 { - font-weight: bold; - line-height: 120%; - text-align: left; - margin-top: 20px; - margin-bottom: 10px; - } - h4.norm, h5.norm, h6.norm { - margin-top: 10px; - margin-bottom: 0px; - } - h1.center, h2.center, h3.center, h4.center, h5.center, h6.center { - text-align: center; - } - h1 { font-size: 120%; } - h2 { font-size: 115%; } - h3 { font-size: 110%; } - h4 { font-size: 105%; } - h5 { font-size: 100%; } - h6 { font-size: 100%; } - h0 { font-size: 80%; } - - h1.i {margin-left: 2em;} - h2.i {margin-left: 3em;} - h3.i {margin-left: 4em;} - h4.i {margin-left: 5em;} - h5.i {margin-left: 6em;} - h6.i {margin-left: 7em;} - h7.i {margin-left: 8em;} - h8.i {margin-left: 9em;} - h9.i {margin-left: 10em;} - - .toc { - font-weight: normal; - margin-top: 6px; - margin-bottom: 6px; - } - h1.toc { - margin-left: 1em; - font-size: 115%; - line-height: 150%; - } - h2.toc { - margin-left: 2em; - font-size: 110%; - line-height: 140%; - } - h3.toc { - margin-left: 3em; - font-size: 105%; - line-height: 120%; - } - h4.toc { - margin-left: 4em; - font-size: 100%; - line-height: 120%; - } - h5.toc { - margin-left: 5em; - font-size: 95%; - line-height: 110%; - } - h6.toc { - margin-left: 6em; - font-size: 90%; - line-height: 110%; - } - - .microtoc { - margin-top: 2px; - margin-bottom: 2px; - } - - h1.microtoc { - margin-left: 0mm; - font-size: 115%; - } - h2.microtoc { - margin-left: 5mm; - font-size: 110%; - } - h3.microtoc { - margin-left: 10mm; - font-size: 105%; - } - h4.microtoc { - margin-left: 15mm; - font-weight: normal; - font-size: 100%; - } - h5.microtoc { - margin-left: 20mm; - font-weight: normal; - font-size: 95%; - } - h6.microtoc { - margin-left: 25mm; - font-weight: normal; - font-size: 90%; - } - - .subtoc { - margin-right: 34%; - font-weight: normal; - } - h5.subtoc { - margin-left: 2em; - font-size: 80%; - margin-top: 2px; - margin-bottom: 2px; - } - h6.subtoc { - margin-left: 3em; - font-size: 75%; - margin-top: 0px; - margin-bottom: 0px; - } - - div.substance { - width: 100%; - background-color: #ffffff; - } - div.ocn { - width: 5%; - float: right; - top: 0; - background-color: #ffffff; - } - div.endnote { - width: 100%; - background-color: #fffffff; - } - div.toc { - position: absolute; - float: left; - margin: 0; - padding: 0; - padding-top: 0.5em; - border: 0; - width: 5%; - background-color: #eeeeee; - margin-right:1em; - } - div.summary { - margin: 0; - padding: 0; - border-left: 2em solid #eeeeee; - padding-left: 0em; - background-color: #eeeeee; - } - div.content, div.main_column { - margin: 0; - padding: 0; - border-left: 0% solid #ffffff; - padding-left: 5%; - } - div.content:after { - content:' '; - clear:both; - display:block; - height:0; - overflow:hidden - } - div.footer { - clear:left; - padding: 0.5em; - font-size: 80%; - margin: 0; - } - div.toc ul { - list-style: none; - padding: 0; - margin: 0; - } - div.toc li ul a, li ul span.currentlink - { - font-weight: normal; - font-size: 90%; - padding-left: 2em; - background-color: #eeeeee; - } - div.toc a, span.currentlink{ - display:block; - text-decoration: none; - padding-left: 0.5em; - color: #0000aa; - } - hr { - width: 90%; - } - - span.currentlink { - text-decoration: none; - background-color: #aaaaf9; - } - - div.toc a:visited { - color: #0000aa; - } - div.toc a:hover { - color: #000000; - background-color: #f9f9aa; - } - - h1.c, h2.c, h3.c, h4.c, h5.c, h6.c, p.c { - text-align: center - } - h1.red, h2.red, h3.red, h4.red, h5.red, h6.red { - text-align: center; - color: #ff0000; - margin-left: 5mm; - text-indent: 5mm; - margin-top: 30px; - margin-bottom: 20px; - margin-right: 15mm; - } - h1.ruby, h2.ruby, h3.ruby, h4.ruby, h5.ruby, h6.ruby { - text-align: center; - color: #990000; - margin-left: 5mm; - text-indent: 5mm; - margin-top: 30px; - margin-bottom: 20px; - margin-right: 15mm; - } - WOK - end - end - module SanitizeXML - def self.xml(x) - if x.is_a?(String) - x=x.gsub(/ /,' ') if Ep[:alt]==:on - x.gsub(/&/,'&'). - gsub(//,">"). - gsub(/#{Dx[:url_o]}/,Dx[:url_o_xml]).gsub(/#{Dx[:url_c]}/,Dx[:url_o_xml]). - #gsub(//,'>'). - gsub(/\\\\/,'
'). - gsub(/<br(?: \/)?>/,'
') - else x - end - end - end - class HeadInformation - include SiSU_Viz - attr_reader :md,:rdf,:vz - def initialize(md) - @md=md - # DublinCore 1 - title - @vz=SiSU_Viz::Defaults.new - @css=SiSU_Env::CSS_Stylesheet.new(md) - @seg_name_xhtml=(SiSU_EPUB::Source::Seg.new.seg_name_xhtml || []) - @seg_name_xhtml_tracker=(SiSU_EPUB::Source::Seg.new.seg_name_xhtml_tracker || []) - @tocband_scroll,@tocband_segtoc=nil,nil - @index,@metalink='index','#metadata' - end - def doc_type_xhtml - <<-WOK - - - WOK - end -=begin -~/epub - |-- META-INF - | `-- container.xml # simple, make sure full-path of rootfile points to metadata.opf - |-- content - | |-- 1.xhtml - | |-- 2.xhtml - | |-- 3.xhtml - | |-- ... .xhtml - | |-- concordance.xhtml - | |-- css - | | `-- xhtml.css - | |-- endnotes.xhtml - | |-- image - | | |-- arrow_next_red.png - | | |-- arrow_prev_red.png - | | |-- arrow_up_red.png - | | `-- bullet_09.png - | |-- index.xhtml - | |-- meta.xhtml - | |-- metadata.xhtml - | `-- toc.xhtml - |-- metadata.opf #(i) metadata dc; (ii) manifest (contents); (iii) spine (mimetypes) - |-- mimetype # application/epub+zip - `-- toc.ncx #(i) head (ii) doc title (iii) navmap, list of navigation points (like chapters) -=end - def doc_type - doc_type_xhtml - end - def mimetype - <<-WOK -application/epub+zip - WOK - end - def metainf_container #container.xml file in META-INF directory - #simple, make sure full-path of rootfile points to metadata.opf - #epub_metadata.opf content.opf - <<-WOK - - - - - - - WOK - end - def sections(dob,fn_base) - name=fn_base + Sfx[:epub_xhtml] - dir_epub_cont=@md.env.processing_path.epub + '/' + Ep[:d_oebps] - segfilename=dir_epub_cont + '/' + name - output_epub_cont_seg=File.new(segfilename,'w') - output_epub_cont_seg << %{#{doc_type} - - - #{dob.obj} - - #{@md.html_title} - - - #{@css.xhtml_epub} - - #{@vz.color_body} -
-
- #{dob.ocn} -

- #{dob.obj} -

-
-
- - } -output_epub_cont_seg.close - end - def toc_ncx #list of navigation points (like chapters), table of contents, listing each navigation point (chapters and such) under the navigation map - def structure - open - head_open - head - head_close - doc_title - doc_author - navmap_open - #navmap ... - navmap_close - close - end - def open - <<-WOK - - - WOK - end - def close - <<-WOK - - WOK - end - def head_open - <<-WOK - - WOK - end - def head - depth=@md.lvs[1] + @md.lvs[2] + @md.lvs[3] + @md.lvs[4] - title=SanitizeXML.xml(@md.title.full) - author=SanitizeXML.xml(@md.author) - <<-WOK - - #{title} by #{author} - - - - - - - WOK - end - def head_close - <<-WOK - - WOK - end - def doc_title - txt=SanitizeXML.xml(@md.title.full) - <<-WOK - - #{txt} - - WOK - end - def doc_author - txt=SanitizeXML.xml(@md.author) - <<-WOK - - #{txt} - - WOK - end - def navmap_open - <<-WOK - - WOK - end - def navmap_sisu_toc(no) - id_u=DISABLE[:epub][:ncx_navpoint_unique_id] \ - ? '' - : "-#{no}" - <<-WOK - - - Table of Contents - - - - WOK - end - def navpoint(dob,no,fn_base,hashtag=nil) - fn=fn_base + Sfx[:epub_xhtml] - name=hashtag ? fn + hashtag : fn - id_u=DISABLE[:epub][:ncx_navpoint_unique_id] \ - ? '' - : "-#{no}" - <<-WOK - - - #{dob.obj} - - - WOK - end - def navpoint_close - <<-WOK - - WOK - end - def navmap_close - <<-WOK - - WOK - end - self - end - def metadata_opf #(i) metadata dc; (ii) manifest (contents); (iii) spine (mimetypes) - def structure - package_open - metadata_open - metadata_close - manifest_open - manifest_close - spine_open - spine_close - guide_open - guide_close - package_close - end - def package_open - <<-WOK - - - WOK - end - def package_close - <<-WOK - - WOK - end - def metadata #metadata dc - cover_image=if defined? @md.make.cover_image \ - and @md.make.cover_image.is_a?(Hash) \ - and @md.make.cover_image[:cover] =~/\S+/ - %{\n <#{$ep[:o]}meta name="cover" content="cover_image" />} - else '' - end - author=if defined? @md.creator.author \ - and @md.creator.author =~/\S+/ - m='' - @md.creator.author_detail.each do |i| - surname=i[:the] \ - ? i[:the] - : '' - other_names=i[:others] \ - ? ', ' + i[:others] - : '' - m=(m.empty?) \ - ? (surname + other_names) - : (m + '; ' + surname + ', ' + other_names) - m=SanitizeXML.xml(m) - end - x=@md.creator.author.dup - x=SanitizeXML.xml(x) - %{\n #{x}} - else '' - end - editor=if defined? @md.creator.editor \ - and @md.creator.editor =~/\S+/ - m='' - @md.creator.editor_detail.each do |i| - surname=i[:the] \ - ? i[:the] - : '' - other_names=i[:others] \ - ? ', ' + i[:others] - : '' - m=(m.empty?) \ - ? (surname + other_names) - : (m + '; ' + surname + ', ' + other_names) - m=SanitizeXML.xml(m) - end - x=@md.creator.editor.dup - x=SanitizeXML.xml(x) - %{\n #{x}} - else '' - end - translator=if defined? @md.creator.translator \ - and @md.creator.translator =~/\S+/ - m='' - @md.creator.translator_detail.each do |i| - surname=i[:the] \ - ? i[:the] - : '' - other_names=i[:others] \ - ? ', ' + i[:others] - : '' - m=(m.empty?) \ - ? (surname + other_names) - : (m + '; ' + surname + ', ' + other_names) - m=SanitizeXML.xml(m) - end - x=@md.creator.translator.dup - x=SanitizeXML.xml(x) - %{\n #{x}} - else '' - end - illustrator=if defined? @md.creator.illustrator \ - and @md.creator.illustrator =~/\S+/ - m='' - @md.creator.illustrator_detail.each do |i| - surname=i[:the] \ - ? i[:the] - : '' - other_names=i[:others] \ - ? ', ' + i[:others] - : '' - m=(m.empty?) \ - ? (surname + other_names) - : (m + '; ' + surname + ', ' + other_names) - m=SanitizeXML.xml(m) - end - x=@md.creator.illustrator.dup - x=SanitizeXML.xml(x) - %{\n #{x}} - else '' - end - date_published=if defined? @md.date.published \ - and @md.date.published =~/\S+/ - x=@md.date.published.dup - x=SanitizeXML.xml(x) - %{\n #{x}} - else '' - end - subject=if defined? @md.classify.subject \ - and @md.classify.subject =~/\S+/ - x=@md.classify.subject.dup - x=SanitizeXML.xml(x) - %{\n #{x}} - else '' - end - language=if defined? @md.opt.lng \ - and @md.opt.lng =~/\S+/ - language=@md.opt.lng.gsub(/
/,'
') - %{\n #{language}} - else '' - end - rights=if defined? @md.rights.all \ - and @md.rights.all =~/\S+/ - rights=SanitizeXML.xml(@md.rights.all) - rights=rights.gsub(//,' ') - %{\n #{rights}} - else '' - end - f=SiSU_Env::FileOp.new(@md) - <<-WOK - <#{$ep[:o]}metadata - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xmlns:opf="http://www.idpf.org/2007/opf" - xmlns:dcterms="http://purl.org/dc/terms/" - xmlns:dc="http://purl.org/dc/elements/1.1/" - unique-identifier="urn:uuid:#{@md.dgst[1]}" version="2.0"> - #{@md.title.full} - #{cover_image}#{author}#{editor}#{translator}#{illustrator}#{language}#{date_published}#{subject}#{rights} - #{f.output_path.epub.url.gsub(/http:\/\//,'')}/#{f.base_filename.epub} - urn:uuid:#{@md.dgst[1]} - - - WOK - end - def manifest_open - <<-WOK - - - - - - - WOK - end - def manifest_content_sisu_toc - <<-WOK - - WOK - end - def manifest_cover_image_information(md) - if defined? md.make.cover_image \ - and @md.make.cover_image.is_a?(Hash) \ - and md.make.cover_image[:cover] =~/\S+/ - <<-WOK - - WOK - else '' - end - end - def manifest_content(dob,fn_base,hashtag=nil) - fn=fn_base + Sfx[:epub_xhtml] - name=hashtag ? fn + hashtag : fn - <<-WOK - - WOK - end - def manifest_images(imgs) - imgs=imgs + ['arrow_next_red.png','arrow_prev_red.png','arrow_up_red.png','bullet_09.png'] - images=[" \n"] - imgs.each do |i| - image,type=/(\S+?)\.(png|jpg|gif)/.match(i)[1,2] - type=type.sub(/jpg/,'jpeg') - images<<<<-WOK - - WOK - end - images=images.join('') - images - end - def manifest_close - <<-WOK - - WOK - end - def spine_open - #spine: reading order of XHTML files from manifest, idref attribute refers back to id in manifest (exclude images, CSS etc.). - <<-WOK - - WOK - end - def spine_cover_image - <<-WOK - - WOK - end - def spine_sisu_toc - <<-WOK - - WOK - end - def spine(dob,fn_base,hashtag=nil) - fn=fn_base + Sfx[:epub_xhtml] - name=hashtag ? fn + hashtag : fn - <<-WOK - - WOK - end - def spine_close - <<-WOK - - WOK - end - def guide_open - #guide: presentation order of XHTML files by reader). - <<-WOK - - WOK - end - def guide_cover_image - <<-WOK - - WOK - end - def guide_sisu_toc - <<-WOK - - WOK - end - def guide(dob,fn_base,hashtag=nil) - fn=fn_base + Sfx[:epub_xhtml] - name=hashtag ? fn + hashtag : fn - name=name ? name : dob.name - guide_name=(name =~/#{Sfx[:epub_xhtml]}/) ? name : (name + Sfx[:epub_xhtml]) - <<-WOK - - WOK - end - def guide_close - <<-WOK - - WOK - end - self - end - def table_close - %{ -#{@vz.table_close}} - end - def xhtml_close - %{#{@vz.credits_sisu_epub} - -} - end - end - class HeadToc < HeadInformation - def initialize(md) - super(md) - @md=md - @tocband_segtoc=make_seg - end - def manifest_link(text) - %{ #{text}} - end - def concordance_link(text) - if @md.concord_make - %{ - #{text} - } - else '' - end - end - def head - %{#{doc_type} - - - #{@css.xhtml_epub} - - #{@vz.color_body}} - end - def concordance - if @md.concord_make - %{#{@vz.margin_css} -

- - Concordance - -

-#{@vz.table_close}} - else - %{#{@vz.margin_css} -#{@vz.table_close}} - end - end - def links_guide_open(type='horizontal') - (type=='vertical') \ - ? links_guide_vertical_open - : links_guide_horizontal_open - end - def prefix_a - end - def rights - def all - rights=SanitizeXML.xml(@md.rights.all) - %{

Rights: #{rights}

} - end - self - end - def prefix_b - %{

Prefix: #{@md.prefix_b}} - end - def make_seg - concord=concordance_link(@vz.nav_txt_concordance) - %{ - -
- #{@vz.nav_txt_toc_link} - - - #{concord} -#{@vz.table_close}} - end - def manifest #check structure - manifest=manifest_link(@vz.nav_txt_manifest) - %{#{@vz.margin_txt_3} - #{@vz.paragraph_font_small} - #{manifest} - -#{@vz.table_close}} - end - def concordance #check structure - concord=concordance_link(@vz.nav_txt_concordance) - %{#{@vz.margin_txt_3} - #{@vz.paragraph_font_small} - #{concord} - -#{@vz.table_close}} - end - def metadata - %{#{@vz.margin_css} -

- - MetaData - -

-#{@vz.table_close}} - end - end - class HeadSeg < HeadInformation - def initialize(md) - super(md) - end - def head - %{#{doc_type} - - - #{@seg_name_xhtml[@seg_name_xhtml_tracker]} - - #{@md.html_title} - - - #{@css.xhtml_epub} - - #{@vz.color_body}} - end - def endnote_mark -%{ -
-} - end - end - class HeadScroll < HeadToc - def initialize(md) - super(md) - end - def toc_owner_details - %{#{@vz.margin_txt_3} -#{@vz.paragraph_font_small} - - Owner Details - - #{$ep[:hsp]*3} - - - -#{@vz.table_close}} - end - end - class FormatTextObject - @vz=SiSU_Viz::Defaults.new - attr_accessor :md,:t_o,:txt,:ocn,:format,:table,:link,:linkname,:paranum,:p_num,:headname,:banner,:url - def initialize(md,t_o) - @md,@t_o=md,t_o - if t_o.is_a?(Hash) - @txt =t_o[:txt] || nil - @ocn =t_o[:ocn] || nil - @ocn_display =t_o[:ocn_display] || nil - @headname =t_o[:headname] || nil - @trailer =t_o[:trailer] || nil - @endnote_part_a =t_o[:endnote_part_a] || nil - @endnote_part_b =t_o[:endnote_part_b] || nil - @lnk_url =t_o[:lnk_url] || nil - @lnk_txt =t_o[:lnk_txt] || nil - @format =t_o[:format] || nil - @target =t_o[:target] || nil #occasionally passed but not used - if @format and not @format.empty? - if @format=~/^\d:(\S+)/ #need more reliable marker #if @format =~ /#{Rx[:lv]}/ - headname=$1 #format[/\d~(\S+)/m,1] - @headname=(headname =~/^[a-zA-Z]/) \ - ? %{} - : %{} - @headname=(headname =~/^[a-zA-Z]/) \ - ? %{} - : %{} - end - end - elsif t_o.class.inspect =~/Object/ - @dob=t_o if defined? t_o.is - @named=nametags_seg(@dob) - @txt=((defined? t_o.obj) ? t_o.obj : nil) - @ocn=((defined? t_o.ocn) ? t_o.ocn.to_s : nil) - @headname=((t_o.is==:heading and defined? t_o.name) ? t_o.name : nil) - else - if @md.opt.act[:maintenance][:set]==:on - p __FILE__ << ':' << __LINE__.to_s - p t_o.class - p caller - end - end - if @txt and not @txt.empty? - @txt=@txt.gsub(/#{Mx[:mk_o]}[-~]##{Mx[:mk_c]}/,'') - end - @p_num=ParagraphNumber.new(@md,@ocn) - @vz=SiSU_Viz::Defaults.new - end - def nametags_seg(dob) #FIX - tags='' - if defined? dob.tags \ - and dob.tags.length > 0 # insert tags "hypertargets" - dob.tags.each do |t| - tags=tags << %{} - end - end - tags - end - def endnote_body - %{ -

- #{@txt} -

-} - end - def endnote_body_indent - %{ -

- #{@txt} -

-} - end - def no_paranum - %{ -
- -

- #{@txt} -

-
-} - end - def para_form_css(tag,attrib,txt) # regular paragraphs shaped here - ul=ulc='' - ul,ulc="
    \n ","\n
" if @tag =~/li/ - %{ -
- #{@p_num.ocn_display} - #{ul}<#{tag} class="#{attrib}" #{@p_num.id}> - #{@named}#{txt} - #{ulc} -
-} - end - def para - para_form_css('p','norm',@txt) - end - def group - para_form_css('p','group',@txt) - end - def block - para_form_css('p','block',@txt) - end - def alt - para_form_css('p','alt',@txt) - end - def verse - para_form_css('p','verse',@txt) - end - def code - para_form_css('p','code',@txt) - end - def center - para_form_css('p','center',@txt) - end - def bold - para_form_css('p','bold',@txt) - end - def bullet - para_form_css('li','bullet',@txt) - end - def table - @txt=if @t_o.obj !~/^
'). - gsub(/#{Mx[:br_obj]}/,'

') - para_form_css('p','norm',@txt) - end - def format(tag,attrib) - para_form_css(tag,attrib,@txt) - end - def title_heading(tag,attrib) - %{ -
-<#{tag} class="#{attrib}"> - #{@named}#{@txt} - -
-} - end - def title_heading1 - DISABLE[:epub][:per_section_title] \ - ? '' - : title_heading('h1','tiny') - end - def title_heading2 - DISABLE[:epub][:per_section_title] \ - ? '' - : title_heading('h2','tiny') - end - def title_heading3 - DISABLE[:epub][:per_section_title] \ - ? '' - : title_heading('h3','tiny') - end - def title_heading4 - '' - end - def seg_heading_sub(tag,attrib,txt) - txt=txt.gsub(/(?:#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]})\s*/m,' ') - %{ -
- #{@p_num.ocn_display} - <#{tag} class="#{attrib}" #{@p_num.id}>#{@p_num.name} - #{@named}#{@txt} - -
-} - end - def seg_heading4 - %{ -
- #{@p_num.ocn_display} -

- #{@txt} -

-
-} - end - def seg_heading5 - seg_heading_sub('p','bold',@txt) - end - def seg_heading6 - seg_heading_sub('p','bold',@txt) - end - def dl #check :trailer - "
#{@txt} #{@trailer}
" - end - def table_css_end - '
-

- ' - end - def gsub_body #unused - @txt=case @txt - when /^(?:#{Mx[:pa_o]}i[1-9]#{Mx[:pa_c]}\s*)?\((i+|iv|v|vi+|ix|x|xi+)\)/ - @txt.gsub(/^\((i+|iv|v|vi+|ix|x|xi+)\)/,'(\1)'). - gsub(/^(#{Mx[:pa_o]}i[1-9]#{Mx[:pa_c]})\s*\((i+|iv|v|vi+|ix|x|xi+)\)/,'\1(\2)') - when /^(?:#{Mx[:pa_o]}i[1-9]#{Mx[:pa_c]}\s*)?\(?(\d|[a-z])+\)/ - @txt.gsub(/^\((\d+|[a-z])+\)/,'(\1)'). - gsub(/^(#{Mx[:pa_o]}i[1-9]#{Mx[:pa_c]})\s*\((\d+|[a-z])+\)/,'\1(\2)') - when /^\s*\d{1,3}\.\s/ - @txt.gsub(/^\s*(\d+\.)/,'\1') - when /^\s*[A-Z]\.\s/ - @txt.gsub(/^\s*([A-Z]\.)/,'\1') - else @txt - end - end - def bold_para - %{#{@vz.margin_txt_0} -

- #{@txt} -

-#{@vz.margin_num_css} - #{$ep[:hsp]*3} -#{@vz.table_close}} - end - def bold_heading #unused - @txt=@txt.gsub(/[1-9]~\S+/,''). - gsub(/[1-9]~/,'') - %{

- #{@txt} -

-#{@vz.margin_num_css} - #{$ep[:hsp]*3} -#{@vz.table_close}} - end - def toc_head_copy_at - @txt=SanitizeXML.xml(@txt) - %{

#{@txt}

\n} - end - def center - @txt=SanitizeXML.xml(@txt) - %{

#{@txt}

\n} - end - def bold - @txt=SanitizeXML.xml(@txt) - %{

#{@txt}

\n} - end - def center_bold - @txt=SanitizeXML.xml(@txt) - %{

#{@txt}

\n} - end - end - class FormatScroll < FormatTextObject - def initialize(md,txt) - super(md,txt) - @vz=SiSU_Viz::Defaults.new - end - end - class FormatSeg < FormatTextObject - def initialize(md,txt) - super(md,txt) - end - def endnote_seg_body(fn='') #FIX #url construction keep within single line... BUG WATCH 200408 - fn='doc' if fn.to_s.empty? #you may wish to reconsider, sends to 'doc' where no segment info - %{ -

- #{@endnote_part_a}#{fn}#{Sfx[:epub_xhtml]}#{@endnote_part_b} -

-} - end - def clean(txt) - txt=txt.gsub(/#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}/,''). - gsub(/#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]}/,'') - end - def subtoc_lev(tag,attrib) - @txt=clean(@txt) - txt=if @txt \ - and @txt =~/<\/?i>|/mi - @txt.gsub(/<\/?i>|/mi,'') #removes name markers from subtoc, go directly to substantive text - else @txt - end - note='' - if txt =~/(#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]})/m # had \s* at end - note=$1 - note=note.gsub(/[\n\s]+/m,' ') - txt=txt.gsub(/(?:#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]})\s*/m,' '). - gsub(/#{$ep[:hsp]}\d+<\/sup>#{$ep[:hsp]}/m,''). - gsub(/#{$ep[:hsp]}\d+<\/sup>#{$ep[:hsp]}/m,'') #remove - end - %{<#{tag} class="#{attrib}"> - #{txt} #{note} - } - end - def subtoc_lev5 - subtoc_lev('h5','subtoc') if @txt - end - def subtoc_lev6 - subtoc_lev('h6','subtoc') if @txt - end - def heading_sub(tag,attrib,txt) - txt=txt.gsub(/(?:#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]})\s*/m,' ') - %{ -
- #{@p_num.ocn_display} - <#{tag} class="#{attrib}" #{@p_num.id}> #{@headname} - #{@txt} - -
-} - end - def heading4 - %{ -
- #{@p_num.ocn_display} -

- #{@t_o[:format]} - #{@txt} -

-
-} - end - def heading5 - heading_sub('p','bold',@txt) - end - def heading6 - heading_sub('p','bold',@txt) - end - def navigation_heading4 - %{ -
-

- #{@txt} -

-#{@vz.table_close}} - end - def navigation_heading5 - %{

- #{@txt} -

} - end - def navigation_heading6 - %{

- #{@txt} -

} - end - def navigation_center - %{

#{@txt}

} - end - end - class FormatToc < FormatTextObject - def initialize(md,txt) - super(md,txt) - end - def links_guide - %{
  • - - #{@lnk_txt} - -
  • -} - end - def lev(tag,attrib) - if @txt - %{<#{tag} class="#{attrib}"> - #{@txt} - -} - else '' - end - end - def lev1 - lev('h1','toc') - end - def lev2 - lev('h2','toc') - end - def lev3 - lev('h3','toc') - end - def lev4 - lev('h4','toc') - end - def lev5 - lev('h5','toc') - end - def lev6 - lev('h6','toc') - end - def lev0 #docinfo - lev('h0','toc') - end - end -end -__END__ diff --git a/lib/sisu/v5/epub_segments.rb b/lib/sisu/v5/epub_segments.rb deleted file mode 100644 index 16e26855..00000000 --- a/lib/sisu/v5/epub_segments.rb +++ /dev/null @@ -1,543 +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: epub segment generation, processing - -=end -module SiSU_EPUB_Seg - require_relative 'shared_xhtml' # shared_xhtml.rb - require_relative 'epub' # epub.rb - require_relative 'shared_metadata' # shared_metadata.rb - class Output - def initialize(md,outputfile,seg,type='') - @md,@output_epub_cont_seg,@seg,@type=md,outputfile,seg,type - end - def output #CONSIDER - if @seg[:title] =~/\S/ - filename_seg=[] - filename_seg << @seg[:title] << @seg[:nav] - if @type=='endnotes' - @seg[:headings]=[] #watch - txt_obj={ txt: 'Endnotes', ocn_display: ''} - format_seg=SiSU_EPUB_Format::FormatSeg.new(@md,txt_obj) - @seg[:headings] << format_seg.title_heading1 - filename_seg << @seg[:heading_endnotes] << @seg[:headings] << %{\n
    \n} << @seg[:endnote_all] << '
    ' - elsif @type=='idx' - @seg[:headings]=[] - format_seg=SiSU_EPUB_Format::FormatSeg.new(@md,txt_obj) - @seg[:headings] << format_seg.title_heading1 - filename_seg << @seg[:heading_idx] << @seg[:headings] << %{\n
    \n} << @seg[:idx] << '
    ' - elsif @type=='metadata' - metadata=SiSU_Metadata::Summary.new(@md).xhtml_display.metadata - @seg[:headings]=[] - txt_obj={ txt: 'Metadata', ocn_display: ''} - format_seg=SiSU_EPUB_Format::FormatSeg.new(@md,txt_obj) - @seg[:headings] << format_seg.title_heading1 - filename_seg << @seg[:heading_idx] << @seg[:headings] << %{\n
    \n} << metadata << '
    ' - elsif @type=='sisu_manifest' - env=SiSU_Env::InfoEnv.new(@md.fns) - path_and_name,url_and_name="#{env.path.output}/#{@md.fnb}/sisu_manifest.html","#{env.url.root}/#{@md.fnb}/sisu_manifest.html" - manifest=if FileTest.file?("#{path_and_name}")==true - <A list of available output types may be available at the following url:

    -

    #{url_and_name}

    -WOK - else '' - end - @seg[:headings]=[] - txt_obj={ txt: 'Manifest', ocn_display: ''} - format_seg=SiSU_EPUB_Format::FormatSeg.new(@md,txt_obj) - @seg[:headings] << format_seg.title_heading1 - filename_seg << @seg[:heading_idx] << @seg[:headings] << %{\n
    \n} << manifest << '
    ' - else - filename_seg << @seg[:headings] << @seg[:main] << "\n\n" - end - filename_seg << @seg[:tail] << @seg[:nav] << @seg[:close] - filename_seg=filename_seg.flatten.compact #watch - filename_seg.each do |str| - unless str =~/\A\s*\Z/ - @output_epub_cont_seg << str.strip - end - end - @output_epub_cont_seg.close - end - end - end - class Seg - @@seg,@@seg_subtoc,@@seg_endnotes,@@seg_ad={},{},{},{} - @@seg_name,@@seg_name_xhtml=[],[] - @@seg_url=@@fn=@@get_hash_to=@@get_hash_fn='' - @@loop_count=@@seg_total=@@tracker=0 - @@is4=@@is3=@@is2=@@is1=0 - @@heading1=@@heading2=@@heading3=@@heading4=0 - @@seg[:headings],@@seg[:main],@@seg[:idx],@@seg[:tail],@@seg_subtoc_array,@@seg_endnotes_array,@@seg[:endnote_all]=Array.new(7){[]} - @@seg[:heading_endnotes]='' - @@tablehead,@@number_of_cols=0,0 - @@fns_previous='' - attr_reader :seg_name_xhtml,:seg_name_xhtml_tracker - def initialize(md='',data='') - @md,@data=md,data - @vz=SiSU_Viz::Defaults.new - @seg_name_xhtml=@@seg_name_xhtml || nil - @seg_name_xhtml_tracker=@@tracker || nil - @make=SiSU_Env::ProcessingSettings.new(@md) if @md - end - def songsheet - begin - data=get_subtoc_endnotes(@data) - data=articles(data) - SiSU_EPUB_Seg::Seg.new.cleanup # (((( added )))) - #### (((( END )))) #### - rescue - SiSU_Errors::Rescued.new($!,$@,@md.opt.cmd,@md.fns).location do - __LINE__.to_s + ':' + __FILE__ - end - ensure - @@seg_name=[] - end - end - protected - def articles(data) - tracking,newfile=0,0 - @@is4=@@is3=@@is2=@@is1=0 - printed_endnote_seg='n' - idx_xhtml=nil - if @md.book_idx - idx_xhtml=SiSU_Particulars::CombinedSingleton.instance.get_idx_xhtml(@md).xhtml_idx - idx_xhtml.each {|x| @@seg[:idx] << x } - @@seg[:heading_idx]='' - end - data.each do |dob| - if (dob.is==:heading \ - || dob.is==:heading_insert) \ - and dob.ln==4 - @@seg_name << dob.name - dob.name - end - end - @@seg_name_xhtml=@@seg_name - @@seg_total=@@seg_name.length - testforartnum=@@seg_name_xhtml - if (@md.opt.act[:verbose][:set]==:on \ - || @md.opt.act[:verbose_plus][:set]==:on \ - || @md.opt.act[:maintenance][:set]==:on) - SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set],@@seg_name.length) - end - SiSU_Particulars::CombinedSingleton.instance.get_map_nametags(@md).nametags_map #p map_nametags - data.each do |dob| - #if defined? dob.obj \ - #and dob.obj =~/href="#{Xx[:segment]}#+\S+?"/ - # ##Consider: remove, reinstate earlier? - # #while dob.obj =~/href="#{Xx[:segment]}#+(\S+?)"/ - # # m=$1 - # # if map_nametags[m][:segname] - # # dob.obj=dob.obj.sub(/href="#{Xx[:segment]}#+(\S+?)"/,%{href="#{map_nametags[m][:segname]}#{Sfx[:html]}#\\1"}) - # # else - # # p "NOT FOUND name_tags: #{m}" - # # dob.obj=dob.obj.sub(/href="#{Xx[:segment]}#+(\S+?)"/,%{href="#\\1"}) # not satisfactory - # # end - # #end - #end - if (dob.is==:heading \ - || dob.is==:heading_insert) \ - and dob.ln==4 - if dob.ocn==0 - @@heading4=dob.obj - else @@heading4=dob.obj - end - @@is4=newfile=1 - end - if (dob.is==:heading \ - || dob.is==:heading_insert) \ - and dob.ln==3 - @@heading3=dob.obj - @@is4,@@is3=0,1 - end - if (dob.is==:heading \ - || dob.is==:heading_insert) \ - and dob.ln==2 - @@heading2=dob.obj - @@is4,@@is3,@@is2=0,0,1 - end - if (dob.is==:heading \ - || dob.is==:heading_insert) \ - and dob.ln==1 - @@heading1=dob.obj - @@is4,@@is3,@@is2,@@is1=0,0,0,1 - end - if (@@is1 && !@@is2 && !@@is3 && !@@is4) - if not (dob.is==:heading \ - || dob.is==:heading_insert) \ - and dob.ln==1 - $_ #; check - end - end - if @@is4==1 - dir_epub_cont="#{@md.env.processing_path.epub}/#{Ep[:d_oebps]}" - if newfile==1 \ - or dob.obj =~/^#{Mx[:br_endnotes]}|^#{Mx[:br_eof]}/ - newfile=0 - if (dob.is==:heading \ - || dob.is==:heading_insert) \ - and dob.ln==4 - if tracking != 0 - SiSU_EPUB_Seg::Seg.new(@md).tail - segfilename="#{dir_epub_cont}/#{@@seg_name_xhtml[tracking-1]}#{Sfx[:epub_xhtml]}" - output_epub_cont_seg=File.new(segfilename,'w') if @@seg_name_xhtml[tracking-1] - if dob.is==:heading \ - or @@seg_name_xhtml[tracking-1] !~/endnotes|book_index|metadata/ - SiSU_EPUB_Seg::Output.new(@md,output_epub_cont_seg,@@seg).output - elsif dob.is==:heading_insert - if @@seg_name_xhtml[tracking-1]=='endnotes' - SiSU_EPUB_Seg::Output.new(@md,output_epub_cont_seg,@@seg,'endnotes').output - elsif @@seg_name_xhtml[tracking-1]=='book_index' - SiSU_EPUB_Seg::Output.new(@md,output_epub_cont_seg,@@seg,'idx').output - @@seg[:idx]=[] - elsif @@seg_name_xhtml[tracking-1]=='metadata' # navigation bug FIX - SiSU_EPUB_Seg::Output.new(@md,output_epub_cont_seg,@@seg,'metadata').output - else puts "#{__FILE__}::#{__LINE__}" - end - else puts "#{__FILE__}::#{__LINE__}" - end - SiSU_EPUB_Seg::Seg.new.reinitialise - heading_art(dob) - head(dob) - if @@seg_name_xhtml[tracking] =='metadata' - segfilename="#{dir_epub_cont}/#{@@seg_name_xhtml[tracking]}#{Sfx[:epub_xhtml]}" - output_epub_cont_seg=File.new(segfilename,'w') - SiSU_EPUB_Seg::Output.new(@md,output_epub_cont_seg,@@seg,'metadata').output - SiSU_EPUB_Seg::Seg.new.reinitialise #BUG navigation bug with items following metadata, and occurring before manifest, this becomes a bug ... work area for book index, FIX - end - #@output_epub_cont_seg.close #%(((( EOF )))) --> - end - if tracking==0 - heading_art(dob) - head(dob) - end - end - tracking=tracking+1 - end - if (dob.is==:heading \ - || dob.is==:heading_insert) \ - and dob.ln==4 \ - and dob.name - @@get_hash_to=dob.name - @@get_hash_fn=dob.name - end - if dob.obj.is_a?(String) - markup(dob) - elsif dob.obj.is_a?(Array) - dob.obj.each do |pg| - markup(pg) - end - end - if testforartnum[tracking-1] =~/endnote/ - if printed_endnote_seg=='n' - printed_endnote_seg='y' - end - end - end - end - data - end - def heading_art(dob) - @@seg[:title]=SiSU_EPUB_Format::HeadSeg.new(@md).head - end - def head(dob) - clean=/|<:.*?>$/ - @p_num ||= '' - if @@is1==1 - if defined? @md.creator.author \ - and @md.creator.author - @author=%{#{@md.creator.author}\n} - end - ocn=(@@heading1[/.+?#{Mx[:id_o]}~(\d+);(?:[oh]|[0-6]:)\d+;\w\d+#{Mx[:id_c]}#{Mx[:id_o]}#{@dp}:#{@dp}#{Mx[:id_c]}$/]) \ - ? $1 - : '' - @p_num=SiSU_EPUB_Format::ParagraphNumber.new(@md,ocn) - txt_obj={ txt: @@heading1, ocn_display: @p_num.ocn_display } - format_seg=SiSU_EPUB_Format::FormatSeg.new(@md,txt_obj) - @@seg[:headings] << format_seg.title_heading1.gsub(clean,'') - @@heading1=@@heading1.gsub(/#{$ep[:hsp]}#{$ep[:hsp]}[\d*+]+<\/sup>#{$ep[:hsp]}<\/a>/,'') - end - if @@is2==1 - heading2=@@heading2 - ocn=(heading2[/.+?#{Mx[:id_o]}~(\d+);(?:[oh]|[0-6]:)\d+;\w\d+#{Mx[:id_c]}#{Mx[:id_o]}#{@dp}:#{@dp}#{Mx[:id_c]}$/]) \ - ? $1 - : '' - @p_num=SiSU_EPUB_Format::ParagraphNumber.new(@md,ocn) - txt_obj={ txt: heading2, ocn_display: @p_num.ocn_display } - format_seg=SiSU_EPUB_Format::FormatSeg.new(@md,txt_obj) - @@seg[:headings] << format_seg.title_heading2.gsub(clean,'') - @@heading2=@@heading2.gsub(/#{$ep[:hsp]}#{$ep[:hsp]}[\d*+]+<\/sup>#{$ep[:hsp]}<\/a>/,'') - end - if @@is3==1 - heading3=@@heading3 - ocn=(heading3[/.+?#{Mx[:id_o]}~(\d+);(?:[oh]|[0-6]:)\d+;\w\d+#{Mx[:id_c]}#{Mx[:id_o]}#{@dp}:#{@dp}#{Mx[:id_c]}$/]) \ - ? $1 - : '' - @p_num=SiSU_EPUB_Format::ParagraphNumber.new(@md,ocn) - txt_obj={ txt: heading3, ocn_display: @p_num.ocn_display } - format_seg=SiSU_EPUB_Format::FormatSeg.new(@md,txt_obj) - @@seg[:headings] << format_seg.title_heading3.gsub(clean,'') - @@heading3=@@heading3.gsub(/#{$ep[:hsp]}#{$ep[:hsp]}[\d*+]+<\/sup>#{$ep[:hsp]}<\/a>/,'') - end - if @@is4==1 - heading4=@@heading4 - ocn=(heading4[/.+?#{Mx[:id_o]}~(\d+);(?:[oh]|[0-6]:)\d+;\w\d+#{Mx[:id_c]}#{Mx[:id_o]}#{@dp}:#{@dp}#{Mx[:id_c]}$/]) \ - ? $1 - : '' - @p_num=SiSU_EPUB_Format::ParagraphNumber.new(@md,ocn) - txt_obj={ txt: heading4, ocn_display: @p_num.ocn_display } - format_seg=SiSU_EPUB_Format::FormatSeg.new(@md,txt_obj) - @@seg[:headings] << format_seg.title_heading4.gsub(clean,'') - end - @@tracker=@@tracker+1 - end - def markup(dob) - @debug=[] - if dob.is ==:heading \ - || dob.is ==:heading_insert \ - || dob.is ==:para - #extend as necessary FIX - @p_num=SiSU_EPUB_Format::ParagraphNumber.new(@md,dob.ocn) - end - sto=SiSU_EPUB_Format::FormatTextObject.new(@md,dob) - dob_xhtml=if dob.is==:heading \ - || dob.is==:heading_insert \ - || dob.is==:para - dob_xhtml=if dob.is==:heading \ - or dob.is==:heading_insert - if dob.ln==4 - sto.seg_heading4 # work on see SplitTextObject - elsif dob.ln==5 - sto.seg_heading5 - elsif dob.ln==6 - sto.seg_heading6 - end - elsif dob.is==:para - if dob.indent \ - and dob.hang \ - and dob.indent =~/[0-9]/ \ - and dob.hang =~/[0-9]/ - if dob.bullet_ - (dob.indent =~/[1-9]/) \ - ? sto.format('li',"i#{dob.indent}") - : sto.format('li','bullet') - elsif dob.indent == dob.hang - sto.format('p',"i#{dob.indent}") - elsif dob.indent != dob.hang - sto.format('p',"h#{dob.hang}i#{dob.indent}") - else sto.para - end - else sto.para - end - end - elsif dob.is ==:block \ - || dob.is ==:group \ - || dob.is ==:alt - sto.para #fix this should be block type specific #FIX - elsif dob.is==:verse - sto.verse - elsif dob.is==:code - sto.code - elsif dob.is==:table - sto.table - elsif dob.is==:break - sto.break - end - if @md.flag_separate_endnotes # may need to revisit, check - dob.obj=dob.obj.gsub(/"\s+href="#note_ref(\d+)">/,%{" href=\"endnotes#{Sfx[:epub_xhtml]}#note_ref\\1">}) #endnote- twice #removed file type - end - if (dob.is ==:heading \ - || dob.is==:heading_insert \ - || dob.is==:para) \ - && (not dob.ocn or dob.ocn.to_s.empty?) - format_seg=SiSU_EPUB_Format::FormatSeg.new(@md,dob) - end - if (dob.is==:heading \ - || dob.is==:heading_insert \ - || dob.is==:para) \ - and dob.note_ #dob.obj =~/ \n} - @@seg[:main] << dob_xhtml - if @make.build.segsubtoc? - @@seg[:main] << @@seg_subtoc[@@get_hash_fn] #% insertion of sub-toc - end - else - @@seg[:main] << dob_xhtml - end - end - def tail - format_head_seg=SiSU_EPUB_Format::HeadSeg.new(@md) - if @md.flag_auto_endnotes \ - and @@seg_endnotes[@@get_hash_fn] - @@seg[:tail] << %{\n
    \n
    \n} - if @@seg_endnotes[@@get_hash_fn].flatten.length > 0 - @@seg[:tail] << format_head_seg.endnote_mark - @@seg[:tail] << @@seg_endnotes[@@get_hash_fn].flatten #endnotes deposited at end of individual segments ||@|EXTRACTION OF ENDNOTES| - end - @@seg[:tail] << '
    ' - @@seg[:tail] << '
    ' #this div closes div class content - end - @@seg[:close]=[] - @@seg[:close] << format_head_seg.xhtml_close - end - def reinitialise - @@seg[:headings],@@seg[:main],@@seg[:tail],@@seg[:credits]=Array.new(4){[]} - end - def cleanup - reinitialise - @@seg_total,@@tracker=0,0 - @@seg_endnotes,@@seg_subtoc={},{} - @@seg_endnotes_array,@@seg_subtoc_array=[],[] - @@seg[:endnote_all]=[] - end - def get_subtoc_endnotes(data) #get endnotes & sub-table of contents subtoc - data.each do |dob| - dob.obj=dob.obj.gsub(/
    (.+?)<\/a>/mi,'\1') - if @md.flag_auto_endnotes - if (dob.is==:heading \ - || dob.is==:heading_insert) \ - and dob.ln.to_s =~/^[1234]/ \ - and not @@fn.to_s.empty? - @@seg_endnotes[@@fn]=[] - @@seg_endnotes[@@fn] << @@seg_endnotes_array - @@seg_endnotes_array=[] if dob.ln==4 - @@fns_previous=@md.fns if dob.ln==4 and dob.name =~/^meta/ - end - if (dob.is==:heading \ - || dob.is==:heading_insert) \ - and dob.ln==4 #% EXTRACTION OF SUB-TOCs & SEGMENT NAME, after EXTRACTION OF ENDNOTES & SUB-TOCs - @@seg_subtoc[@@fn]=@@seg_subtoc_array - @@seg_subtoc_array=[] - if dob.name \ - and dob.obj - @@fn=dob.name - else - @@fn=(dob.name =~/\S+/) \ - ? dob.name - : '' - end - end - end - if dob.is==:heading \ - and dob.ln.to_s =~/^[56]/ - case dob.ln - when 5 - format_seg=SiSU_EPUB_Format::FormatSeg.new(@md,dob) - subtoc=format_seg.subtoc_lev5 #keep and make available, this is the subtoc - when 6 - format_seg=SiSU_EPUB_Format::FormatSeg.new(@md,dob) - subtoc=format_seg.subtoc_lev6 #keep and make available, this is the subtoc - end - @@seg_subtoc_array << subtoc - end - if @md.flag_auto_endnotes - ast,pls='*','+' - if dob.obj =~/(?:#{Mx[:en_a_o]}|#{Mx[:en_b_o]})(?:\d|#{ast}|#{pls})+ / \ - and dob.is !=:code # endnote- - endnote_array=[] - if dob.obj=~/#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}/m - endnote_array << dob.obj.scan(/#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}/m) - end - if dob.obj=~/#{Mx[:en_b_o]}#{ast}\d+\s.+?#{Mx[:en_b_c]}/m - endnote_array << dob.obj.scan(/#{Mx[:en_b_o]}#{ast}\d+\s.+?#{Mx[:en_b_c]}/m) - end - if dob.obj=~/#{Mx[:en_b_o]}#{pls}\d+\s.+?#{Mx[:en_b_c]}/m - endnote_array << dob.obj.scan(/#{Mx[:en_b_o]}#{pls}\d+\s.+?#{Mx[:en_b_c]}/m) - end - endnote_array=endnote_array.flatten #.compact #check compacting - endnote_array.each do |note| - note_match=note.dup - note_match_seg=note.dup - e_n=note_match_seg[/(?:#{Mx[:en_a_o]}(?:\d|#{ast}|#{pls})+|#{Mx[:en_b_o]}(?:#{ast}|#{pls})\d+)\s+(.+?)(?:#{Mx[:en_a_c]}|#{Mx[:en_b_c]})/m,1] - try=e_n.split(/
    /) - try.each do |e| - txt_obj={ txt: e } - format_seg=SiSU_EPUB_Format::FormatSeg.new(@md,txt_obj) - note_match=if e =~/#{Mx[:pa_o]}i[1-9]#{Mx[:pa_c]}/ - format_seg.endnote_body_indent - else format_seg.endnote_body - end - @@seg_endnotes_array << note_match - end - try.join('
    ') - #% creation of separate end segment/page of all endnotes referenced back to reference segment - m=/(?:#{Mx[:en_a_o]}(?:\d|#{ast}|#{pls})+|#{Mx[:en_b_o]}(?:#{ast}|#{pls})\d+)\s+(.+?href=")(#note_ref(?:\d|_a|_b)+".+)(?:#{Mx[:en_a_c]}|#{Mx[:en_b_c]})/mi - endnote_part_a=note_match_seg[m,1] - endnote_part_b=note_match_seg[m,2] - txt_obj={ endnote_part_a: endnote_part_a, endnote_part_b: endnote_part_b } - format_seg=SiSU_EPUB_Format::FormatSeg.new(@md,txt_obj) - note_match_all_seg=format_seg.endnote_seg_body(@@fn) #BUG WATCH 200408 - @@seg[:endnote_all] << note_match_all_seg - end - dob.obj=dob.obj.gsub(/(?:#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]})\s*/m,' ') - end - end - end - end - end -end -__END__ diff --git a/lib/sisu/v5/epub_tune.rb b/lib/sisu/v5/epub_tune.rb deleted file mode 100644 index 5ec5fa56..00000000 --- a/lib/sisu/v5/epub_tune.rb +++ /dev/null @@ -1,333 +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: epub generation, epub pre-processing - -=end -require_relative 'param' -module SiSU_EPUB_Tune - require_relative 'sysenv' # sysenv.rb - include SiSU_Env; include SiSU_Screen - require_relative 'epub_format' # epub_format.rb #watch - @@line_mode='' - @@endnote_array=[] - @@endnote_call_counter=1 - @@table_align=' - - -
    - \;' - @@table_align_close=' - -   
    ' - @@counter,@@column,@columns=0,0,0 - class Output - def initialize(data,md) - @data,@md=data,md - @file=SiSU_Env::FileOp.new(@md) - @cX=SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set]).cX - end - def hard_output - @filename_tune=@file.write_file_processing.html_tune - data=[] - @data.each {|x| x.obj.strip; data << x if not x.obj.empty?} #1.9 array? - data.each do |dob| - @filename_tune.puts dob, "\n" #check - end - end - def marshal - File.open(@file.marshal.html_tune,'w') {|f| Marshal.dump(@data.to_a,f)} - end - end - class CleanXHTML - def initialize(html='') - @html=html - end - def clean - html=@html - str=if html.is_a?(String) - html - else html.obj - end - str=str.gsub(/#{Mx[:gl_o]}(#[0-9]{3})#{Mx[:gl_c]}/u,'&\1;'). - gsub(/#{Mx[:gl_o]}#([a-z]{2,4})#{Mx[:gl_c]}/u,'&\1;'). - gsub(/
    /u,'
    '). - gsub(/#{Mx[:nbsp]}/u,$ep[:hsp]) - end - end - class Tune - def initialize(data,md) - @data,@md=data,md - @vz=SiSU_Viz::Defaults.new - @env=SiSU_Env::InfoEnv.new(@md.fns) - @sys=SiSU_Env::SystemCall.new - @env=SiSU_Env::InfoEnv.new(@md.fns) - @brace_url=SiSU_Viz::Defaults.new.url_decoration - end - def songsheet - begin - @cX=SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set]).cX - if (@md.opt.act[:verbose][:set]==:on \ - || @md.opt.act[:verbose_plus][:set]==:on \ - || @md.opt.act[:maintenance][:set]==:on) - SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set],'Tune').txt_grey - end - data=SiSU_EPUB_Tune::Tune.new(@data,@md).amp_angle_brackets - data=SiSU_EPUB_Tune::Tune.new(data,@md).endnotes_html - data=SiSU_EPUB_Tune::Tune.new(data,@md).url_markup - data=SiSU_EPUB_Tune::Tune.new(data,@md).markup - if @md.opt.act[:maintenance][:set]==:on #Hard Output Tune Optional on/off here - data=SiSU_EPUB_Tune::Output.new(data,@md).hard_output - SiSU_EPUB_Tune::Output.new(data,@md).marshal - end - SiSU_EPUB_Tune::Tune.new(@data,@md).output - rescue - SiSU_Errors::Rescued.new($!,$@,@md.opt.cmd,@md.fns).location do - __LINE__.to_s + ':' + __FILE__ - end - ensure - end - end - def markup - @tuned_file=[] - @data.each do |dob| - dob.obj=dob.obj.gsub(/#{Mx[:mk_o]}#([a-zA-Z]+)#{Mx[:mk_c]}/,'&\1;'). - gsub(/#{Mx[:mk_o]}(#[0-9]+)#{Mx[:mk_c]}/,'&\1;') - dob.obj=dob.obj.gsub(/#{Mx[:br_line]}|#{Mx[:br_nl]}/,'
    ') unless dob.is==:table - dob.obj=dob.obj.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_insert_o]}(.+?)#{Mx[:fa_insert_c]}/,'\1'). - gsub(/#{Mx[:fa_cite_o]}(.+?)#{Mx[:fa_cite_c]}/,'\1'). - gsub(/#{Mx[:fa_strike_o]}(.+?)#{Mx[:fa_strike_c]}/,'\1'). - gsub(/#{Mx[:fa_monospace_o]}(.+?)#{Mx[:fa_monospace_c]}/,'\1'). # tt, kbd - gsub(/#{Mx[:mk_o]}:name#(\S+?)#{Mx[:mk_c]}/,''). - gsub(/#{Mx[:gl_bullet]}/m,"●#{$ep[:hsp]*2}"). - gsub(/#{Dx[:url_o]}/,Dx[:url_o_xml]).gsub(/#{Dx[:url_c]}/,Dx[:url_o_xml]). - gsub(/#{Mx[:nbsp]}/,$ep[:hsp]). - gsub(/<(p|br)>/,'<\1 />') - dob.obj=SiSU_EPUB_Tune::CleanXHTML.new(dob.obj).clean - @tuned_file << dob - end - end - def urls(data) - @words=[] - map_nametags=SiSU_Particulars::CombinedSingleton.instance.get_map_nametags(@md).nametags_map #p map_nametags - data.each do |word| - @words << if word=~/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}|image)/ - http_=true - if word =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/ - m,u=/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/.match(word).captures - elsif word =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}/ - http_=false - m,u=/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:rel_o]}(\S+?)#{Mx[:rel_c]}/.match(word).captures - elsif word =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}image/ - m,u=/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}(image)/.match(word).captures - end - case m - when /\.png|\.jpg|\.gif|c=|\s\d+x\d+/ - w,h=/\s(\d+)x(\d+)/.match(m).captures if m =~/\s\d+x\d+/ - w=%{width="#{w}"} if w - h=%{height="#{h}"} if h - c=m[/"(.+?)"/m,1] - caption=%{

    #{c}

    } if c - png=m.scan(/\S+/)[0] - image_path=@md.file.output_path.epub.rel_image #image_path=@env.url.images_epub - ins=if u \ - and u.strip !~/^image$/ - %{
    #{caption}} - else %{#{caption}} - end - word=word.gsub(/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|image)/,ins) - else - link=m[/(.+)/m] - png=m.scan(/\S+/)[0].strip - link=link.strip - u=u.sub(/^#*/,'') #make neater - if map_nametags[u] \ - and map_nametags[u][:segname] - u=unless http_ - u=if u=~/^\d+$/ - u.gsub(/^(\d+)$/,"#{map_nametags[u][:segname]}#{Sfx[:xhtml]}#o\\1") if u !~/\// - else - u.gsub(/(\S+)/,"#{map_nametags[u][:segname]}#{Sfx[:xhtml]}#\\1") if u !~/\// - end - else u - end - elsif u =~/^:/ - u=u.gsub(/^:/,"#{@env.url.root}/") - elsif u =~/^\.\.\// - u=u.gsub(/^\.\.\//,"#{@env.url.root}/") - elsif u =~/https?:\/\// - else p "NOT FOUND name_tags: #{u}" - end - ins=%{#{link}} - word=word.gsub(/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/,ins). - gsub(/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}/,ins) - end - word - else word - end - word - end - @words=@words.join(' ') - end - def url_markup - data=@data - @tuned_file=[] - data.each do |dob| - unless dob.is==:code - if dob.obj =~/<::\s+/ #watch - dob.obj=dob.obj.gsub(/<::\s+(\S+?)\s+!>/, - %{\\1}) - end - if dob.obj =~/<:image\s+/ - dob.obj=dob.obj.gsub(/<:image\s+(http\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+>/, - %{}). - gsub(/<:image\s+(http\S+)\s+(\S+)\s+>/, - %{}). - gsub(/<:image\s+(\S+)\s+(\S+)\s+(\S+)\s+>/, - %{}). - gsub(/<:image\s+(\S+)\s+>/, - %{}) - end - if dob.obj =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}|image)/ - @word_mode=dob.obj.scan(/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}|image)[()\[\]]*[,.;:!?'"]{0,2}|(?:#{Mx[:gl_o]}\S+?#{Mx[:gl_c]})+|[^#{Mx[:lnk_o]}#{Mx[:lnk_c]}]+/mu) - words=urls(@word_mode) - dob.obj=dob.obj.gsub(/.+/m,words) - end - dob.obj=dob.obj.gsub(/\\copyright/i,%{©}) - dob.obj=if (dob.obj !~/\<:ad\s+\.\.\//) - dob.obj.gsub(/\<:ad\s+(\S+)?\s+(\S+\.png)\s+(.+)?\;\s+(.+)?\;\s*!\>/, - %{\n
    \\3
    \n}) - else - dob.obj.gsub(/\<:ad\s+(\S+)?\s+(\S+\.png)\s+(.+)?\;\s+(.+)?\;\s*\>/, - %{\n
    \\3
    \n}) - end - dob.obj=dob.obj.gsub(/!pick/,%{stellar}). - gsub(/!new/,%{#{$ep[:hsp]}new}). - gsub(/<:h(.{1,7}?)>/,'\1'). - gsub(/<:to(\d{1,7}?)>/,%{to#{$ep[:hsp]}\{#{$ep[:hsp]}\\1#{$ep[:hsp]}\} }). - 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 - if dob.obj =~/..\/\S+/ \ - and dob.obj !~/(\"..\/\S+?\"|>\s*..\/\S+<)/ - dob.obj=dob.obj.gsub(/(\.\.\/\S+)/,'\1') - end - dob.obj=dob.obj.gsub(//m,'>') - end - @tuned_file << dob - end - end - def amp_angle_brackets - data,data_new=@data,[] - data.each do |dob| - dob.obj=dob.obj. - gsub(/&/u,'&'). - gsub(//u,'>') - data_new << dob - end - data_new - end - def endnotes_html - data=@data - @tuned_file=[] - a,s='_a','_s' - ast,pls='*','+' - data.each do |dob| - unless dob.is ==:code - dob.obj=dob.obj.gsub(/(#{Mx[:en_a_o]}|#{Mx[:en_b_o]})(\d+)\s+(.+?)(#{Mx[:en_a_c]}|#{Mx[:en_b_c]})/, - %{#{Mx[:nbsp]}#{Mx[:nbsp]}\\2#{Mx[:nbsp]} } + #note- endnote- - %{\\1\\2 #{Mx[:nbsp]}\\2. \\3 \\4}). #endnote- note- (careful may have switched) - gsub(/(#{Mx[:en_b_o]})[*](\d+)\s+(.+?)(#{Mx[:en_b_c]})/, - %{#{Mx[:nbsp]}#{Mx[:nbsp]}#{ast}\\2#{Mx[:nbsp]} } + #note- endnote- - %{\\1#{ast}\\2 #{Mx[:nbsp]}#{ast}\\2. \\3 \\4}). #endnote- note- (careful may have switched) - gsub(/(#{Mx[:en_b_o]})[+](\d+)\s+(.+?)(#{Mx[:en_b_c]})/, - %{#{Mx[:nbsp]}#{Mx[:nbsp]}#{pls}\\2#{Mx[:nbsp]} } + #note- endnote- - %{\\1#{pls}\\2 #{Mx[:nbsp]}#{pls}\\2. \\3 \\4}) #endnote- note- (careful may have switched) # double-check there may here be a bug - if dob.obj =~/#{Mx[:en_a_o]}([*+]+)\s+.+?#{Mx[:en_a_c]}/ - m=$1.length.to_i - dob.obj=dob.obj.gsub(/(#{Mx[:en_a_o]})[*]+\s+(.+?)(#{Mx[:en_a_c]})/, - %{#{Mx[:nbsp]}#{Mx[:nbsp]}#{ast*m}#{Mx[:nbsp]} } + #note- endnote- - %{\\1#{ast*m} #{Mx[:nbsp]}#{ast*m} \\2 \\3}). #endnote- note- (careful may have switched) - gsub(/(#{Mx[:en_a_o]})([+]+)\s+(.+?)(#{Mx[:en_a_c]})/, - %{#{Mx[:nbsp]}#{Mx[:nbsp]}#{pls*m}#{Mx[:nbsp]} } + #note- endnote- - %{\\1#{pls*m} #{Mx[:nbsp]}#{pls*m} \\2 \\3}) #endnote- note- (careful may have switched) - end - end - @tuned_file << dob - end - end - def output - data=@data - @tuned_file=[] - data.each do |dob| - dob.obj=dob.obj.strip.chomp - @tuned_file << dob - end - @tuned_file << "\n" if (@md.fns =~/\.sst0/) #remove - @tuned_file - end - end -end -__END__ diff --git a/lib/sisu/v5/html_format.rb b/lib/sisu/v5/html_format.rb index 3a20ef67..db9fb449 100644 --- a/lib/sisu/v5/html_format.rb +++ b/lib/sisu/v5/html_format.rb @@ -93,7 +93,7 @@ module SiSU_HTML_Format end class HeadInformation require_relative 'css' # css.rb - require_relative 'shared_xml' # shared_xml.rb + require_relative 'xml_shared' # xml_shared.rb include SiSU_Viz attr_reader :md,:rdf,:vz def initialize(md) diff --git a/lib/sisu/v5/html_lite_shared.rb b/lib/sisu/v5/html_lite_shared.rb new file mode 100644 index 00000000..20e07f8c --- /dev/null +++ b/lib/sisu/v5/html_lite_shared.rb @@ -0,0 +1,325 @@ +# 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: modules shared by db and flatfile output generators, mostly + xml/xhtml/html formatting + +=end +module SiSU_FormatShared + require_relative 'defaults' # defaults.rb + include SiSU_Viz + class CSS_Format + require_relative 'defaults' # defaults.rb + require_relative 'particulars' # particulars.rb + @@fns=nil + def initialize(md,t_o) + @md,@t_o=md,t_o + @txt=@t_o.obj + @id=@ocn=@t_o.ocn if defined? @t_o.ocn + @lv=@t_o.lv.to_s if @t_o.is==:heading + if @md.fns != @@fns + @@fns,@@hname=@md.fns,'' + end + @hname=if defined? @t_o.name \ + and not @t_o.name.to_s.empty? + @@hname=@t_o.name + else @@hname + end + @tab="\t" + @brace_url=SiSU_Viz::Defaults.new.url_decoration + @@tablehead,@@tablefoot=[],[] + @vz=SiSU_Viz::Defaults.new + @env=SiSU_Env::InfoEnv.new(@md.fns) + @base_url="#{@env.url.root}/#{@md.fnb}/#{@hname}.html" + end + def urls(data) + @words=[] + map_nametags=SiSU_Particulars::CombinedSingleton.instance.get_map_nametags(@md).nametags_map + data.each do |word| + @words << if word=~/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}(#{Mx[:url_o]}\S+?#{Mx[:url_c]}|#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}|image)/ + if word =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/ + m,u=/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/.match(word).captures + elsif word =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}/ + m,u=/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:rel_o]}(\S+?)#{Mx[:rel_c]}/.match(word).captures + elsif word =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}image/ + m,u=/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}(image)/.match(word).captures + end + word=case m + when /\.png|\.jpg|\.gif|c=|\d+x\d+/ + w,h=/(\d+)x(\d+)/.match(m).captures if m =~/\d+x\d+/ + w=%{width="#{w}"} if w + h=%{height="#{h}"} if h + c=m[/"(.+?)"/m,1] + caption=%{

    #{c}

    } if c + png=m.scan(/\S+/)[0] + ins=if u \ + and u.strip !~/^image$/ + %{[#{png}]#{caption}} + else %{[#{png}] #{caption}} + end + word=word.gsub(/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}(#{Mx[:url_o]}\S+?#{Mx[:url_c]}|image)/,ins) + else + u=case u + when /^https?:\/\// + u + when /^:/ + u=u.gsub(/^:/,'') + "#{@env.url.root}/#{u}" + when /^\.\.\// # can remove + u=u.gsub(/^\.\.\//,'') + "#{@env.url.root}/#{u}" + else + "#{@env.url.root}/#{@md.fnb}/#{map_nametags[u][:segname]}#{Sfx[:html]}##{u}" + end + link=m[/(.+)/m] + png=m.scan(/\S+/)[0].strip + link=link.strip + ins=%{#{link}} + word=word.gsub(/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/,ins). + gsub(/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}/,ins) + word + end + word + else word + end + word + end + @words=@words.join(' ') + end + def markup_generic(s) + s=s.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_cite_o]}(.+?)#{Mx[:fa_cite_c]}/,'"\1"'). + gsub(/#{Mx[:fa_insert_o]}(.+?)#{Mx[:fa_insert_c]}/,'+{\1}+'). + gsub(/#{Mx[:fa_strike_o]}(.+?)#{Mx[:fa_strke_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'). # tt, kbd + gsub(/#{Mx[:gl_o]}#(?:126|152)#{Mx[:gl_c]}/i,'~') + end + def markup_object(t_o) + s=t_o.obj + s=if t_o.is !=:code + s=markup_generic(s) + if s =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}|image)/ + wm=s.scan(/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}|image)|\S+/) + words=urls(wm) + s=s.gsub(/.+/m,words) + end + s.gsub(/#{Mx[:gl_o]}(#[0-9]{3})#{Mx[:gl_c]}/u,'&\1;'). + gsub(/#{Mx[:gl_o]}#([a-z]{2,4})#{Mx[:gl_c]}/u,'&\1;'). + gsub(/#{Mx[:url_o]}[_\\](\S+?)#{Mx[:url_c]}/,'\1'). #http ftp matches escaped, no decoration + gsub(/(#{Mx[:lnk_c]})#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,'\1\2'). #special case \{ e.g. \}http://url + gsub(/(^|#{Mx[:gl_c]}|\s)#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,%{\\1#{@brace_url.xml_open}\\2#{@brace_url.xml_close}\\3}) #http ftp matches with decoration + else + s.gsub(//m,'>') + end + s + end + def markup_note(s) + s=markup_generic(s) + if s =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}(#{Mx[:url_o]}\S+?#{Mx[:url_c]}|#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}|image)/ + wm=s.scan(/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}|image)|\S+/) + words=urls(wm) + s=s.gsub(/.+/m,words) + end + s=s.gsub(/#{Mx[:gl_o]}(#[0-9]{3})#{Mx[:gl_c]}/u,'&\1;'). + gsub(/#{Mx[:gl_o]}#([a-z]{2,4})#{Mx[:gl_c]}/u,'&\1;'). + gsub(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/,'\1\2'). #http ftp matches escaped, no decoration + gsub(/(#{Mx[:lnk_c]})#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,'\1\2'). #special case \{ e.g. \}http://url + gsub(/#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,%{#{@brace_url.xml_open}\\1#{@brace_url.xml_close}}) #http ftp matches with decoration + end + def paragraph + %{

    #{@txt}

    \n} # << "\n" + end + def endnote(nr,en) #used only by db + txt=markup_note(en) + < +#{nr}. #{txt} +

    +GSUB + end + def tag_header(h) + %{

    #{h[:txt]}

    \n} # << "\n" + end + def tag_para(h) + %{

    #{h[:txt]}

    \n} << "\n" + end + def lev_toc_hname + %{

    #{@txt}

    \n} #<< "\n" + end + def lev_toc + h={ txt: txt, class: "toc#{@lv}", type: 'toc' } + tag_para(h) + end + def lev4_plus + txt=markup_object(@t_o) + h={ txt: txt, class: "h#{@lv}", type: 'substantive', id: @ocn, header: @hname } + tag_header(h) + end + def lev4_minus + txt=markup_object(@t_o) + h={ txt: txt, class: "h#{@t_o.ln}", type: 'substantive', id: @ocn } + tag_para(h) + end + def norm_comment + h={ txt: @t_o.obj, class: 'norm', type: 'comment' } + tag_para(h) + end + def norm + txt=markup_object(@t_o) + h={ txt: txt, class: 'norm', type: 'substantive', id: @ocn } + tag_para(h) + end + def code + txt=markup_object(@t_o) + h={ txt: "#{txt}", class: 'code', type: 'substantive', id: @ocn } + tag_para(h) + end + def indent(t) + txt=markup_object(@t_o) + h={ txt: txt, class: "indent#{t}", type: 'substantive', id: @ocn } + tag_para(h) + end + def hang_indent(f,t) + txt=markup_object(@t_o) + h={ txt: txt, class: "hang#{f}indent#{t}", type: 'substantive', id: @ocn } + #h={ txt: txt, class: "h#{f}i#{t}", type: 'substantive', id: @ocn } + tag_para(h) + end + def para_table + %{

    } + end + def ocn + %{} << "\n" + end + def html_table # get rid of use html_table + @new_content=[] + @txt.split(/\n/).each do |parablock| + m=parablock[//,1] + @@tablefoot << m if m + parablock=parablock.gsub(//,'') + @@tablehead=1 if parablock =~/#{Mx[:gr_o]}Th#{Mx[:tc_p]}/u + parablock=parablock.gsub(/#{Mx[:gr_o]}Th?#{Mx[:tc_p]}.+?#{Mx[:tc_p]}~(\d+)#{Mx[:gr_c]}/, + %{}) + if parablock =~/#{Mx[:gr_o]}TZ#{Mx[:gr_c]}/ + tablefoot=[] + @@tablefoot.each {|x| tablefoot << %{

    #{x}

    \n}} + @@tablefoot=[] + parablock=parablock.gsub(/#{Mx[:gr_o]}TZ#{Mx[:gr_c]}/, + %{#{@vz.table_close}\n}) # + + end + if @@tablehead==1 + if parablock =~/#{Mx[:tc_p]}#{Mx[:tc_p]}/u + parablock=parablock.gsub(/#{Mx[:tc_o]}#{Mx[:tc_p]}#{Mx[:tc_p]}(\d+?)#{Mx[:tc_p]}/u, + %{\n} + + %{\n') + @@tablehead=0 + end + parablock + else + parablock=parablock.gsub(/#{Mx[:tc_o]}#{Mx[:tc_p]}#{Mx[:tc_p]}(\d+?)#{Mx[:tc_p]}/u, + %{\n} + + %{\n') + parablock + end + @new_content << parablock + end + @new_content.join + end + end + class CSS_FormatGeneric #does CSS_Format in one definition, needs to be told about attrib, despite brevity of generic, easier to see structure with CSS_Format + def initialize(attrib='',txt='',id=nil,ocnd=nil,ocns=nil,lv='',hname=nil) + @tab="\t" + @attrib=attrib + @txt=txt + @lv=lv.to_s + @hname=hname.to_s + @id=@ocn=id + end + def paragraph + attrib=%{class="#{@attrib}" } + if @ocn + id=%{id="#{@ocn}" } + type=%{type="substantive" } + else + id=%{id="none" } + type=%{type="comment" } + end + header=%{header="#{@hname}" } if @hname + %{

    #{@txt}

    \n} #<< "\n" + end + def para + paragraph + end + end +end +__END__ diff --git a/lib/sisu/v5/html_scroll.rb b/lib/sisu/v5/html_scroll.rb index 3ac75aaa..f525b462 100644 --- a/lib/sisu/v5/html_scroll.rb +++ b/lib/sisu/v5/html_scroll.rb @@ -60,7 +60,7 @@ =end module SiSU_HTML_Scroll - require_relative 'shared_html' # shared_html.rb + require_relative 'html_shared' # html_shared.rb require_relative 'html' # html.rb require_relative 'shared_metadata' # shared_metadata.rb require_relative 'html_promo' # html_promo.rb diff --git a/lib/sisu/v5/html_segments.rb b/lib/sisu/v5/html_segments.rb index 79dda0e2..d6b341ac 100644 --- a/lib/sisu/v5/html_segments.rb +++ b/lib/sisu/v5/html_segments.rb @@ -60,7 +60,7 @@ =end module SiSU_HTML_Seg - require_relative 'shared_html' # shared_html.rb + require_relative 'html_shared' # html_shared.rb require_relative 'html' # html.rb require_relative 'html_promo' # html_promo.rb require_relative 'shared_metadata' # shared_metadata.rb diff --git a/lib/sisu/v5/html_shared.rb b/lib/sisu/v5/html_shared.rb new file mode 100644 index 00000000..63a8964e --- /dev/null +++ b/lib/sisu/v5/html_shared.rb @@ -0,0 +1,68 @@ +# 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: shared html parts + +=end +module SiSU_HTML_Shared + require_relative 'defaults' # defaults.rb + require_relative 'html_table' # html_table.rb + class TableHTML < SiSU_HTML_Table::TableHTML + end +end +__END__ diff --git a/lib/sisu/v5/hub.rb b/lib/sisu/v5/hub.rb index 9390d517..a4fd408f 100644 --- a/lib/sisu/v5/hub.rb +++ b/lib/sisu/v5/hub.rb @@ -299,8 +299,8 @@ module SiSU SiSU_DigestView::Source.new(@opt).read end if @opt.act[:txt][:set]==:on #% --txt, -t -a - require_relative 'plaintext' # plaintext.rb - SiSU_Plaintext::Source.new(@opt).read + require_relative 'txt_plain' # txt_plain.rb + SiSU_Txt_Plain::Source.new(@opt).read end if @opt.act[:html][:set]==:on #% --html, -h -H require_relative 'html' # html.rb @@ -320,12 +320,12 @@ module SiSU SiSU_Concordance::Source.new(@opt).read end if @opt.act[:epub][:set]==:on #% --epub, -e - require_relative 'epub' # epub.rb - SiSU_EPUB::Source.new(@opt).read + require_relative 'xhtml_epub2' # xhtml_epub2.rb + SiSU_XHTML_EPUB2::Source.new(@opt).read end if @opt.act[:odt][:set]==:on #% --odt, -o opendocument - require_relative 'odf' # odf.rb - SiSU_ODF::Source.new(@opt).read + require_relative 'xml_odf_odt' # xml_odf_odt.rb + SiSU_XML_ODF_ODT::Source.new(@opt).read end if @opt.act[:xhtml][:set]==:on #% --xhtml, -b xhtml require_relative 'xhtml' # xhtml.rb @@ -391,12 +391,12 @@ module SiSU or @opt.act[:sisupod][:set]==:on \ or @opt.act[:git][:set]==:on begin - require_relative 'shared_sisupod_source' + require_relative 'src_shared' OptionLoopFiles.new(@opt).loop_files_on_given_option do SiSU_Source::SiSUpodSource.new(@opt).read end if @opt.act[:share_source][:set]==:on - require_relative 'share_src' # -s share_src.rb + require_relative 'src_share' # -s src_share.rb begin ensure OptionLoopFiles.new(@opt).loop_files_on_given_option_bundle do @@ -405,7 +405,7 @@ module SiSU end end if @opt.act[:sisupod][:set]==:on #% --sisupod, -S make sisupod - require_relative 'sisupod_make' # -S sisupod_make.rb + require_relative 'src_sisupod_make' # -S src_sisupod_make.rb begin ensure OptionLoopFiles.new(@opt).loop_files_on_given_option_bundle do diff --git a/lib/sisu/v5/manpage.rb b/lib/sisu/v5/manpage.rb index 905cf87f..ccdd829c 100644 --- a/lib/sisu/v5/manpage.rb +++ b/lib/sisu/v5/manpage.rb @@ -69,7 +69,7 @@ module SiSU_Manpage require_relative 'manpage_format' # manpage_format.rb include SiSU_ManpageFormat require_relative 'shared_metadata' # shared_metadata.rb - require_relative 'shared_txt' # shared_txt.rb + require_relative 'txt_shared' # txt_shared.rb @@alt_id_count,@@alt_id_count,@@tablehead,@@number_of_cols=0,0,0,0 @@tablefoot='' class Source @@ -112,7 +112,7 @@ module SiSU_Manpage private class Scroll . - - 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 'ao' # ao.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,@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_ODF::Source::Scroll.new(@particulars).songsheet - rescue - SiSU_Errors::Rescued.new($!,$@,@opt.cmd,@opt.fns).location 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 - 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) - SiSU_ODF_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 - 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) - 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) - 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.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}/#{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.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 - 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]}/, - %{#{@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) - 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]}/, - %{#{@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 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]}/, - %{#{@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 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_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_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 @env.odt_ocn? - if defined? dob.ocn \ - and dob.ocn.is_a?(Fixnum) - p_num=SiSU_ODF_Format::ParagraphNumber.new(dob.ocn).set_bookmark_and_display - end - end - end - 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 - @@odf[:toc] << toc(dob,p_num).obj - end - end - elsif dob.is ==:verse - @@odf[:body] << poem(dob,p_num).obj << break_line*2 - elsif dob.is==:group - @@odf[:body] << group(dob,p_num).obj << break_line*2 - elsif dob.is==:block - @@odf[:body] << block(dob,p_num).obj << break_line*2 - elsif dob.is==:code - @@odf[: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..6).each { |x| @cont[x]=@level[x]=false } - (4..6).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.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.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 - @@odf[:head] << x - end - def publish - content=[] - br_pg=' ' - 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 . - - 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 formatting, default opendocument template - -=end -module SiSU_ODF_Format - require_relative 'param' # param.rb - include SiSU_Param - include SiSU_Viz - class ParagraphNumber - def initialize(paranum) - @paranum=/(\d+)/m.match(paranum.to_s)[1] - end - def set_ref_and_display - set_ref=@paranum.gsub(/(\d+)/,' ') - disp=@paranum.gsub(/(\d+)/,%{ #{Dx[:ocn_o]}\\1#{Dx[:ocn_c]}}) - { display: disp, set_ref: set_ref } - end - def set_bookmark_and_display - set_ref=@paranum.gsub(/(\d+)/,' ') - disp=@paranum.gsub(/(\d+)/,%{ #{Dx[:ocn_o]}\\1#{Dx[:ocn_c]}}) - { display: disp, set_ref: set_ref } - end - def name - @paranum.gsub(/(\d+)/,'') - end - def goto - @paranum.gsub(/(\d+)/,'') - end - end - class FormatBookIndex - def initialize(idx_str) - @idx_str=idx_str - end - def book_idx_bookmark - map_nametags=SiSU_Particulars::CombinedSingleton.instance.get_map_nametags(@md).nametags_map #p map_nametags - rgx_bookmark=/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:rel_o]}#?\S+?#{Mx[:rel_c]}/m - while @idx_str =~/#{Mx[:lnk_o]}([^#{Mx[:lnk_o]}#{Mx[:lnk_c]}]+)#{Mx[:lnk_c]}#{Mx[:rel_o]}#?(\S+?)#{Mx[:rel_c]}/m - link,url=$1,$2 - link,url=link.strip,url.strip - @idx_str=@idx_str.gsub(/&/m,"&") - ocn_lnk=if map_nametags[url] \ - and map_nametags[url][:ocn] - map_nametags[url][:ocn] - else nil - end - ocn_lnk=(url=~/^\d+$/ ? url : ocn_lnk) - if ocn_lnk and not ocn_lnk.empty? - @idx_str=@idx_str.sub(/#{Mx[:fa_bold_o]}(.+?)#{Mx[:fa_bold_c]}/, - '\1'). - sub(rgx_bookmark, - %{#{link.strip}}) - else - puts %{name tag: "#{url}" not found} - @idx_str.sub!(rgx_bookmark,"#{link}") - end - end - @idx_str=@idx_str.gsub(/#{Xx[:protect]}/m,''). - sub(/,\s*$/m,''). - gsub(/\n/,'') - @idx_str='' + @idx_str + '' - end - end - class Tags - def set_bookmark_tag(dob) - tags='' - if dob.tags.length > 0 - dob.tags.each do |tag| - tags +=%{ } - end - end - tags - end - end - class FormatTextObject - def initialize(md,t_o) - @md,@t_o=md,t_o - if t_o.is_a?(Hash) - @txt =t_o[:txt] || nil - else - p t_o.class - p caller - end - rgx=/#{Mx[:en_a_o]}\d+\s+(.+?)#{Mx[:en_a_c]}/ - @txt=@txt.gsub(rgx,'\1') if @txt =~rgx - @vz=SiSU_Viz::Defaults.new - end - def scr_endnote_body - "#{@txt} " - end - def heading_body1 - end - def heading_body2 - end - def heading_body3 - end - def heading_body4 - end - def heading_body5 - end - def heading_body6 - end - end - class Table - @@tablehead,@@table_counter=0,0 #reinitialise on new file - @@tablefoot=[] #watch - @@fns='' - def initialize(md,dob,p_num) - @md,@dob,@p_num=md,dob,p_num - @txt=dob.obj - @vz=SiSU_Viz::Defaults.new - if @md.fns != @@fns - @@table_counter=0 - @@fns=@md.fns - end - end - def break_line - (@md.opt.act[:maintenance][:set]==:on) \ - ? "\n" : '' - end - def table_head_open(count) - type=(@dob.head_) \ - ? 1 - : 2 - alpha=case @dob.cols - when 1; 'A' - when 2; 'B' - when 3; 'C' - when 4; 'D' - when 5; 'E' - when 6; 'F' - when 7; 'G' - when 8; 'H' - when 9; 'I' - when 10; 'J' - when 11; 'K' - when 12; 'L' - when 13; 'M' - when 14; 'N' - else 'D' - end - tag=SiSU_ODF_Format::Tags.new.set_bookmark_tag(@dob) - %{#{@p_num[:set_ref]}#{tag}#{break_line}} + - %{#{break_line}} - end - def table_close(tablefoot='') - '' \ - + %{#{@p_num[:display]}} - end - def table_tag_cell(str,i) - txt_name_cell=if i==0 \ - and @dob.head_ - 'Table_Heading' - else 'P_table_cell' - end - str=str.gsub(/^~$/,'') # tilde / empty cell - %{#{break_line}} + - %{#{break_line}} + - %{#{str}} + - %{#{break_line}} + - %{#{break_line}} - end - def table_tag_row(str,i) - %{#{break_line}} + - %{#{str}} + - %{#{break_line}} - end - def table_tag_row_dump(str,i) - txt_name_row=if i==0 \ - and @dob.head_ - 'Table_Heading' - else 'P_table_cell' - end - %{#{break_line}} + - %{#{break_line}} + - %{#{break_line}} + - %{#{str}} + - %{#{break_line}} + - %{#{break_line}} + - %{#{break_line}} - end - def table_row(row,i) - row='' if row =~/^/,1] - @@tablefoot << m if m - row=row.gsub(//,'') - @cells=[] - row.split(/\s*#{Mx[:tc_p]}/).each do |cell| - @cells << table_tag_cell(cell,i) - end - row=@cells.join - row=table_tag_row(row,i) - row - end - def table - @@table_counter+=1 - table_head_open(@@table_counter) - @table=[] - @dob.obj.split(/\s*#{Mx[:tc_c]}/).each_with_index do |r,i| - @table << table_row(r,i) - end - @dob.obj= table_head_open(@@table_counter) + @table.join + table_close - @dob - end - end - class ODT_Head_1_2 - def initialize(md) - @md=md - @generator="#{@md.sisu_version[:project]} #{@md.sisu_version[:version]} #{@md.sisu_version[:date_stamp]} (#{@md.sisu_version[:date]})" - end - def manifest_rdf - x=< - - - - - - - - - - - - - - - - - -WOK - x=x.strip - x=x.gsub(/\n+/m,'') unless @md.opt.act[:maintenance][:set]==:on - x - end - def meta_inf_manifest_xml(md) - images=[' '] - if md.ec[:image].length > 0 - md.ec[:image].each do |i| - images<<< -WOK - end - end - images=images.join('') - x=< - - - - - #{images} - - - - - - - - -WOK - x=x.strip - x=x.gsub(/\n+/m,'') unless @md.opt.act[:maintenance][:set]==:on - x - end - def meta_xml - x=< - - - #{@generator} - #{@md.generated} - #{@md.generated} - en-US - - -WOK - x=x.strip - x=x.gsub(/\n+/m,'') unless @md.opt.act[:maintenance][:set]==:on - x - end - def settings_xml - x=< - - - - 0 - 0 - 0 - 0 - true - false - - - view2 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 2 - true - 100 - false - - - - - true - false - false - true - true - false - true - false - false - - false - false - false - true - true - 0 - false - false - false - false - true - false - false - false - false - true - true - false - false - true - false - true - false - high-resolution - 1 - 0 - true - - - false - true - - false - true - false - true - false - true - false - - true - true - false - true - true - true - false - false - - false - 0 - false - false - true - true - - - -WOK - x=x.strip - x=x.gsub(/\n+/m,'') unless @md.opt.act[:maintenance][:set]==:on - x - end - def styles_xml - x=< - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -WOK - x=x.strip - x=x.gsub(/\n+/m,'') unless @md.opt.act[:maintenance][:set]==:on - x - end - def mimetype - x=<#{sep*60}
    } - @t_o - end - def obj_sep #center later - sep='--- ' - @t_o.obj=%{#{sep*20}} - @t_o - end - end - class XML - end -end -__END__ diff --git a/lib/sisu/v5/plaintext.rb b/lib/sisu/v5/plaintext.rb deleted file mode 100644 index 57838342..00000000 --- a/lib/sisu/v5/plaintext.rb +++ /dev/null @@ -1,576 +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: plaintext text generation, stripped plaintext output (unix, - linefeed) - -=end -module SiSU_Plaintext - require_relative 'ao' # ao.rb - require_relative 'sysenv' # sysenv.rb - include SiSU_Env - require_relative 'plaintext_format' # plaintext_format.rb - include SiSU_Plaintext_Format - require_relative 'shared_metadata' # shared_metadata.rb - require_relative 'shared_txt' # shared_txt.rb - include SiSU_Param - include SiSU_Viz - @@alt_id_count,@@alt_id_count,@@tablehead,@@number_of_cols=0,0,0,0 - @@tablefoot='' - class Source - def initialize(opt) - @opt=opt - unless @opt.fns =~/(.+?)\.(?:-|ssm\.)?sst$/ - puts "#{sf} not a processed file type" - end - end - def read - begin - md=SiSU_Param::Parameters.new(@opt).get - env=SiSU_Env::InfoEnv.new(@opt.fns) - 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.text_editor} #{md.file.output_path.txt.dir}/#{md.file.base_filename.txt}" - : "[#{@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],'Plaintext',tool).green_hi_blue - : SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'Plaintext',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,"#{md.file.output_path.txt.dir}/#{md.file.base_filename.txt}").flow - end - end - ao_array=SiSU_AO::Source.new(@opt).get # ao file drawn here - wrap_width=if defined? md.make.plaintext_wrap \ - and md.make.plaintext_wrap - md.make.plaintext_wrap - elsif defined? env.plaintext_wrap \ - and env.plaintext_wrap - env.plaintext_wrap - else 78 - end - #wrap_width=(defined? md.make.plaintext_wrap) ? md.make.plaintext_wrap : 78 - SiSU_Plaintext::Source::Scroll.new(md,ao_array,wrap_width).songsheet - rescue - SiSU_Errors::Rescued.new($!,$@,@opt.cmd,@opt.fns).location do - __LINE__.to_s + ':' + __FILE__ - end - ensure - end - end - private - class Scroll appropriately within plaintext, consider - n=n.dup.to_s - if n =~/#{Mx[:br_line]}|#{Mx[:br_nl]}/ - fix = n.split(/#{Mx[:br_line]}|#{Mx[:br_nl]}/) #watch #added - fix.each do |x| - unless x.empty?; @n << x - end - end - else @n << n - end - end - notes=@n.flatten - notes.each do |e| - util=(e.to_s =~/^\[[\d*+]+\]:/) \ - ? (SiSU_TextUtils::Wrap.new(e.to_s,@wrap_width,4,1)) - : (SiSU_TextUtils::Wrap.new(e.to_s,@wrap_width,1,1)) - wrap=util.line_wrap - wrap=if wrap =~ /^\s*[\d*+]+\s+.+?\s*\Z/m - wrap.gsub(/^(\s*)([\d*+]+)\s+(.+?)\s*\Z/m, <<-GSUB -\\1[\\2]: \\3 - GSUB - ) - else - wrap.gsub(/^(.+)\Z/m, <<-GSUB -\\1 - GSUB - ) - end - @@endnotes[:para] << "-#{wrap}" - @@endnotes[:end] << '' << wrap - end - @@endnotes - end - def plaintext_metadata - array=SiSU_Metadata::Summary.new(@md).plaintext.metadata - array.each do |meta| - tag,inf=meta.scan(/^.+?:\s|.+/) - if tag and inf - util=SiSU_TextUtils::Wrap.new(inf,@wrap_width,15,1) - txt=util.line_wrap - @plaintext[:metadata] <<< @wrap_width - @plaintext[:body] << case lv - when 1; wrapped.upcase << break_line << decorate.heading_underscore.l1*times + p_num << break_line*2 - when 2; wrapped.upcase << break_line << decorate.heading_underscore.l2*times + p_num << break_line*2 - when 3; wrapped.upcase << break_line << decorate.heading_underscore.l3*times + p_num << break_line*2 - when 4; wrapped.upcase << break_line << decorate.heading_underscore.l4*times + p_num << break_line*2 - when 5; wrapped.upcase << break_line << decorate.heading_underscore.l5*times + p_num << break_line*2 - when 6; wrapped.upcase << break_line << decorate.heading_underscore.l6*times + p_num << break_line*2 - end - else - @plaintext[:body] << wrapped + p_num << break_line # main text, contents, body KEEP - end - if @@endnotes[:para] \ - and not @@endnotes_ - @@endnotes[:para].each {|e| @plaintext[:body] << e << break_line} - elsif @@endnotes[:para] \ - and @@endnotes_ - end - @@endnotes[:para]=[] - end - def markup(data) # Used for major markup instructions - SiSU_Env::InfoEnv.new(@md.fns) - @data_mod,@endnotes,@level,@cont,@copen,@plaintext_contents_close=Array.new(6){[]} - (0..6).each { |x| @cont[x]=@level[x]=false } - (4..6).each { |x| @plaintext_contents_close[x]='' } - plaintext_tail #($1,$2) - plaintext_metadata - table_message='[table omitted, see other document formats]' - data.each do |dob| - dob.obj=dob.obj.gsub(/#{Mx[:gr_o]}Th?#{Mx[:tc_p]}.+/um,"#{break_line}#{table_message}"). #fix - gsub(/.+?#{Mx[:gl_o]}-##{Mx[:gl_c]}/,''). # remove dummy headings (used by html) #check also [~-]# - gsub(/#{Mx[:fa_bold_o]}(.+?)#{Mx[:fa_bold_c]}/, - "#{decorate.bold.open}\\1#{decorate.bold.close}"). - gsub(/#{Mx[:fa_italics_o]}(.+?)#{Mx[:fa_italics_c]}/, - "#{decorate.italics.open}\\1#{decorate.italics.close}"). - gsub(/#{Mx[:fa_underscore_o]}(.+?)#{Mx[:fa_underscore_c]}/, - "#{decorate.underscore.open}\\1#{decorate.underscore.close}"). - gsub(/#{Mx[:fa_subscript_o]}(.+?)#{Mx[:fa_subscript_c]}/, - "#{decorate.subscript.open}\\1#{decorate.subscript.close}"). - gsub(/#{Mx[:fa_superscript_o]}(.+?)#{Mx[:fa_superscript_c]}/, - "#{decorate.superscript.open}\\1#{decorate.superscript.close}"). - gsub(/#{Mx[:fa_insert_o]}(.+?)#{Mx[:fa_insert_c]}/, - "#{decorate.insert.open}\\1#{decorate.insert.close}"). - gsub(/#{Mx[:fa_cite_o]}(.+?)#{Mx[:fa_cite_c]}/, - "#{decorate.cite.open}\\1#{decorate.cite.close}"). - gsub(/#{Mx[:fa_strike_o]}(.+?)#{Mx[:fa_strike_c]}/, - "#{decorate.strike.open}\\1#{decorate.strike.close}"). - gsub(/#{Mx[:fa_monospace_o]}(.+?)#{Mx[:fa_monospace_c]}/, - "#{decorate.monospace.open}\\1#{decorate.monospace.close}") - unless dob.is==:code - dob.obj=dob.obj.gsub(/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}/,'\1'). - gsub(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/,'\1'). - gsub(/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,'\1 [link: <\2>]'). - gsub(/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}image/,'\1 [link: local image]'). - gsub(/#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,"#{@brace_url.txt_open}\\1#{@brace_url.txt_close}") - extract_endnotes(dob) - dob.obj=dob.obj.gsub(/#{Mx[:en_a_o]}([\d*+]+)\s+(?:.+?)#{Mx[:en_a_c]}/,'[^\1]'). # endnote marker marked up - gsub(/#{Mx[:en_b_o]}([\d*+]+)\s+(?:.+?)#{Mx[:en_b_c]}/,'[^\1]'). # endnote marker marked up - gsub(/#{Mx[:gl_o]}(?:#lt|#060)#{Mx[:gl_c]}/,'<'). - gsub(/#{Mx[:gl_o]}(?:#gt|#062)#{Mx[:gl_c]}/,'>'). - gsub(/#{Mx[:gl_o]}#(?:038|amp)#{Mx[:gl_c]}/,'&'). - gsub(/#{Mx[:gl_o]}#033#{Mx[:gl_c]}/,'!'). - gsub(/#{Mx[:gl_o]}#035#{Mx[:gl_c]}/,'#'). - gsub(/#{Mx[:gl_o]}#042#{Mx[:gl_c]}/,'*'). - gsub(/#{Mx[:gl_o]}#045#{Mx[:gl_c]}/,'-'). - gsub(/#{Mx[:gl_o]}#047#{Mx[:gl_c]}/,'/'). - gsub(/#{Mx[:gl_o]}#095#{Mx[:gl_c]}/,'_'). - gsub(/#{Mx[:gl_o]}#123#{Mx[:gl_c]}/,'{'). - gsub(/#{Mx[:gl_o]}#125#{Mx[:gl_c]}/,'}'). - gsub(/#{Mx[:gl_o]}#126#{Mx[:gl_c]}/,'~'). - gsub(/#{Mx[:gl_o]}#169#{Mx[:gl_c]}/,'©'). - gsub(/#{Mx[:gl_o]}#092#{Mx[:gl_c]}/,'\\') - end - dob.obj=if dob.of==:block # watch - dob.obj.gsub(/#{Mx[:gl_o]}●#{Mx[:gl_c]}/m,"* "). - gsub(/\n?#{Mx[:br_line]}\n?|\n?#{Mx[:br_nl]}\n?/m,break_line) - else dob.obj.gsub(/\n?#{Mx[:br_line]}\n?|\n?#{Mx[:br_nl]}\n?/m,break_line*2) - end - if dob.is==:code - dob.obj=dob.obj.gsub(/(^|[^}])_([<>])/m,'\1\2'). # _> _< - gsub(/(^|[^}])_([<>])/m,'\1\2') # _<_< - end - dob.obj=dob.obj.gsub(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/,'\1'). - gsub(/(.+?)<\/a>/m,'\1'). - gsub(/#{Mx[:mk_o]}:name#(\S+?)#{Mx[:mk_c]}/,''). # remove name links - gsub(/ |#{Mx[:nbsp]}/,' '). # decide on - gsub(/(?:^|[^_\\])#{Mx[:lnk_o]}(\S+?\.(?:png|jpg|gif)) .+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/,' [ \1 ]'). #"[ #{dir.url.images_local}\/\\1 ]") - gsub(/(?:^|[^_\\])#{Mx[:lnk_o]}(\S+?\.(?:png|jpg|gif)) .+?#{Mx[:lnk_c]}image/,' [ \1 ]'). - gsub(/(?:^|[^_\\])\{\s*\S+?\.(?:png|jpg|gif)\s+.+?"(.*?)"\s*\}\S+/,'[image: "\1"]') - if dob.obj !~/(^#{Rx[:meta]}|#{Mx[:br_eof]}|#{Mx[:br_endnotes]})/ - p_num='' - if @env.plaintext_ocn? - if defined? dob.ocn \ - and dob.ocn.is_a?(Fixnum) - p_num=SiSU_Plaintext_Format::ParagraphNumber.new(dob.ocn).display - end - end - if dob.is==:heading \ - or dob.is==:para - plaintext_structure(dob,p_num) - elsif dob.is==:group \ - or dob.is==:block \ - or dob.is==:verse \ - or dob.is==:code \ - or dob.is==:table - @plaintext[:body] << dob.obj + p_num << break_line - elsif dob.is==:break - sp=' ' - ln='-' - @plaintext[:body] <<=if dob.obj==Mx[:br_page] \ - or dob.obj==Mx[:br_page_new] \ - or dob.obj==Mx[:br_page_line] - "#{break_line}#{ln*40}#{break_line*2}" - elsif dob.obj ==Mx[:br_obj] - "#{break_line}#{sp*20}* * *#{break_line*2}" - end # following empty line (break_line) missing, fix - end - dob='' if (dob.obj =~// \ - and dob.obj =~/^(-\{{2}~\d+|)/) # -endnote - if dob ## Clean Prepared Text - dob.obj=dob.obj.gsub(//,' '). - gsub(/<:\S+>/,' ') - end - end - end - @plaintext - end - def publish(plaintext) - divider='=' - content=[] - content << plaintext[:open] - content << plaintext[:head] - content << plaintext[:body] - content << @@endnotes[:end] if @@endnotes_ - content << "#{break_line}#{divider*@wrap_width}#{break_line}" - content << plaintext[:metadata] - content << "#{break_line}#{divider*@wrap_width}#{break_line}" if @md.stmp =~/\w+/ #not used? - content << plaintext[:tail] - Output.new(content,@md).plaintext - @@endnotes={ para: [], end: [] } - end - end - class Output 0 - para.each do |line| - if line - line=line.gsub(/[ \t]+$/m,''). - gsub(/^\A[ ]*\Z/m,'') - (line=~/^\A\Z/) \ - ? (emptyline+=1) - : emptyline=0 - if emptyline < 2 #remove additional empty lines - file_plaintext.puts line - end - end - end - else file_plaintext.puts para #unix plaintext # /^([*=-]|\.){5}/ - end - end - file_plaintext.close - end - end - end -end -__END__ - bold_o: '*', bold_c: '*', - #bold_o: '!', bold_c: '!', - #emphasis_o: '*', emphasis_c: '*', - italics_o: '/', italics_c: '/', - underscore_o: '_', underscore_c: '_', - cite_o: '"', cite_c: '"', - insert_o: '+', insert_c: '+', - strike_o: '-', strike_c: '-', - superscript_o: '^', superscript_c: '^', - subscript_o: '[', subscript_c: ']', - hilite_o: '*', hilite_c: '*', - monospace_o: '', monospace_c: '', - po_bold_o: '!{', po_bold_c: '}!', - po_italics_o: '/{', po_italics_c: '}/', - po_underscore_o: '_{', po_underscore_c: '}_', - po_cite_o: '"{', po_cite_c: '}"', - po_insert_o: '+{', po_insert_c: '}+', - po_strike_o: '-{', po_strike_c: '}-', - po_superscript_o: '^{', po_superscript_c: '}^', - po_subscript_o: ',{', po_subscript_c: '},', - po_hilite_o: '*{', po_hilite_c: '}*', - po_monospace_o: '#{', po_monospace_c: '}#', diff --git a/lib/sisu/v5/plaintext_format.rb b/lib/sisu/v5/plaintext_format.rb deleted file mode 100644 index acad8828..00000000 --- a/lib/sisu/v5/plaintext_format.rb +++ /dev/null @@ -1,104 +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: plaintext formatting template - -=end -module SiSU_Plaintext_Format - require_relative 'param' # param.rb - include SiSU_Param - include SiSU_Viz - class ParagraphNumber - def initialize(paranum) - @paranum=/(\d+)/m.match(paranum.to_s)[1] - end - def display - @paranum.gsub(/(\d+)/,"\n#{Dx[:ocn_o]}\\1#{Dx[:ocn_c]}") - end - def name #unused - @paranum.gsub(/(\d+)/,'\1') - end - def goto #unused - @paranum.gsub(/(\d+)/,'"#\1"') - end - end - class FormatTextObject - def initialize(md,t_o) - @md,@t_o=md,t_o - if t_o.is_a?(Hash) - @txt =t_o[:txt] || nil - @lnk_url =t_o[:lnk_url] || nil - @lnk_txt =t_o[:lnk_txt] || nil - else - p t_o.class - p caller - end - rgx=/^#{Rx[:lv]}/ - @txt=@txt.gsub(rgx,'') if @txt =~rgx - rgx=/#{Mx[:en_a_o]}[\d*+]+\s+(.+?)#{Mx[:en_a_c]}/ - @txt=@txt.gsub(rgx,'\1') if @txt =~rgx - @vz=SiSU_Viz::Defaults.new - end - def scr_endnote_body - "#{@txt} " - end - end - class XML - end -end -__END__ diff --git a/lib/sisu/v5/share_src.rb b/lib/sisu/v5/share_src.rb deleted file mode 100644 index 69dd7bb9..00000000 --- a/lib/sisu/v5/share_src.rb +++ /dev/null @@ -1,102 +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: share sisu source markup file, copy it to output directory! - -=end -module SiSU_Markup - require_relative 'shared_sisupod_source' # shared_sisupod_source.rb - include SiSU_Source - require_relative 'sysenv' # sysenv.rb - include SiSU_Env - class Source < SiSU_Source::SiSUpodSource - def initialize(opt,build=nil,place=nil) - super(opt,build,place) - @opt=opt - end - def read - unless @opt.act[:quiet][:set]==:on - (@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],'Share document markup text source',@opt.fns).cyan_hi_blue - : SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'Share document markup text source',@opt.fns).cyan_title_hi - end - if FileTest.directory?(@path_pod[:fnb]) - FileUtils::mkdir_p(@file.output_path.src.dir) unless FileTest.directory?(@file.output_path.src.dir) - v=(@opt.act[:maintenance][:set]==:on) \ - ? 'v' : '' - system(%{ - rsync -a#{v} #{@path_pod[:fnb]} #{@file.output_path.sisupod.dir} - chbk=`pwd` - cd #{@file.output_path.sisupod.dir} - for I in `find -type d` ; do chmod 755 $I ; done - for I in `find -type f` ; do chmod 644 $I ; done - cd ${chbk} - }) - else - if (@opt.act[:verbose][:set]==:on \ - || @opt.act[:verbose_plus][:set]==:on \ - || @opt.act[:maintenance][:set]==:on) - SiSU_Screen::Ansi.new('',"#{@opt.fno} not available").blue_tab - end - end - end - end -end -__END__ diff --git a/lib/sisu/v5/share_src_kdissert.rb b/lib/sisu/v5/share_src_kdissert.rb deleted file mode 100644 index b696891e..00000000 --- a/lib/sisu/v5/share_src_kdissert.rb +++ /dev/null @@ -1,90 +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: share sisu source markup file, copy it to output directory! - -=end -module SiSU_KdiSource - require_relative 'sysenv' # sysenv.rb - include SiSU_Env - class Source - require 'fileutils' - include FileUtils - def initialize(opt) - @opt=opt - @env=SiSU_Env::InfoEnv.new(@opt.fns) - @output_path="#{@env.path.output}/#{@opt.fnb}" - end - def read - SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'Share Kdissert Source Document!',@opt.fnb).green_hi_blue unless @opt.act[:quiet][:set]==:on - SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"Copy kdissert file to output directory","#{@opt.fnb} -> #{@output_path}").warn unless @opt.act[:quiet][:set]==:on - FileUtils::mkdir_p(@env.path.output) unless FileTest.directory?(@env.path.output) - FileUtils::mkdir_p(@output_path) unless FileTest.directory?(@output_path) - if FileTest.directory?(@output_path) - if @opt.fns =~/\.kdi\._sst$/ \ - and FileTest.file?(@opt.fnb) - FileUtils::cp(@opt.fnb,@output_path) - end - else - SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"Output directory does not exist","#{@opt.fnb} -> #{@output_path}").warn unless @opt.act[:quiet][:set]==:on - exit - end - end - end -end -__END__ diff --git a/lib/sisu/v5/shared_html.rb b/lib/sisu/v5/shared_html.rb deleted file mode 100644 index 84c89ecf..00000000 --- a/lib/sisu/v5/shared_html.rb +++ /dev/null @@ -1,68 +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: shared html parts - -=end -module SiSU_HTML_Shared - require_relative 'defaults' # defaults.rb - require_relative 'html_table' # html_table.rb - class TableHTML < SiSU_HTML_Table::TableHTML - end -end -__END__ diff --git a/lib/sisu/v5/shared_html_lite.rb b/lib/sisu/v5/shared_html_lite.rb deleted file mode 100644 index e46510ea..00000000 --- a/lib/sisu/v5/shared_html_lite.rb +++ /dev/null @@ -1,325 +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: modules shared by db and flatfile output generators, mostly - xml/xhtml/html formatting - -=end -module SiSU_FormatShared - require_relative 'defaults' # defaults.rb - include SiSU_Viz - class CSS_Format - require_relative 'defaults' # defaults.rb - require_relative 'particulars' # particulars.rb - @@fns=nil - def initialize(md,t_o) - @md,@t_o=md,t_o - @txt=@t_o.obj - @id=@ocn=@t_o.ocn if defined? @t_o.ocn - @lv=@t_o.lv.to_s if @t_o.is==:heading - if @md.fns != @@fns - @@fns,@@hname=@md.fns,'' - end - @hname=if defined? @t_o.name \ - and not @t_o.name.to_s.empty? - @@hname=@t_o.name - else @@hname - end - @tab="\t" - @brace_url=SiSU_Viz::Defaults.new.url_decoration - @@tablehead,@@tablefoot=[],[] - @vz=SiSU_Viz::Defaults.new - @env=SiSU_Env::InfoEnv.new(@md.fns) - @base_url="#{@env.url.root}/#{@md.fnb}/#{@hname}.html" - end - def urls(data) - @words=[] - map_nametags=SiSU_Particulars::CombinedSingleton.instance.get_map_nametags(@md).nametags_map - data.each do |word| - @words << if word=~/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}(#{Mx[:url_o]}\S+?#{Mx[:url_c]}|#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}|image)/ - if word =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/ - m,u=/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/.match(word).captures - elsif word =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}/ - m,u=/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:rel_o]}(\S+?)#{Mx[:rel_c]}/.match(word).captures - elsif word =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}image/ - m,u=/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}(image)/.match(word).captures - end - word=case m - when /\.png|\.jpg|\.gif|c=|\d+x\d+/ - w,h=/(\d+)x(\d+)/.match(m).captures if m =~/\d+x\d+/ - w=%{width="#{w}"} if w - h=%{height="#{h}"} if h - c=m[/"(.+?)"/m,1] - caption=%{

    #{c}

    } if c - png=m.scan(/\S+/)[0] - ins=if u \ - and u.strip !~/^image$/ - %{
    [#{png}]#{caption}} - else %{[#{png}] #{caption}} - end - word=word.gsub(/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}(#{Mx[:url_o]}\S+?#{Mx[:url_c]}|image)/,ins) - else - u=case u - when /^https?:\/\// - u - when /^:/ - u=u.gsub(/^:/,'') - "#{@env.url.root}/#{u}" - when /^\.\.\// # can remove - u=u.gsub(/^\.\.\//,'') - "#{@env.url.root}/#{u}" - else - "#{@env.url.root}/#{@md.fnb}/#{map_nametags[u][:segname]}#{Sfx[:html]}##{u}" - end - link=m[/(.+)/m] - png=m.scan(/\S+/)[0].strip - link=link.strip - ins=%{#{link}} - word=word.gsub(/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/,ins). - gsub(/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}/,ins) - word - end - word - else word - end - word - end - @words=@words.join(' ') - end - def markup_generic(s) - s=s.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_cite_o]}(.+?)#{Mx[:fa_cite_c]}/,'"\1"'). - gsub(/#{Mx[:fa_insert_o]}(.+?)#{Mx[:fa_insert_c]}/,'+{\1}+'). - gsub(/#{Mx[:fa_strike_o]}(.+?)#{Mx[:fa_strke_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'). # tt, kbd - gsub(/#{Mx[:gl_o]}#(?:126|152)#{Mx[:gl_c]}/i,'~') - end - def markup_object(t_o) - s=t_o.obj - s=if t_o.is !=:code - s=markup_generic(s) - if s =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}|image)/ - wm=s.scan(/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}|image)|\S+/) - words=urls(wm) - s=s.gsub(/.+/m,words) - end - s.gsub(/#{Mx[:gl_o]}(#[0-9]{3})#{Mx[:gl_c]}/u,'&\1;'). - gsub(/#{Mx[:gl_o]}#([a-z]{2,4})#{Mx[:gl_c]}/u,'&\1;'). - gsub(/#{Mx[:url_o]}[_\\](\S+?)#{Mx[:url_c]}/,'\1'). #http ftp matches escaped, no decoration - gsub(/(#{Mx[:lnk_c]})#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,'\1\2'). #special case \{ e.g. \}http://url - gsub(/(^|#{Mx[:gl_c]}|\s)#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,%{\\1#{@brace_url.xml_open}\\2#{@brace_url.xml_close}\\3}) #http ftp matches with decoration - else - s.gsub(//m,'>') - end - s - end - def markup_note(s) - s=markup_generic(s) - if s =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}(#{Mx[:url_o]}\S+?#{Mx[:url_c]}|#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}|image)/ - wm=s.scan(/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}|image)|\S+/) - words=urls(wm) - s=s.gsub(/.+/m,words) - end - s=s.gsub(/#{Mx[:gl_o]}(#[0-9]{3})#{Mx[:gl_c]}/u,'&\1;'). - gsub(/#{Mx[:gl_o]}#([a-z]{2,4})#{Mx[:gl_c]}/u,'&\1;'). - gsub(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/,'\1\2'). #http ftp matches escaped, no decoration - gsub(/(#{Mx[:lnk_c]})#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,'\1\2'). #special case \{ e.g. \}http://url - gsub(/#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,%{#{@brace_url.xml_open}\\1#{@brace_url.xml_close}}) #http ftp matches with decoration - end - def paragraph - %{

    #{@txt}

    \n} # << "\n" - end - def endnote(nr,en) #used only by db - txt=markup_note(en) - < -#{nr}. #{txt} -

    -GSUB - end - def tag_header(h) - %{

    #{h[:txt]}

    \n} # << "\n" - end - def tag_para(h) - %{

    #{h[:txt]}

    \n} << "\n" - end - def lev_toc_hname - %{

    #{@txt}

    \n} #<< "\n" - end - def lev_toc - h={ txt: txt, class: "toc#{@lv}", type: 'toc' } - tag_para(h) - end - def lev4_plus - txt=markup_object(@t_o) - h={ txt: txt, class: "h#{@lv}", type: 'substantive', id: @ocn, header: @hname } - tag_header(h) - end - def lev4_minus - txt=markup_object(@t_o) - h={ txt: txt, class: "h#{@t_o.ln}", type: 'substantive', id: @ocn } - tag_para(h) - end - def norm_comment - h={ txt: @t_o.obj, class: 'norm', type: 'comment' } - tag_para(h) - end - def norm - txt=markup_object(@t_o) - h={ txt: txt, class: 'norm', type: 'substantive', id: @ocn } - tag_para(h) - end - def code - txt=markup_object(@t_o) - h={ txt: "#{txt}", class: 'code', type: 'substantive', id: @ocn } - tag_para(h) - end - def indent(t) - txt=markup_object(@t_o) - h={ txt: txt, class: "indent#{t}", type: 'substantive', id: @ocn } - tag_para(h) - end - def hang_indent(f,t) - txt=markup_object(@t_o) - h={ txt: txt, class: "hang#{f}indent#{t}", type: 'substantive', id: @ocn } - #h={ txt: txt, class: "h#{f}i#{t}", type: 'substantive', id: @ocn } - tag_para(h) - end - def para_table - %{

    } - end - def ocn - %{} << "\n" - end - def html_table # get rid of use html_table - @new_content=[] - @txt.split(/\n/).each do |parablock| - m=parablock[//,1] - @@tablefoot << m if m - parablock=parablock.gsub(//,'') - @@tablehead=1 if parablock =~/#{Mx[:gr_o]}Th#{Mx[:tc_p]}/u - parablock=parablock.gsub(/#{Mx[:gr_o]}Th?#{Mx[:tc_p]}.+?#{Mx[:tc_p]}~(\d+)#{Mx[:gr_c]}/, - %{

    } + + %{#{para_table}}). + gsub(/#{Mx[:tc_p]}#{Mx[:tc_p]}(\d+?)#{Mx[:tc_p]}/u, + %{} + + %{#{para_table}}). + gsub(/#{Mx[:tc_c]}/, '
    } + + %{#{para_table}}). + gsub(/#{Mx[:tc_p]}#{Mx[:tc_p]}(\d+?)#{Mx[:tc_p]}/u, + %{} + + %{#{para_table}}). + gsub(/#{Mx[:tc_c]}/, '
    }) - if parablock =~/#{Mx[:gr_o]}TZ#{Mx[:gr_c]}/ - tablefoot=[] - @@tablefoot.each {|x| tablefoot << %{

    #{x}

    \n}} - @@tablefoot=[] - parablock=parablock.gsub(/#{Mx[:gr_o]}TZ#{Mx[:gr_c]}/, - %{#{@vz.table_close}\n}) # + - end - if @@tablehead==1 - if parablock =~/#{Mx[:tc_p]}#{Mx[:tc_p]}/u - parablock=parablock.gsub(/#{Mx[:tc_o]}#{Mx[:tc_p]}#{Mx[:tc_p]}(\d+?)#{Mx[:tc_p]}/u, - %{\n
    } + - %{\n') - @@tablehead=0 - end - parablock - else - parablock=parablock.gsub(/#{Mx[:tc_o]}#{Mx[:tc_p]}#{Mx[:tc_p]}(\d+?)#{Mx[:tc_p]}/u, - %{\n} + - %{\n') - parablock - end - @new_content << parablock - end - @new_content.join - end - end - class CSS_FormatGeneric #does CSS_Format in one definition, needs to be told about attrib, despite brevity of generic, easier to see structure with CSS_Format - def initialize(attrib='',txt='',id=nil,ocnd=nil,ocns=nil,lv='',hname=nil) - @tab="\t" - @attrib=attrib - @txt=txt - @lv=lv.to_s - @hname=hname.to_s - @id=@ocn=id - end - def paragraph - attrib=%{class="#{@attrib}" } - if @ocn - id=%{id="#{@ocn}" } - type=%{type="substantive" } - else - id=%{id="none" } - type=%{type="comment" } - end - header=%{header="#{@hname}" } if @hname - %{

    #{@txt}

    \n} #<< "\n" - end - def para - paragraph - end - end -end -__END__ diff --git a/lib/sisu/v5/shared_sisupod_source.rb b/lib/sisu/v5/shared_sisupod_source.rb deleted file mode 100644 index 021d2e0f..00000000 --- a/lib/sisu/v5/shared_sisupod_source.rb +++ /dev/null @@ -1,312 +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: create sisupod filetype and copy it to output directory! - -=end -module SiSU_Source - include SiSU_Env - class SiSUpodSource - require_relative 'sysenv' # sysenv.rb - require_relative 'particulars' # particulars.rb - def initialize(opt,build=nil,place=nil) - @opt=opt - @date=SiSU_Env::InfoDate.new.dt - @env=SiSU_Env::InfoEnv.new(opt.fns) - @ver=SiSU_Env::InfoVersion.instance.get_version - @v=(@opt.act[:verbose_plus][:set]==:on \ - || @opt.act[:maintenance][:set]==:on) \ - ? 'v' : '' - @particulars=SiSU_Particulars::CombinedSingleton.instance.get_all(opt) - @file=@particulars.file - @local_path="#{@file.output_path.sisupod.dir}" - processing_sisupod=@env.processing_path.processing_sisupod(opt) - processing_sisupod.make - path_pod=processing_sisupod.paths[:sisupod] - path_pod_fnb=processing_sisupod.paths[:fnb] - FileUtils::mkdir_p(path_pod) unless FileTest.directory?(path_pod) - @path_pod={ - fnb: path_pod_fnb, - pod: path_pod, - doc: path_pod + '/' + Gt[:doc] + '/' + opt.lng, - po: path_pod + '/' + Gt[:po] + '/' + opt.lng, - pot: path_pod + '/' + Gt[:pot], - conf: path_pod + '/' + Gt[:conf], - image: path_pod + '/' + Gt[:image], - audio: path_pod + '/' + Gt[:audio], - video: path_pod + '/' + Gt[:video], - } - end - def read - unless @opt.act[:quiet][:set]==:on - (@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],'Assemble SiSU source',"[#{@opt.f_pth[:lng_is]}] #{@opt.fno}").green_hi_blue - : '' - end - unless @opt.fns.empty? - directories - pod_source_build #this needs to be built in case of multi-lingual for all of them, before single pass tar - end - end - def directories - SiSU_Env::InfoEnv.new.sisupod_v4(@opt) - end - def images_extract(f,images) # consider using param info - rgx_image=/(?:^|[^_\\])\{(?:\s*|\~\^\s+)(\S+?\.(?:png|jpg|gif)\b)/m - if f !~/^%+\s/ \ - and f =~rgx_image - images << f.scan(rgx_image).uniq - end - images.flatten - end - def pod_source_build - @pwd=Dir.pwd - @rgx_rb_image=/["']\S*?([a-zA-Z0-9_-]+?\.(?:png|jpg|gif))["']/ - @rgx_image=/(?:^|[^_\\])\{\s*(\S+?\.(?:png|jpg|gif))/ - @rgx_doc_import=/^<<\s*(\S+?\.ss[ti])/ - file_array=IO.readlines(@opt.fno,'') - images,doc_import=[],[] - doc_import_dir=@opt.sub_location - file_array.each do |f| #% work area - if f !~/^%+\s/ - f=f.gsub(/<:=(\S+?)>/,'{ c_\1.png 14x14 }image') # embedded symbol (image) - if f !~/^%+\s/ \ - and f =~@rgx_image - images=images_extract(f,images) - end - if @opt.fno =~/\.ssm$/ - doc_import << f.scan(@rgx_doc_import) if f =~@rgx_doc_import - end - end - end - if doc_import.length > 0 - doc_import=doc_import.uniq.flatten - doc_import.each do |fn| - file_array=IO.readlines(fn,'') - file_array.each do |f| #% work area - if f !~/^%+\s/ \ - and f =~@rgx_image - images=images_extract(f,images) - end - end - end - end - gi=SiSU_Env::GetInit.new - unless FileTest.file?("#{@path_pod[:conf]}/#{gi.makefile_name}") - if gi.makefile \ - && FileTest.file?(gi.makefile) - FileUtils::mkdir_p(@path_pod[:conf]) unless FileTest.directory?(@path_pod[:conf]) - FileUtils::cp(gi.makefile,"#{@path_pod[:conf]}/#{gi.makefile_name}") - end - #get images from makefile, consider placing in param - end - if images \ - and images.length > 1 - images=images.flatten.uniq - images.delete_if {|x| x =~/https?:\/\// } - #images=images.sort - FileUtils::mkdir_p(@path_pod[:image]) - #unattractive hard coding ... ! - image_path='_sisu/image' - images_pwd="#{@opt.base_path}/#{image_path}" - ##sequence copies base images, defaults used in all html outputs - #image_source_base='/usr/share/sisu/image' - #dir_pwd=Dir.pwd - #Dir.chdir(image_source_base) - #base_images=Dir.glob('*') - #base_images.each do |i| - # FileUtils::cp_r(i,"#{images_path_pod}/#{i}") - #end - #Dir.chdir(dir_pwd) - if FileTest.directory?(images_pwd) - images=images.uniq - images.each do |i| - if FileTest.file?("#{images_pwd}/#{i}") - FileUtils::cp("#{images_pwd}/#{i}","#{@path_pod[:image]}/#{i}") - else STDERR.puts %{\t*WARN* did not find image - "#{images_pwd}/#{i}" [#{__FILE__}:#{__LINE__}]} - end - end - else STDERR.puts %{\t*WARN* did not find - #{images_pwd} #{@path_pod[:image]} [#{__FILE__}:#{__LINE__}]} - end - end - if doc_import.length > 0 \ - and @opt.fno =~/\.ssm$/ - doc_import.each do |f| - if FileTest.file?("#{@opt.base_path}#{doc_import_dir}/#{f}") - FileUtils::cp("#{@opt.base_path}#{doc_import_dir}/#{f}","#{@path_pod[:doc]}/#{f}") - else STDERR.puts %{\t*WARN* did not find image - "#{@opt.base_path}#{doc_import_dir}/#{f}" [#{__FILE__}:#{__LINE__}]} - end - end - end - x=@env.document_language_versions_found #check multiple document language versions (param not used) - if x[:f] \ - and x[:f].length > 0 #store multiple document language versions, sisupod - x[:f].each do |f| - FileUtils::mkdir_p(@path_pod[:doc]) unless FileTest.directory?(@path_pod[:doc]) - if f[:f] =~/\~(\S{2,3})\.ss[tm]$/ - lng_f=$1 - if @opt.lng == lng_f - if @opt.fno =~/\.ssm$/ - if FileTest.file?("#{@opt.base_path}#{doc_import_dir}/#{f[:f]}") - FileUtils::cp("#{@opt.base_path}#{doc_import_dir}/#{f[:f]}", - "#{@path_pod[:doc]}/#{f[:n]}") - else STDERR.puts %{\t*WARN* did not find - "#{@opt.base_path}#{doc_import_dir}/#{f[:f]}" [#{__FILE__}:#{__LINE__}]} - end - else - if FileTest.file?("#{@opt.base_path}/#{f[:f]}") - cpy= :no - cpy=if f[:f] =~ /^#{@opt.f_pth[:lng_is]}\// \ - or f[:f] =~ /~#{@opt.f_pth[:lng_is]}\.sst/ - :yes - elsif f[:f] !~ /^(?:#{Px[:lng_lst_rgx]})\/|~(?:#{Px[:lng_lst_rgx]})\.sst/ \ - and @opt.f_pth[:lng_is] == 'en' - :yes - else :no - end - if cpy == :yes - FileUtils::cp("#{@opt.base_path}/#{f[:f]}", - "#{@path_pod[:doc]}/#{f[:n]}") - end - else STDERR.puts %{\t*WARN* did not find - "#{@opt.base_path}/#{f[:f]}" [#{__FILE__}:#{__LINE__}]} - end - end - end - else - if @opt.fno =~/\.ssm$/ - if FileTest.file?("#{@opt.base_path}#{doc_import_dir}/#{f[:f]}") - FileUtils::cp_r("#{@opt.base_path}#{doc_import_dir}/#{f[:f]}", - "#{@path_pod[:doc]}/#{f[:n]}") - else STDERR.puts %{\t*WARN* did not find - "#{@opt.base_path}#{doc_import_dir}/#{f[:f]}" [#{__FILE__}:#{__LINE__}]} - end - else - if FileTest.file?("#{@opt.base_path}/#{f[:f]}") - cpy= :no - cpy=if f[:f] =~ /^#{@opt.f_pth[:lng_is]}\// \ - or f[:f] =~ /~#{@opt.f_pth[:lng_is]}\.sst/ - :yes - elsif f[:f] !~ /^(?:#{Px[:lng_lst_rgx]})\/|~(?:#{Px[:lng_lst_rgx]})\.sst/ \ - and @opt.f_pth[:lng_is] == 'en' - :yes - else :no - end - if cpy == :yes - FileUtils::cp("#{@opt.base_path}/#{f[:f]}", - "#{@path_pod[:doc]}/#{f[:n]}") - end - else STDERR.puts %{\t*WARN* did not find - "#{@opt.base_path}/#{f[:f]}" [#{__FILE__}:#{__LINE__}]} - end - end - end - end - end #NB not all possibilies met, revisit, also in case of composite file may wish to add README - end - end -end -__END__ -question?: should you permit the packing of multiple documents in single .xz ? - - open @opt.fns, parse file - extract from file content: - images and copy each image from whatever image source to _sisu/sisupod/sisu/_sisu/image - - remove previously existing contents of _/sisu/sisupod & - make directory structure: - -v3 --> - _sisu - sisupod - doc - manifest.txt - en/content.sst [file content] - fr/content.sst - _sisu - conf - image (ln -s ../../image) - audio (ln -s ../../audio) - video (ln -s ../../video) - image [all images for specific document gathered here] - audio - video - -v2 --> - _sisu - sisupod - content.sst [file content] - filename.sst [link to content.sst] - _sisu/ - image/ [all images for specific document gathered here] - -sisu - _sisu - sisurc.yml - convert/ - standard_terms/ - image - processing - ao/ - tex/ - texinfo/ - tune/ - sisupod - -special case - -composite file (master), e.g. -SiSU.ssm diff --git a/lib/sisu/v5/shared_txt.rb b/lib/sisu/v5/shared_txt.rb deleted file mode 100644 index 0e3b6018..00000000 --- a/lib/sisu/v5/shared_txt.rb +++ /dev/null @@ -1,236 +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: modules shared by flatfile output generators - -=end -module SiSU_TextUtils - class Wrap - def initialize(para='',n_char_max=76,n_indent=0,n_hang=nil) - @para,@n_char_max,@n_indent=para,n_char_max,n_indent - @n_char_max_extend = n_char_max - @n_hang=n_hang ? n_hang : @n_indent - end - def break_line - "\n" - end - def line_wrap - space=' ' - spaces_indent,spaces_hang="#{break_line}#{space*@n_indent}",space*@n_hang - line=0 - out=[] - out[line]='' - @para=@para.gsub(/
    /,' \\ '). - gsub(/#{Mx[:br_nl]}/,"\n\n") - words=@para.scan(/\n\n|\s+\\\s+|
    |\S+/m) - while words != '' - word=words.shift - if not word - out[line] unless out[line].empty? #check - break - elsif word =~/
    / - word=nil - out[line]=out[line].gsub(/
    /,'') - line=line - elsif word =~/\n\n/ - word="\n" - @n_char_max_extend = @n_char_max - line += 1 - elsif (out[line].length + word.length) > (@n_char_max_extend - @n_indent) \ - and out[line] =~/\S+/ - @n_char_max_extend = @n_char_max - out[line].squeeze!(' ') - line += 1 - end - if word - out[line]=if out[line] \ - and out[line] !~/\S+$/m - "#{out[line]}#{word}" - elsif out[line] \ - and out[line] =~/\S+/ - "#{out[line]} #{word}" - else "#{word.strip}" - end - end - @oldword=word if word =~/\S+/ - end - spaces_hang + out.join(spaces_indent) - end - def line_wrap_indent1 - @n_indent,@n_hang=2,2 - line_wrap - end - def line_wrap_endnote - @n_indent,@n_hang=4,2 - line_wrap - end - def array_wrap - if @para.is_a?(Array) - @arr=[] - @para.each do |line| - @arr << SiSU_TextUtils::Wrap.new(line,@n_char_max,@n_indent,@n_hang).line_wrap - end - end - @arr - end - end - class HeaderScan - def initialize(md,para) - @md,@p=md,para - end - def extract(tag,tag_content,type,attrib) - if dc_tag \ - and dc_content - [dc_tag,dc_content,{dc_tag=>dc_content}] - else nil - end - end - def header(tag,tag_content,type='',attrib='') #this will break stuff and must be tested thoroughly 20060825 - @tag,@tag_content,@type,@attrib=tag,tag_content,type,attrib - def label #element - @tag - end - def type - @type - end - def text - @tag_content - end - def info #element text - @tag_content - end - def attribute - @attrib - end - def element - @tag - end - def attrib - @attrib - end - def el - @tag - end - self - end - def start_is_match - case @p - when /^#{Mx[:meta_o]}(title)#{Mx[:meta_c]}\s*(.+?)$/; header($1,@md.title.full,'meta','dc') #dc 1 - when /^#{Mx[:meta_o]}(creator|author)#{Mx[:meta_c]}\s*(.+?)$/; header('creator',$2,'meta','dc') #dc 2 - when /^#{Mx[:meta_o]}(subject)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','dc') #dc 3 - when /^#{Mx[:meta_o]}(description)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','dc') #dc 4 - when /^#{Mx[:meta_o]}(publisher)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','dc') #dc 5 - when /^#{Mx[:meta_o]}(contributor)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','dc') #dc 6 - when /^#{Mx[:meta_o]}(date)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','dc') #dc 7 - when /^#{Mx[:meta_o]}(date\.created)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','extra') - when /^#{Mx[:meta_o]}(date\.issued)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','extra') - when /^#{Mx[:meta_o]}(date\.available)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','extra') - when /^#{Mx[:meta_o]}(date\.valid)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','extra') - when /^#{Mx[:meta_o]}(date\.modified)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','extra') - when /^#{Mx[:meta_o]}(type)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','dc') #dc 8 - when /^#{Mx[:meta_o]}(format)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','dc') #dc 9 - when /^#{Mx[:meta_o]}(identifier)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','dc') #dc 10 - when /^#{Mx[:meta_o]}(source)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','dc') #dc 11 - when /^#{Mx[:meta_o]}(language)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','dc') #dc 12 - when /^#{Mx[:meta_o]}(relation)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','dc') #dc 13 - when /^#{Mx[:meta_o]}(coverage)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','dc') #dc 14 - when /^#{Mx[:meta_o]}(rights)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','dc') #dc 15 - when /^#{Mx[:meta_o]}(keywords)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','extra') - when /^#{Mx[:meta_o]}(copyright)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','extra') - when /^#{Mx[:meta_o]}(translator|translated_by)#{Mx[:meta_c]}\s*(.+?)$/; header('translator',$2) - when /^#{Mx[:meta_o]}(illustrator|illustrated_by)#{Mx[:meta_c]}\s*(.+?)$/; header('illustrator',$2) - when /^#{Mx[:meta_o]}(prepared_by)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','extra') - when /^#{Mx[:meta_o]}(digitized_by)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','extra') - when /^#{Mx[:meta_o]}(comments?)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','extra') - when /^#{Mx[:meta_o]}(abstract)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','extra') - when /^#{Mx[:meta_o]}(tags?)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','extra') - when /^#{Mx[:meta_o]}(catalogue)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','extra') - when /^#{Mx[:meta_o]}(class(?:ify)?_loc)#{Mx[:meta_c]}\s*(.+?)$/; header('classify_loc',$2,'meta','extra') - when /^#{Mx[:meta_o]}(class(?:ify)?_dewey)#{Mx[:meta_c]}\s*(.+?)$/; header('classify_dewey',$2,'meta','extra') - when /^#{Mx[:meta_o]}(class(?:ify)?_pg)#{Mx[:meta_c]}\s*(.+?)$/; header('classify_pg',$2,'meta','extra') - when /^#{Mx[:meta_o]}(class(?:ify)?_isbn)#{Mx[:meta_c]}\s*(.+?)$/; header('classify_isbn',$2,'meta','extra') - when /^#{Mx[:meta_o]}(toc|structure)#{Mx[:meta_c]}\s*(.+?)$/; header('structure',$2,'process','instruct') - when /^#{Mx[:meta_o]}(level|page|markup)#{Mx[:meta_c]}\s*(.+?)$/; header('markup',$2,'process','instruct') - when /^#{Mx[:meta_o]}(bold)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'process','instruct') - when /^#{Mx[:meta_o]}(italics|itali[sz]e)#{Mx[:meta_c]}\s*(.+?)$/; header('italicize',$2,'process','instruct') - when /^#{Mx[:meta_o]}(vocabulary|wordlist)#{Mx[:meta_c]}\s*(.+?)$/; header('vocabulary',$2,'process','instruct') - when /^#{Mx[:meta_o]}(css|stylesheet)#{Mx[:meta_c]}\s*(.+?)$/; header('css',$2,'process','instruct') - when /^#{Mx[:meta_o]}(links)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'process','instruct') - when /^#{Mx[:meta_o]}(prefix)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'process','instruct') #add a & b - when /^#{Mx[:meta_o]}(suffix)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'process','instruct') - when /^#{Mx[:meta_o]}(information)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'process','instruct') - when /^#{Mx[:meta_o]}(contact)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'process','instruct') - when /^#{Mx[:meta_o]}(rcs|cvs)#{Mx[:meta_c]}\s*(.+?)$/; header('version',$2,'process','instruct') - else nil - end - end - def dublin - if @p =~/^#{Mx[:meta_o]}\S+?#{Mx[:meta_c]}/ - start_is_match - else nil - end - end - def meta - if @p =~/^#{Mx[:meta_o]}\S+?#{Mx[:meta_c]}/ - start_is_match - else nil - end - end - end -end -__END__ diff --git a/lib/sisu/v5/shared_xhtml.rb b/lib/sisu/v5/shared_xhtml.rb deleted file mode 100644 index c9534823..00000000 --- a/lib/sisu/v5/shared_xhtml.rb +++ /dev/null @@ -1,68 +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: shared html parts - -=end -module SiSU_XHTML_Shared - require_relative 'defaults' # defaults.rb - require_relative 'xhtml_table' # xhtml_table.rb - class TableXHTML < SiSU_XHTML_Table::TableXHTML - end -end -__END__ diff --git a/lib/sisu/v5/shared_xml.rb b/lib/sisu/v5/shared_xml.rb deleted file mode 100644 index 76b5374b..00000000 --- a/lib/sisu/v5/shared_xml.rb +++ /dev/null @@ -1,721 +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: common file for xml generation -=end -module SiSU_XML_Munge - class Trans - require_relative 'defaults' # defaults.rb - def initialize(md) - @md=md - @sys=SiSU_Env::SystemCall.new - @dir=SiSU_Env::InfoEnv.new(@md.fns) - @brace_url=SiSU_Viz::Defaults.new.url_decoration - if @md.sem_tag - @ab ||=semantic_tags.default - end - end - def semantic_tags - def default - { - pub: 'publication', - conv: 'convention', - vol: 'volume', - pg: 'page', - cty: 'city', - org: 'organization', - uni: 'university', - dept: 'department', - fac: 'faculty', - inst: 'institute', - co: 'company', - com: 'company', - conv: 'convention', - dt: 'date', - y: 'year', - m: 'month', - d: 'day', - ti: 'title', - au: 'author', - ed: 'editor', #editor? - v: 'version', #edition - n: 'name', - fn: 'firstname', - mn: 'middlename', - ln: 'lastname', - in: 'initials', - qt: 'quote', - ct: 'cite', - ref: 'reference', - ab: 'abreviation', - def: 'define', - desc: 'description', - trans: 'translate', - } - end - self - end - def char_enc #character encode - def utf8(dob='') - if @sys.locale =~/utf-?8/i # instead ucs for utf8 # String#encode Iñtërnâtiônàlizætiøn - str=if defined? dob.obj then dob.obj - elsif dob.is_a?(String) then dob - end - if str - #¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûü - #¢£¥§©ª«®°±²³µ¶¹º»¼½¾×÷ - str=str.gsub(//um,'>'). # '>' # > - gsub(/¢/um,'¢'). # '¢' # ¢ - gsub(/£/um,'£'). # '£' # £ - gsub(/¥/um,'¥'). # '¥' # ¥ - gsub(/§/um,'§'). # '§' # § - gsub(/©/um,'©'). # '©' # © - gsub(/ª/um,'ª'). # 'ª' # ª - gsub(/«/um,'«'). # '«' # « - gsub(/®/um,'®'). # '®' # ® - gsub(/°/um,'°'). # '°' # ° - gsub(/±/um,'±'). # '±' # ± - gsub(/²/um,'²'). # '²' # ² - gsub(/³/um,'³'). # '³' # ³ - gsub(/µ/um,'µ'). # 'µ' # µ - gsub(/¶/um,'¶'). # '¶' # ¶ - gsub(/¹/um,'¹'). # '¹' # ¹ - gsub(/º/um,'º'). # 'º' # º - gsub(/»/um,'»'). # '»' # » - gsub(/¼/um,'¼'). # '¼' # ¼ - gsub(/½/um,'½'). # '½' # ½ - gsub(/¾/um,'¾'). # '¾' # ¾ - gsub(/×/um,'×'). # '×' # × - gsub(/÷/um,'÷'). # '÷' # ÷ - gsub(/¿/um,'¿'). # '¿' # ¿ - gsub(/À/um,'À'). # 'À' # À - gsub(/Á/um,'Á'). # 'Á' # Á - gsub(/Â/um,'Â'). # 'Â' #  - gsub(/Ã/um,'Ã'). # 'Ã' # à - gsub(/Ä/um,'Ä'). # 'Ä' # Ä - gsub(/Å/um,'Å'). # 'Å' # Å - gsub(/Æ/um,'Æ'). # 'Æ' # Æ - gsub(/Ç/um,'Ç'). # 'Ç' # Ç - gsub(/È/um,'È'). # 'È' # È - gsub(/É/um,'É'). # 'É' # É - gsub(/Ê/um,'Ê'). # 'Ê' # Ê - gsub(/Ë/um,'Ë'). # 'Ë' # Ë - gsub(/Ì/um,'Ì'). # 'Ì' # Ì - gsub(/Í/um,'Í'). # 'Í' # Í - gsub(/Î/um,'Î'). # 'Î' # Î - gsub(/Ï/um,'Ï'). # 'Ï' # Ï - gsub(/Ð/um,'Ð'). # 'Ð' # Ð - gsub(/Ñ/um,'Ñ'). # 'Ñ' # Ñ - gsub(/Ò/um,'Ò'). # 'Ò' # Ò - gsub(/Ó/um,'Ó'). # 'Ó' # Ó - gsub(/Ô/um,'Ô'). # 'Ô' # Ô - gsub(/Õ/um,'Õ'). # 'Õ' # Õ - gsub(/Ö/um,'Ö'). # 'Ö' # Ö - gsub(/Ø/um,'Ø'). # 'Ø' # Ø - gsub(/Ù/um,'Ù'). # 'Ù' # Ù - gsub(/Ú/um,'Ú'). # 'Ú' # Ú - gsub(/Û/um,'Û'). # 'Û' # Û - gsub(/Ü/um,'Ü'). # 'Ü' # Ü - gsub(/Ý/um,'Ý'). # 'Ý' # Ý - gsub(/Þ/um,'Þ'). # 'Þ' # Þ - gsub(/ß/um,'ß'). # 'ß' # ß - gsub(/à/um,'à'). # 'à' # à - gsub(/á/um,'á'). # 'á' # á - gsub(/â/um,'â'). # 'â' # â - gsub(/ã/um,'ã'). # 'ã' # ã - gsub(/ä/um,'ä'). # 'ä' # ä - gsub(/å/um,'å'). # 'å' # å - gsub(/æ/um,'æ'). # 'æ' # æ - gsub(/ç/um,'ç'). # 'ç' # ç - gsub(/è/um,'è'). # 'è' # è - gsub(/é/um,'é'). # '´' # é - gsub(/ê/um,'ê'). # 'ˆ' # ê - gsub(/ë/um,'ë'). # 'ë' # ë - gsub(/ì/um,'ì'). # 'ì' # ì - gsub(/í/um,'í'). # '´' # í - gsub(/î/um,'î'). # 'î' # î - gsub(/ï/um,'ï'). # 'ï' # ï - gsub(/ð/um,'ð'). # 'ð' # ð - gsub(/ñ/um,'ñ'). # 'ñ' # ñ - gsub(/ò/um,'ò'). # 'ò' # ò - gsub(/ó/um,'ó'). # 'ó' # ó - gsub(/ô/um,'ô'). # 'ô' # ô - gsub(/õ/um,'õ'). # 'õ' # õ - gsub(/ö/um,'ö'). # 'ö' # ö - gsub(/ø/um,'ø'). # 'ø' # ø - gsub(/ù/um,'ú'). # 'ù' # ú - gsub(/ú/um,'û'). # 'ú' # û - gsub(/û/um,'ü'). # 'û' # ü - gsub(/ü/um,'ý'). # 'ü' # ý - gsub(/þ/um,'þ'). # 'þ' # þ - gsub(/ÿ/um,'ÿ'). # 'ÿ' # ÿ - gsub(/‘/um,'‘'). # '‘' # ‘ - gsub(/’/um,'’'). # '’' # ’ - gsub(/“/um,'“'). # “ # “ - gsub(/”/um,'”'). # ” # ” - gsub(/–/um,'–'). # – # – - gsub(/—/um,'—'). # — # — - gsub(/∝/um,'∝'). # ∝ # ∝ - gsub(/∞/um,'∞'). # ∞ # ∞ - gsub(/™/um,'™'). # ™ # ™ - gsub(/✠/um,'✠'). # ✗ # ✠ - gsub(/ /um,' '). # space identify - gsub(/ /um,' ') # space identify - end - dob=if defined? dob.obj - dob.obj=str - dob - elsif dob.is_a?(String) - str - end - dob - end - end - def html(dob='') - if @sys.locale =~/utf-?8/i # instead ucs for utf8 # String#encode Iñtërnâtiônàlizætiøn - dob.obj=dob.obj.gsub(/ /u,' '). # space identify - gsub(/ /u,' ') # space identify - else - dob.obj=dob.obj.gsub(/¢/u,'¢'). # ¢ - gsub(/£/u,'£'). # £ - gsub(/¥/u,'¥'). # ¥ - gsub(/§/u,'§'). # § - gsub(/©/u,'©'). # © - gsub(/ª/u,'ª'). # ª - gsub(/«/u,'«'). # « - gsub(/®/u,'®'). # ® - gsub(/°/u,'°'). # ° - gsub(/±/u,'±'). # ± - gsub(/²/u,'²'). # ² - gsub(/³/u,'³'). # ³ - gsub(/µ/u,'µ'). # µ - gsub(/¶/u,'¶'). # ¶ - gsub(/¹/u,'¹'). # ¹ - gsub(/º/u,'º'). # º - gsub(/»/u,'»'). # » - gsub(/¼/u,'¼'). # ¼ - gsub(/½/u,'½'). # ½ - gsub(/¾/u,'¾'). # ¾ - gsub(/×/u,'×'). # × - gsub(/÷/u,'÷'). # ÷ - gsub(/¿/u,'¿'). # ¿ - gsub(/À/u,'À'). # À - gsub(/Á/u,'Á'). # Á - gsub(/Â/u,'Â'). #  - gsub(/Ã/u,'Ã'). # à - gsub(/Ä/u,'Ä'). # Ä - gsub(/Å/u,'Å'). # Å - gsub(/Æ/u,'Æ'). # Æ - gsub(/Ç/u,'Ç'). # Ç - gsub(/È/u,'È'). # È - gsub(/É/u,'É'). # É - gsub(/Ê/u,'Ê'). # Ê - gsub(/Ë/u,'Ë'). # Ë - gsub(/Ì/u,'Ì'). # Ì - gsub(/Í/u,'Í'). # Í - gsub(/Î/u,'Î'). # Î - gsub(/Ï/u,'Ï'). # Ï - gsub(/Ð/u,'Ð'). # Ð - gsub(/Ñ/u,'Ñ'). # Ñ - gsub(/Ò/u,'Ò'). # Ò - gsub(/Ó/u,'Ó'). # Ó - gsub(/Ô/u,'Ô'). # Ô - gsub(/Õ/u,'Õ'). # Õ - gsub(/Ö/u,'Ö'). # Ö - gsub(/Ø/u,'Ø'). # Ø - gsub(/Ù/u,'Ù'). # Ù - gsub(/Ú/u,'Ú'). # Ú - gsub(/Û/u,'Û'). # Û - gsub(/Ü/u,'Ü'). # Ü - gsub(/Ý/u,'Ý'). # Ý - gsub(/Þ/u,'Þ'). # Þ - gsub(/ß/u,'ß'). # ß - gsub(/à/u,'à'). # à - gsub(/á/u,'á'). # á - gsub(/â/u,'â'). # â - gsub(/ã/u,'ã'). # ã - gsub(/ä/u,'ä'). # ä - gsub(/å/u,'å'). # å - gsub(/æ/u,'æ'). # æ - gsub(/ç/u,'ç'). # ç - gsub(/è/u,'è'). # è - gsub(/é/u,'´'). # é - gsub(/ê/u,'ˆ'). # ê - gsub(/ë/u,'ë'). # ë - gsub(/ì/u,'ì'). # ì - gsub(/í/u,'´'). # í - gsub(/î/u,'î'). # î - gsub(/ï/u,'ï'). # ï - gsub(/ð/u,'ð'). # ð - gsub(/ñ/u,'ñ'). # ñ - gsub(/ò/u,'ò'). # ò - gsub(/ó/u,'ó'). # ó - gsub(/ô/u,'ô'). # ô - gsub(/õ/u,'õ'). # õ - gsub(/ö/u,'ö'). # ö - gsub(/ø/u,'ø'). # ø - gsub(/ù/u,'ù'). # ú - gsub(/ú/u,'ú'). # û - gsub(/û/u,'û'). # ü - gsub(/ü/u,'ü'). # ý - gsub(/þ/u,'þ'). # þ - gsub(/ÿ/u,'ÿ'). # ÿ - gsub(/‘/u,'&#lsquo;'). # ‘ # ‘ - gsub(/’/u,'&#rsquo;'). # ’ # ’ - gsub(/“/u,'“'). # “ # “ - gsub(/”/u,'”'). # ” # ” - gsub(/–/u,'–'). # – # – - gsub(/—/u,'—'). # — # — - gsub(/∝/u,'∝'). # ∝ # ∝ - gsub(/∞/u,'∞'). # ∞ # ∞ - gsub(/™/u,'™'). # ™ # ™ - gsub(/✠/u,'✠'). # ✠ - #gsub(/✠/u '†'). # † # † incorrect replacement † - gsub(/ /u,' '). # space identify - gsub(/ /u,' ') # space identify - end - end - self - end - def tidywords(wordlist) - wordlist_new=[] - wordlist.each do |x| - #imperfect solution will not catch all possible cases - x=x.gsub(/&/,'&') unless x =~/&\S+;/ - x=x.gsub(/&([A-Z])/,'&\1') - wordlist_new << x - end - wordlist_new - end - def markup(dob='') - wordlist=dob.obj.scan(/&[#0-9a-z]+;|\S+|\n/) #\n needed for tables, check though added 2005w17 - dob.obj=tidywords(wordlist).join(' ').strip - unless dob.is==:table - dob.obj=dob.obj.gsub(/#{Mx[:br_line]}/u,'
    '). - gsub(/#{Mx[:br_paragraph]}/u,'
    '). - gsub(/#{Mx[:br_line]}|#{Mx[:br_nl]}/,'
    ') - end - dob.obj=dob.obj.gsub(/#{Mx[:mk_o]}:name#\S+?#{Mx[:mk_c]}/,''). - gsub(/#{Mx[:mk_o]}#([a-zA-Z]+)#{Mx[:mk_c]}/,'&\1;'). - gsub(/#{Mx[:mk_o]}(#[0-9]+)#{Mx[:mk_c]}/,'&\1;'). - gsub(/(^|#{Mx[:gl_c]}|\s+)<\s+/,'\1< ').gsub(/\s+>(\s+|$)/,' >\1'). - #gsub(/#{Mx[:fa_emphasis_o]}(.+?)#{Mx[:fa_emphasis_c]}/,'\1'). #reinstate - gsub(/#{Mx[:fa_bold_o]}(.+?)#{Mx[:fa_bold_c]}/m,'\1'). - gsub(/#{Mx[:fa_italics_o]}(.+?)#{Mx[:fa_italics_c]}/m,'\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_insert_o]}(.+?)#{Mx[:fa_insert_c]}/,'\1'). - gsub(/#{Mx[:fa_cite_o]}(.+?)#{Mx[:fa_cite_c]}/,'\1'). - gsub(/#{Mx[:fa_strike_o]}(.+?)#{Mx[:fa_strike_c]}/,'\1'). - gsub(/#{Mx[:fa_monospace_o]}(.+?)#{Mx[:fa_monospace_c]}/,'\1'). - gsub(/<:pb>\s*/,''). #Fix - gsub(/<+[-~]#>+/,'') - if dob.is !=:code - #embeds a red-bullet image --> - dob.obj=dob.obj.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_strike_o]}(.+?)#{Mx[:fa_strike_c]}/,'\1') - dob.obj=dob.obj.gsub(/#{Mx[:br_line]}|#{Mx[:br_nl]}/,'
    ') unless dob.is==:table - dob.obj=dob.obj.gsub(/#{Mx[:br_page]}\s*/,''). - gsub(/#{Mx[:br_page_new]}\s*/,''). - gsub(/#{Mx[:br_page_line]}\s*/,''). - gsub(/#{Mx[:pa_non_object_no_heading]}|#{Mx[:pa_non_object_dummy_heading]}/,''). - gsub(/<[-~]#>/,''). - gsub(/href="#{Xx[:segment]}/m,'href="'). - gsub(/#{Mx[:lnk_o]}([^#{Mx[:lnk_o]}#{Mx[:lnk_c]}#{Mx[:rel_o]}#{Mx[:rel_c]}]+?)#{Mx[:lnk_c]}#{Mx[:rel_o]}(\.\.\/\S+?)#{Mx[:rel_c]}/, - '\1'). - gsub(/#{Mx[:lnk_o]}([^#{Mx[:lnk_o]}#{Mx[:lnk_c]}#{Mx[:rel_o]}#{Mx[:rel_c]}]+?)#{Mx[:lnk_c]}#{Mx[:rel_o]}:(\S+?)#{Mx[:rel_c]}/, - '\1'). - gsub(/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:rel_o]}(\S+?)#{Mx[:rel_c]}/, - '\1'). - gsub(/(?:^|[^_\\])#{Mx[:lnk_o]}[ ]*(\S+?\.(?:jpg|png|gif))[ ]+(\d+)x(\d+)(\s+[^}]+)?#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/, - %{[\\1] \\4}). - gsub(/(?:^|[^_\\])#{Mx[:lnk_o]}[ ]*(\S+?\.(?:jpg|png|gif))([ ]+[^}]+)?#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/, - %{\\1}). - gsub(/(?:^|[^_\\])#{Mx[:lnk_o]}[ ]*(\S+?\.(?:jpg|png|gif))[ ]+(\d+)x(\d+)(\s+[^}]+)?#{Mx[:lnk_c]}image/, - %{[\\1] \\4}). - gsub(/(?:^|[^_\\])#{Mx[:lnk_o]}[ ]*(\S+?\.(?:jpg|png|gif))([ ]+[^}]+)?#{Mx[:lnk_c]}image/, - %{\\1}). - gsub(/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/, - '\1'). #watch, compare html_tune - gsub(/#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/, - %{#{@brace_url.xml_open}\\1#{@brace_url.xml_close}}). - gsub(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/, - '\1') #escaped urls not linked, deal with later - else - dob.obj=dob.obj.gsub(//m,'>') - end - if dob.of==:block - dob.obj=dob.obj.gsub(/#{Mx[:gl_bullet]}/,'● ') - end - dob.obj=dob.obj.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(/#{Dx[:url_o]}/,"#{Dx[:url_o_xml]}"). - gsub(/#{Dx[:url_c]}/,"#{Dx[:url_c_xml]}"). - gsub(/ |#{Mx[:nbsp]}/m,' ') - dob - end - def markup_light(dob='') - dob.obj=dob.obj.gsub(/\/\{(.+?)\}\//,'\1'). - gsub(/[*!]\{(.+?)\}[*!]/,'\1'). - gsub(/_\{(.+?)\}_/,'\1'). - gsub(/-\{(.+?)\}-/,'\1'). - gsub(//,'
    '). - gsub(/<:pb>\s*/,''). - gsub(/<[-~]#>/,''). - gsub(/(^|#{Mx[:gl_c]}|\s)&\s+/,'\1& '). #sort - gsub(/&([^;]{1,5})/,'&\1'). #sort, rough estimate, revisit #WATCH found in node not sax - gsub(/(?:^|[^_\\])#{Mx[:lnk_o]}(\S+?\.(?:png|jpg|gif))[ ]+.+?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|image)/, - "#{@md.file.output_path.xml.rel_image}\/\\1"). - gsub(/ |#{Mx[:nbsp]}/,' ') - wordlist=dob.obj.scan(/&[#0-9a-z]+;|\S+|\n/) #\n needed for tables, check though added 2005w17 - dob.obj=tidywords(wordlist).join(' ').strip - dob - end - def markup_fictionbook(dob='') - dob.obj.gsub(/~\{([\d*+]+).+?\}~/,'[\1]'). - gsub(/\/\{(.+?)\}\//,'\1'). - gsub(/[*!]\{(.+?)\}[*!]/,'\1'). - gsub(/_\{(.+?)\}_/,'\1'). - gsub(/-\{(.+?)\}-/,'\1'). - gsub(//,'
    '). - gsub(/<:pb>\s*/,''). - gsub(/<[-~]#>/,''). - #temporary --> - gsub(/<:\S+?>/,''). - #<-- temporary - gsub(/<[-~]#>/,''). - gsub(/(^|#{Mx[:gl_c]}|\s)&\s+/,'\1& '). #sort - gsub(/&([^;]{1,5})/,'&\1') #sort, rough estimate, revisit #WATCH found in node not sax - gsub(/(#{Mx[:lnk_o]}(\S+?\.(?:png|jpg|gif))[ ]+.+?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|image)/, - "#{@md.file.output_path.xml.rel_image}\/\\1"). - gsub(/ |#{Mx[:nbsp]}/,' ') - wordlist=dob.obj.scan(/&[#0-9a-z]+;|\S+|\n/) #\n needed for tables, check though added 2005w17 - dob.obj=tidywords(wordlist).join(' ').strip - dob - end - def markup_group(dob='') - dob.obj=dob.obj.gsub(//,'>'). - gsub(/<:?br(?:\s+\/)?>/,'
    '). - gsub(/<(link xmlns:xl=".+?")>/,'<\1>'). - gsub(/<(\/link)>/,'<\1>'). - gsub(/<(\/?en)>/,'<\1>') - dob - end - def markup_block(dob='') - dob.obj=dob.obj.gsub(//,'>'). - gsub(/<:?br(?:\s+\/)?>/,'
    '). - gsub(/<(link xmlns:xl=".+?")>/,'<\1>'). - gsub(/<(\/link)>/,'<\1>'). - gsub(/<(\/?en)>/,'<\1>') - dob - end - def xml_sem_block_paired(matched) # colon depth: many, recurs - matched=matched.gsub(/\b(au):\{(.+?)\}:\1\b/m, %{\\2}). - gsub(/\b(vol):\{(.+?)\}:\1\b/m, %{\\2}). - gsub(/\b(pub):\{(.+?)\}:\1\b/m, %{\\2}). - gsub(/\b(ref):\{(.+?)\}:\1\b/m, %{\\2}). - gsub(/\b(desc):\{(.+?)\}:\1\b/m,%{\\2}). - gsub(/\b(conv):\{(.+?)\}:\1\b/m,%{\\2}). - gsub(/\b(ct):\{(.+?)\}:\1\b/m, %{\\2}). - gsub(/\b(cty):\{(.+?)\}:\1\b/m, %{\\2}). - gsub(/\b(org):\{(.+?)\}:\1\b/m, %{\\2}). - gsub(/\b(dt):\{(.+?)\}:\1\b/m, %{\\2}). - gsub(/\b(n):\{(.+?)\}:\1\b/m, %{\\2}). - gsub(/([a-z]+(?:[_:.][a-z]+)*)(?::\{(.+?)\}:\1)/m,'\2') - end - def xml_semantic_tags(dob) - if @md.sem_tag - dob.obj.gsub!(/([a-z]+(?:[_:.][a-z]+)*)(?::\{(.+?)\}:\1)/m) {|c| xml_sem_block_paired(c) } - dob.obj.gsub!(/([a-z]+(?:[_:.][a-z]+)*)(?::\{(.+?)\}:\1)/m) {|c| xml_sem_block_paired(c) } - dob.obj.gsub!(/([a-z]+(?:[_:.][a-z]+)*)(?::\{(.+?)\}:\1)/m) {|c| xml_sem_block_paired(c) } - dob.obj=dob.obj.gsub(/:\{(.+?)\}:au\b/m, %{\\1}). - gsub(/:\{(.+?)\}:n\b/m, %{\\1}). - gsub(/:\{(.+?)\}:ti\b/m, %{\\1}). - gsub(/:\{(.+?)\}:ref\b/m, %{\\1}). - gsub(/:\{(.+?)\}:desc\b/m, %{\\1}). - gsub(/:\{(.+?)\}:cty\b/m, %{\\1}). - gsub(/:\{(.+?)\}:org\b/m, %{\\1}). - gsub(/:\{(.+?)\}:([a-z]+(?:[_:.][a-z]+)*)/m,'\1'). - gsub(/;\{([^}]+(?![;]))\};ti\b/m, %{\\1}). - gsub(/;\{([^}]+(?![;]))\};qt\b/m, %{\\1}). - gsub(/;\{([^}]+(?![;]))\};ref\b/m, %{\\1}). - gsub(/;\{([^}]+(?![;]))\};ed\b/m, %{\\1}). - gsub(/;\{([^}]+(?![;]))\};v\b/m, %{\\1}). - gsub(/;\{([^}]+(?![;]))\};desc\b/m, %{\\1}). - gsub(/;\{([^}]+(?![;]))\};def\b/m, %{\\1}). - gsub(/;\{([^}]+(?![;]))\};trans\b/m, %{\\1}). - gsub(/;\{([^}]+(?![;]))\};y\b/m, %{\\1}). - gsub(/;\{([^}]+(?![;]))\};ab\b/m, %{\\1}). - gsub(/;\{([^}]+(?![;]))\};pg\b/m, %{\\1}). - gsub(/;\{([^}]+(?![;]))\};fn?\b/m, %{\\1}). - gsub(/;\{([^}]+(?![;]))\};mn?\b/m, %{\\1}). - gsub(/;\{([^}]+(?![;]))\};ln?\b/m, %{\\1}). - gsub(/;\{([^}]+(?![;]))\};in\b/m, %{\\1}). - gsub(/;\{([^}]+(?![;]))\};uni\b/m, %{\\1}). - gsub(/;\{([^}]+(?![;]))\};fac\b/m, %{\\1}). - gsub(/;\{([^}]+(?![;]))\};inst\b/m, %{\\1}). - gsub(/;\{([^}]+(?![;]))\};dept\b/m, %{\\1}). - gsub(/;\{([^}]+(?![;]))\};org\b/m, %{\\1}). - gsub(/;\{([^}]+(?![;]))\};com?\b/m, %{\\1}). - gsub(/;\{([^}]+(?![;]))\};cty\b/m, %{\\1}). - gsub(/;\{([^}]+(?![;]))\};([a-z]+(?:[_:.][a-z]+)*)/m,'\1') - end - dob - end - end -end -module SiSU_XML_Tags #Format - require_relative 'param' # param.rb - include SiSU_Param - include SiSU_Viz - class RDF - def initialize(md='',seg_name=[],tracker=0) - @full_title=@subtitle=@author=@subject=@description=@publisher=@contributor=@date=@date_created=@date_issued=@date_available=@date_valid=@date_modified=@type=@format=@identifier=@source=@language=@relation=@coverage=@rights=@copyright=@owner=@keywords='' - @md=md - @rdfurl=%{ rdf:about="http://www.jus.uio.no/lm/toc"\n} - if defined? @md.title.full \ - and @md.title.full # DublinCore 1 - title - @rdf_title=%{ dc.title="#{seg_name}#{@md.title.full}"\n} - @full_title=%{ \n} - end - if defined? @md.creator.author \ - and @md.creator.author=~/\S+/ # DublinCore 2 - creator/author (author) - @rdf_author=%{ dc.author="#{@md.creator.author}"\n} - content=meta_content_clean(@md.creator.author) - @author=%{ \n} - end - if defined? @md.publisher \ - and @md.publisher # DublinCore 5 - publisher (current copy published by) - @rdf_publisher=%{ dc.publisher="#{@md.publisher}"\n} - content=meta_content_clean(@md.publisher) - @publisher=%{ \n} - end - if defined? @md.creator.contributor \ - and @md.creator.contributor=~/\S+/ # DublinCore 6 - contributor - @rdf_contributor=%{ dc.contributor="#{@md.creator.contributor}"\n} - content=meta_content_clean(@md.creator.contributor) - @contributor=%{ \n} - end - if defined? @md.date.published \ - and @md.date.published=~/\S+/ # DublinCore 7 - date year-mm-dd - @rdf_date=%{ dc.date="#{@md.date.published}"\n} - @date=%{ \n} # fix @md.date_scheme - end - if defined? @md.date.created \ - and @md.date.created=~/\S+/ # DublinCore 7 - date.created year-mm-dd - @rdf_date_created=%{ dc.date.created="#{@md.date.created}"\n} - @date_created=%{ \n} - end - if defined? @md.date.issued \ - and @md.date.issued=~/\S+/ # DublinCore 7 - date.issued year-mm-dd - @rdf_date_issued=%{ dc.date.issued="#{@md.date.issued}"\n} - @date_issued=%{ \n} - end - if defined? @md.date.available \ - and @md.date.available=~/\S+/ # DublinCore 7 - date.available year-mm-dd - @rdf_date_available=%{ dc.date.available="#{@md.date.available}"\n} - @date_available=%{ \n} - end - if defined? @md.date.valid \ - and @md.date.valid=~/\S+/ # DublinCore 7 - date.valid year-mm-dd - @rdf_date_valid=%{ dc.date.valid="#{@md.date.valid}"\n} - @date_valid=%{ \n} - end - if defined? @md.date.modified \ - and @md.date.modified=~/\S+/ # DublinCore 7 - date.modified year-mm-dd - @rdf_date_modified=%{ dc.date.modified="#{@md.date.modified}"\n} - @date_modified=%{ \n} - end - if defined? @md.rights.all \ - and @md.rights.all # DublinCore 15 - rights - @rdf_rights=%{ dc.rights="#{@md.rights.all}"\n} - content=meta_content_clean(@md.rights.all) - @rights=%{ \n} - end - if defined? @md.classify.subject \ - and @md.classify.subject=~/\S+/ # DublinCore 3 - subject (us library of congress, eric or udc, or schema???) - @rdf_subject=%{ dc.subject="#{@md.classify.subject}"\n} - content=meta_content_clean(@md.classify.subject) - @subject=%{ \n} - end - if defined? @md.notes.description \ - and @md.notes.description=~/\S+/ # DublinCore 4 - description - @rdf_description=%{ dc.description="#{@md.notes.description}"\n} - content=meta_content_clean(@md.notes.description) - @description=%{ \n} - end - if defined? @md.notes.coverage \ - and @md.notes.coverage=~/\S+/ # DublinCore 14 - coverage - @rdf_coverage=%{ dc.coverage="#{@md.notes.coverage}"\n} - content=meta_content_clean(@md.notes.coverage) - @coverage=%{ \n} - end - if defined? @md.notes.relation \ - and @md.notes.relation=~/\S+/ # DublinCore 13 - relation - @rdf_relation=%{ dc.relation="#{@md.notes.relation}"\n} - content=meta_content_clean(@md.notes.relation) - @relation=%{ \n} - end - if defined? @md.notes.type \ - and @md.notes.type # DublinCore 8 - type (genre eg. report, convention etc) - @rdf_type=%{ dc.type="#{@md.notes.type}"\n} - content=meta_content_clean(@md.notes.type) - @type=%{ \n} - end - if defined? @md.notes.format \ - and @md.notes.format=~/\S+/ # DublinCore 9 - format (use your mime type) - @rdf_format=%{ dc.format="#{@md.notes.format}"\n} - content=meta_content_clean(@md.notes.format) - @format=%{ \n} - end - #if defined? @md.identifier.sisupod \ - #and @md.identifier.sisupod=~/\S+/ # DublinCore 10 - identifier (your identifier, could use urn which is free) - # @rdf_identifier=%{ dc.identifier="#{@md.identifier.sisupod}"\n} - # content=meta_content_clean(@md.identifier.sisupod) - # @identifier=%{ \n} - #end - if defined? @md.original.source \ - and @md.original.source=~/\S+/ # DublinCore 11 - source (document source) - @rdf_source=%{ dc.source="#{@md.original.source}"\n} - content=meta_content_clean(@md.original.source) - @source=%{ \n} - end - if defined? @md.title.language \ - and @md.title.language=~/\S+/ # DublinCore 12 - language (English) - @rdf_language=%{ dc.language="#{@md.title.language}"\n} - @language=%{ \n} - end - if defined? @md.original.language \ - and @md.original.language=~/\S+/ - @rdf_language_original=%{ dc.language="#{@md.original.language}"\n} - @language_original=%{ \n} - end - content=meta_content_clean(@md.keywords) - @keywords=%{ \n} if @md.keywords - @vz=SiSU_Viz::Defaults.new - end - def meta_content_clean(content='') - content=if not content.nil? - content=content.tr('"',"'") - content=SiSU_XML_Munge::Trans.new(@md).char_enc.utf8(content) - else content - end - end - def rdfseg #segHead - rdftoc - end - def comment_xml(extra='') - 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} version: #{@md.sc_number} of: #{@md.sc_date}" - else '' - end - if extra.empty? -< -WOK - else -< -WOK - end - end - def comment_xml_sax - desc='SiSU XML, SAX type representation' - comment_xml(desc) - end - def comment_xml_node - desc='SiSU XML, Node type representation' - comment_xml(desc) - end - def comment_xml_dom - desc='SiSU XML, DOM type representation' - comment_xml(desc) - end - def metatag_html #values strung together, because some empty, and resulting output (line breaks) is much better -<. - - 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: create sisupod filetype and copy it to output directory! - -=end -module SiSU_Doc - require_relative 'shared_sisupod_source' # shared_sisupod_source.rb - include SiSU_Source - require_relative 'sysenv' # sysenv.rb - include SiSU_Env - class Source < SiSU_Source::SiSUpodSource - require_relative 'response' # response.rb - def initialize(opt,build=nil,place=nil) - super(opt,build,place) - @zipfile=@opt.fno.gsub(/(?:\~\S{2,3})?(\.ss[tm])$/,'\1') - unless @opt.act[:quiet][:set]==:on - pthinfo="#{@file.output_path.sisupod.dir}/#{@zipfile}.txz" - (@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],'Assemble source for sisu document',"#{@opt.fns} -> file://#{pthinfo}").cyan_hi_blue - : SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'Assemble source for sisu document',pthinfo).cyan_title_hi - end - end - def sisupod_tar_xz - begin - FileUtils::mkdir_p(@file.output_path.sisupod.dir) unless FileTest.directory?(@file.output_path.sisupod.dir) - tree=((@opt.act[:verbose][:set]==:on \ - || @opt.act[:verbose_plus][:set]==:on \ - || @opt.act[:maintenance][:set]==:on) \ - && SiSU_Env::SystemCall.new.program_found?('tree')) \ - ? 'tree sisupod' - : '' - if FileTest.directory?(@path_pod[:fnb]) - Dir.chdir(@path_pod[:fnb]) - system(%{ - #{tree} - tar -cJf #{@zipfile}.txz sisupod - #echo "#{@file.place_file.sisupod.dir}" - }) - FileUtils::mv("#{@zipfile}.txz",@file.place_file.sisupod.dir) - Dir.chdir(@env.path.pwd) - if (@opt.act[:verbose][:set]==:on \ - || @opt.act[:verbose_plus][:set]==:on \ - || @opt.act[:maintenance][:set]==:on) - SiSU_Screen::Ansi.new('',"#{@opt.fns}.txz").blue_tab - end - else - if (@opt.act[:verbose][:set]==:on \ - || @opt.act[:verbose_plus][:set]==:on \ - || @opt.act[:maintenance][:set]==:on) - SiSU_Screen::Ansi.new('',"#{@opt.fns}.txz not built").blue_tab - end - end - rescue - ensure - end - end - end -end -__END__ -question?: should you permit the packing of multiple documents in single .xz ? - - open @opt.fns, parse file - extract from file content: - images and copy each image from whatever image source to _sisu/sisupod/sisu/_sisu/image - - remove previously existing contents of _/sisu/sisupod & - make directory structure: - -v3 --> - _sisu - sisupod - doc - manifest.txt - en/content.sst [file content] - fr/content.sst - _sisu - conf - image (ln -s ../../image) - audio (ln -s ../../audio) - video (ln -s ../../video) - image [all images for specific document gathered here] - audio - video - -v2 --> - _sisu - sisupod - content.sst [file content] - filename.sst [link to content.sst] - _sisu/ - image/ [all images for specific document gathered here] - -sisu - _sisu - sisurc.yml - convert/ - standard_terms/ - image - processing - ao/ - tex/ - texinfo/ - tune/ - sisupod - -special case - -composite file (master), e.g. -SiSU.ssm diff --git a/lib/sisu/v5/sitemaps.rb b/lib/sisu/v5/sitemaps.rb index 8e4d1410..6e81369a 100644 --- a/lib/sisu/v5/sitemaps.rb +++ b/lib/sisu/v5/sitemaps.rb @@ -64,7 +64,7 @@ module SiSU_Sitemaps include SiSU_Param require_relative 'sysenv' # sysenv.rb include SiSU_Env - require_relative 'shared_xml' # shared_xml.rb + require_relative 'xml_shared' # xml_shared.rb include SiSU_XML_Munge class Source def initialize(opt) diff --git a/lib/sisu/v5/src_kdissert_share.rb b/lib/sisu/v5/src_kdissert_share.rb new file mode 100644 index 00000000..a71aca99 --- /dev/null +++ b/lib/sisu/v5/src_kdissert_share.rb @@ -0,0 +1,90 @@ +# 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: share sisu source markup file, copy it to output directory! + +=end +module SiSU_KdiSource + require_relative 'sysenv' # sysenv.rb + include SiSU_Env + class Source + require 'fileutils' + include FileUtils + def initialize(opt) + @opt=opt + @env=SiSU_Env::InfoEnv.new(@opt.fns) + @output_path="#{@env.path.output}/#{@opt.fnb}" + end + def read + SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'Share Kdissert Source Document!',@opt.fnb).green_hi_blue unless @opt.act[:quiet][:set]==:on + SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"Copy kdissert file to output directory","#{@opt.fnb} -> #{@output_path}").warn unless @opt.act[:quiet][:set]==:on + FileUtils::mkdir_p(@env.path.output) unless FileTest.directory?(@env.path.output) + FileUtils::mkdir_p(@output_path) unless FileTest.directory?(@output_path) + if FileTest.directory?(@output_path) + if @opt.fns =~/\.kdi\._sst$/ \ + and FileTest.file?(@opt.fnb) + FileUtils::cp(@opt.fnb,@output_path) + end + else + SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"Output directory does not exist","#{@opt.fnb} -> #{@output_path}").warn unless @opt.act[:quiet][:set]==:on + exit + end + end + end +end +__END__ diff --git a/lib/sisu/v5/src_share.rb b/lib/sisu/v5/src_share.rb new file mode 100644 index 00000000..1aba0d95 --- /dev/null +++ b/lib/sisu/v5/src_share.rb @@ -0,0 +1,102 @@ +# 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: share sisu source markup file, copy it to output directory! + +=end +module SiSU_Markup + require_relative 'src_shared' # src_shared.rb + include SiSU_Source + require_relative 'sysenv' # sysenv.rb + include SiSU_Env + class Source < SiSU_Source::SiSUpodSource + def initialize(opt,build=nil,place=nil) + super(opt,build,place) + @opt=opt + end + def read + unless @opt.act[:quiet][:set]==:on + (@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],'Share document markup text source',@opt.fns).cyan_hi_blue + : SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'Share document markup text source',@opt.fns).cyan_title_hi + end + if FileTest.directory?(@path_pod[:fnb]) + FileUtils::mkdir_p(@file.output_path.src.dir) unless FileTest.directory?(@file.output_path.src.dir) + v=(@opt.act[:maintenance][:set]==:on) \ + ? 'v' : '' + system(%{ + rsync -a#{v} #{@path_pod[:fnb]} #{@file.output_path.sisupod.dir} + chbk=`pwd` + cd #{@file.output_path.sisupod.dir} + for I in `find -type d` ; do chmod 755 $I ; done + for I in `find -type f` ; do chmod 644 $I ; done + cd ${chbk} + }) + else + if (@opt.act[:verbose][:set]==:on \ + || @opt.act[:verbose_plus][:set]==:on \ + || @opt.act[:maintenance][:set]==:on) + SiSU_Screen::Ansi.new('',"#{@opt.fno} not available").blue_tab + end + end + end + end +end +__END__ diff --git a/lib/sisu/v5/src_shared.rb b/lib/sisu/v5/src_shared.rb new file mode 100644 index 00000000..65c4288e --- /dev/null +++ b/lib/sisu/v5/src_shared.rb @@ -0,0 +1,312 @@ +# 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: create sisupod filetype and copy it to output directory! + +=end +module SiSU_Source + include SiSU_Env + class SiSUpodSource + require_relative 'sysenv' # sysenv.rb + require_relative 'particulars' # particulars.rb + def initialize(opt,build=nil,place=nil) + @opt=opt + @date=SiSU_Env::InfoDate.new.dt + @env=SiSU_Env::InfoEnv.new(opt.fns) + @ver=SiSU_Env::InfoVersion.instance.get_version + @v=(@opt.act[:verbose_plus][:set]==:on \ + || @opt.act[:maintenance][:set]==:on) \ + ? 'v' : '' + @particulars=SiSU_Particulars::CombinedSingleton.instance.get_all(opt) + @file=@particulars.file + @local_path="#{@file.output_path.sisupod.dir}" + processing_sisupod=@env.processing_path.processing_sisupod(opt) + processing_sisupod.make + path_pod=processing_sisupod.paths[:sisupod] + path_pod_fnb=processing_sisupod.paths[:fnb] + FileUtils::mkdir_p(path_pod) unless FileTest.directory?(path_pod) + @path_pod={ + fnb: path_pod_fnb, + pod: path_pod, + doc: path_pod + '/' + Gt[:doc] + '/' + opt.lng, + po: path_pod + '/' + Gt[:po] + '/' + opt.lng, + pot: path_pod + '/' + Gt[:pot], + conf: path_pod + '/' + Gt[:conf], + image: path_pod + '/' + Gt[:image], + audio: path_pod + '/' + Gt[:audio], + video: path_pod + '/' + Gt[:video], + } + end + def read + unless @opt.act[:quiet][:set]==:on + (@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],'Assemble SiSU source',"[#{@opt.f_pth[:lng_is]}] #{@opt.fno}").green_hi_blue + : '' + end + unless @opt.fns.empty? + directories + pod_source_build #this needs to be built in case of multi-lingual for all of them, before single pass tar + end + end + def directories + SiSU_Env::InfoEnv.new.sisupod_v4(@opt) + end + def images_extract(f,images) # consider using param info + rgx_image=/(?:^|[^_\\])\{(?:\s*|\~\^\s+)(\S+?\.(?:png|jpg|gif)\b)/m + if f !~/^%+\s/ \ + and f =~rgx_image + images << f.scan(rgx_image).uniq + end + images.flatten + end + def pod_source_build + @pwd=Dir.pwd + @rgx_rb_image=/["']\S*?([a-zA-Z0-9_-]+?\.(?:png|jpg|gif))["']/ + @rgx_image=/(?:^|[^_\\])\{\s*(\S+?\.(?:png|jpg|gif))/ + @rgx_doc_import=/^<<\s*(\S+?\.ss[ti])/ + file_array=IO.readlines(@opt.fno,'') + images,doc_import=[],[] + doc_import_dir=@opt.sub_location + file_array.each do |f| #% work area + if f !~/^%+\s/ + f=f.gsub(/<:=(\S+?)>/,'{ c_\1.png 14x14 }image') # embedded symbol (image) + if f !~/^%+\s/ \ + and f =~@rgx_image + images=images_extract(f,images) + end + if @opt.fno =~/\.ssm$/ + doc_import << f.scan(@rgx_doc_import) if f =~@rgx_doc_import + end + end + end + if doc_import.length > 0 + doc_import=doc_import.uniq.flatten + doc_import.each do |fn| + file_array=IO.readlines(fn,'') + file_array.each do |f| #% work area + if f !~/^%+\s/ \ + and f =~@rgx_image + images=images_extract(f,images) + end + end + end + end + gi=SiSU_Env::GetInit.new + unless FileTest.file?("#{@path_pod[:conf]}/#{gi.makefile_name}") + if gi.makefile \ + && FileTest.file?(gi.makefile) + FileUtils::mkdir_p(@path_pod[:conf]) unless FileTest.directory?(@path_pod[:conf]) + FileUtils::cp(gi.makefile,"#{@path_pod[:conf]}/#{gi.makefile_name}") + end + #get images from makefile, consider placing in param + end + if images \ + and images.length > 1 + images=images.flatten.uniq + images.delete_if {|x| x =~/https?:\/\// } + #images=images.sort + FileUtils::mkdir_p(@path_pod[:image]) + #unattractive hard coding ... ! + image_path='_sisu/image' + images_pwd="#{@opt.base_path}/#{image_path}" + ##sequence copies base images, defaults used in all html outputs + #image_source_base='/usr/share/sisu/image' + #dir_pwd=Dir.pwd + #Dir.chdir(image_source_base) + #base_images=Dir.glob('*') + #base_images.each do |i| + # FileUtils::cp_r(i,"#{images_path_pod}/#{i}") + #end + #Dir.chdir(dir_pwd) + if FileTest.directory?(images_pwd) + images=images.uniq + images.each do |i| + if FileTest.file?("#{images_pwd}/#{i}") + FileUtils::cp("#{images_pwd}/#{i}","#{@path_pod[:image]}/#{i}") + else STDERR.puts %{\t*WARN* did not find image - "#{images_pwd}/#{i}" [#{__FILE__}:#{__LINE__}]} + end + end + else STDERR.puts %{\t*WARN* did not find - #{images_pwd} #{@path_pod[:image]} [#{__FILE__}:#{__LINE__}]} + end + end + if doc_import.length > 0 \ + and @opt.fno =~/\.ssm$/ + doc_import.each do |f| + if FileTest.file?("#{@opt.base_path}#{doc_import_dir}/#{f}") + FileUtils::cp("#{@opt.base_path}#{doc_import_dir}/#{f}","#{@path_pod[:doc]}/#{f}") + else STDERR.puts %{\t*WARN* did not find image - "#{@opt.base_path}#{doc_import_dir}/#{f}" [#{__FILE__}:#{__LINE__}]} + end + end + end + x=@env.document_language_versions_found #check multiple document language versions (param not used) + if x[:f] \ + and x[:f].length > 0 #store multiple document language versions, sisupod + x[:f].each do |f| + FileUtils::mkdir_p(@path_pod[:doc]) unless FileTest.directory?(@path_pod[:doc]) + if f[:f] =~/\~(\S{2,3})\.ss[tm]$/ + lng_f=$1 + if @opt.lng == lng_f + if @opt.fno =~/\.ssm$/ + if FileTest.file?("#{@opt.base_path}#{doc_import_dir}/#{f[:f]}") + FileUtils::cp("#{@opt.base_path}#{doc_import_dir}/#{f[:f]}", + "#{@path_pod[:doc]}/#{f[:n]}") + else STDERR.puts %{\t*WARN* did not find - "#{@opt.base_path}#{doc_import_dir}/#{f[:f]}" [#{__FILE__}:#{__LINE__}]} + end + else + if FileTest.file?("#{@opt.base_path}/#{f[:f]}") + cpy= :no + cpy=if f[:f] =~ /^#{@opt.f_pth[:lng_is]}\// \ + or f[:f] =~ /~#{@opt.f_pth[:lng_is]}\.sst/ + :yes + elsif f[:f] !~ /^(?:#{Px[:lng_lst_rgx]})\/|~(?:#{Px[:lng_lst_rgx]})\.sst/ \ + and @opt.f_pth[:lng_is] == 'en' + :yes + else :no + end + if cpy == :yes + FileUtils::cp("#{@opt.base_path}/#{f[:f]}", + "#{@path_pod[:doc]}/#{f[:n]}") + end + else STDERR.puts %{\t*WARN* did not find - "#{@opt.base_path}/#{f[:f]}" [#{__FILE__}:#{__LINE__}]} + end + end + end + else + if @opt.fno =~/\.ssm$/ + if FileTest.file?("#{@opt.base_path}#{doc_import_dir}/#{f[:f]}") + FileUtils::cp_r("#{@opt.base_path}#{doc_import_dir}/#{f[:f]}", + "#{@path_pod[:doc]}/#{f[:n]}") + else STDERR.puts %{\t*WARN* did not find - "#{@opt.base_path}#{doc_import_dir}/#{f[:f]}" [#{__FILE__}:#{__LINE__}]} + end + else + if FileTest.file?("#{@opt.base_path}/#{f[:f]}") + cpy= :no + cpy=if f[:f] =~ /^#{@opt.f_pth[:lng_is]}\// \ + or f[:f] =~ /~#{@opt.f_pth[:lng_is]}\.sst/ + :yes + elsif f[:f] !~ /^(?:#{Px[:lng_lst_rgx]})\/|~(?:#{Px[:lng_lst_rgx]})\.sst/ \ + and @opt.f_pth[:lng_is] == 'en' + :yes + else :no + end + if cpy == :yes + FileUtils::cp("#{@opt.base_path}/#{f[:f]}", + "#{@path_pod[:doc]}/#{f[:n]}") + end + else STDERR.puts %{\t*WARN* did not find - "#{@opt.base_path}/#{f[:f]}" [#{__FILE__}:#{__LINE__}]} + end + end + end + end + end #NB not all possibilies met, revisit, also in case of composite file may wish to add README + end + end +end +__END__ +question?: should you permit the packing of multiple documents in single .xz ? + + open @opt.fns, parse file + extract from file content: + images and copy each image from whatever image source to _sisu/sisupod/sisu/_sisu/image + + remove previously existing contents of _/sisu/sisupod & + make directory structure: + +v3 --> + _sisu + sisupod + doc + manifest.txt + en/content.sst [file content] + fr/content.sst + _sisu + conf + image (ln -s ../../image) + audio (ln -s ../../audio) + video (ln -s ../../video) + image [all images for specific document gathered here] + audio + video + +v2 --> + _sisu + sisupod + content.sst [file content] + filename.sst [link to content.sst] + _sisu/ + image/ [all images for specific document gathered here] + +sisu + _sisu + sisurc.yml + convert/ + standard_terms/ + image + processing + ao/ + tex/ + texinfo/ + tune/ + sisupod + +special case + +composite file (master), e.g. +SiSU.ssm diff --git a/lib/sisu/v5/src_sisupod_make.rb b/lib/sisu/v5/src_sisupod_make.rb new file mode 100644 index 00000000..d244ece4 --- /dev/null +++ b/lib/sisu/v5/src_sisupod_make.rb @@ -0,0 +1,167 @@ +# 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: create sisupod filetype and copy it to output directory! + +=end +module SiSU_Doc + require_relative 'src_shared' # scr_shared.rb + include SiSU_Source + require_relative 'sysenv' # sysenv.rb + include SiSU_Env + class Source < SiSU_Source::SiSUpodSource + require_relative 'response' # response.rb + def initialize(opt,build=nil,place=nil) + super(opt,build,place) + @zipfile=@opt.fno.gsub(/(?:\~\S{2,3})?(\.ss[tm])$/,'\1') + unless @opt.act[:quiet][:set]==:on + pthinfo="#{@file.output_path.sisupod.dir}/#{@zipfile}.txz" + (@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],'Assemble source for sisu document',"#{@opt.fns} -> file://#{pthinfo}").cyan_hi_blue + : SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'Assemble source for sisu document',pthinfo).cyan_title_hi + end + end + def sisupod_tar_xz + begin + FileUtils::mkdir_p(@file.output_path.sisupod.dir) unless FileTest.directory?(@file.output_path.sisupod.dir) + tree=((@opt.act[:verbose][:set]==:on \ + || @opt.act[:verbose_plus][:set]==:on \ + || @opt.act[:maintenance][:set]==:on) \ + && SiSU_Env::SystemCall.new.program_found?('tree')) \ + ? 'tree sisupod' + : '' + if FileTest.directory?(@path_pod[:fnb]) + Dir.chdir(@path_pod[:fnb]) + system(%{ + #{tree} + tar -cJf #{@zipfile}.txz sisupod + #echo "#{@file.place_file.sisupod.dir}" + }) + FileUtils::mv("#{@zipfile}.txz",@file.place_file.sisupod.dir) + Dir.chdir(@env.path.pwd) + if (@opt.act[:verbose][:set]==:on \ + || @opt.act[:verbose_plus][:set]==:on \ + || @opt.act[:maintenance][:set]==:on) + SiSU_Screen::Ansi.new('',"#{@opt.fns}.txz").blue_tab + end + else + if (@opt.act[:verbose][:set]==:on \ + || @opt.act[:verbose_plus][:set]==:on \ + || @opt.act[:maintenance][:set]==:on) + SiSU_Screen::Ansi.new('',"#{@opt.fns}.txz not built").blue_tab + end + end + rescue + ensure + end + end + end +end +__END__ +question?: should you permit the packing of multiple documents in single .xz ? + + open @opt.fns, parse file + extract from file content: + images and copy each image from whatever image source to _sisu/sisupod/sisu/_sisu/image + + remove previously existing contents of _/sisu/sisupod & + make directory structure: + +v3 --> + _sisu + sisupod + doc + manifest.txt + en/content.sst [file content] + fr/content.sst + _sisu + conf + image (ln -s ../../image) + audio (ln -s ../../audio) + video (ln -s ../../video) + image [all images for specific document gathered here] + audio + video + +v2 --> + _sisu + sisupod + content.sst [file content] + filename.sst [link to content.sst] + _sisu/ + image/ [all images for specific document gathered here] + +sisu + _sisu + sisurc.yml + convert/ + standard_terms/ + image + processing + ao/ + tex/ + texinfo/ + tune/ + sisupod + +special case + +composite file (master), e.g. +SiSU.ssm diff --git a/lib/sisu/v5/sst_to_s_xml_sax.rb b/lib/sisu/v5/sst_to_s_xml_sax.rb index 09fecc9e..5f18496a 100644 --- a/lib/sisu/v5/sst_to_s_xml_sax.rb +++ b/lib/sisu/v5/sst_to_s_xml_sax.rb @@ -69,7 +69,7 @@ module SiSU_SimpleXML_ModelSax require_relative 'sysenv' # sysenv.rb include SiSU_Env require_relative 'ao_doc_str' # ao_doc_str.rb - require_relative 'shared_xml' # shared_xml.rb + require_relative 'xml_shared' # xml_shared.rb include SiSU_XML_Munge require_relative 'shared_sem' # shared_sem.rb require_relative 'xml_format' # xml_format.rb @@ -138,7 +138,7 @@ module SiSU_SimpleXML_ModelSax end end class Scroll - require_relative 'shared_txt' # shared_txt.rb + require_relative 'txt_shared' # txt_shared.rb require_relative 'css' # css.rb include SiSU_TextUtils @@xml={ body: [], open: [], close: [], head: [] } diff --git a/lib/sisu/v5/txt_plain.rb b/lib/sisu/v5/txt_plain.rb new file mode 100644 index 00000000..e6a8f46f --- /dev/null +++ b/lib/sisu/v5/txt_plain.rb @@ -0,0 +1,576 @@ +# 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: plaintext text generation, stripped plaintext output (unix, + linefeed) + +=end +module SiSU_Plaintext + require_relative 'ao' # ao.rb + require_relative 'sysenv' # sysenv.rb + include SiSU_Env + require_relative 'txt_plaint_format' # plaintext_format.rb + include SiSU_Plaintext_Format + require_relative 'shared_metadata' # shared_metadata.rb + require_relative 'txt_shared' # txt_shared.rb + include SiSU_Param + include SiSU_Viz + @@alt_id_count,@@alt_id_count,@@tablehead,@@number_of_cols=0,0,0,0 + @@tablefoot='' + class Source + def initialize(opt) + @opt=opt + unless @opt.fns =~/(.+?)\.(?:-|ssm\.)?sst$/ + puts "#{sf} not a processed file type" + end + end + def read + begin + md=SiSU_Param::Parameters.new(@opt).get + env=SiSU_Env::InfoEnv.new(@opt.fns) + 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.text_editor} #{md.file.output_path.txt.dir}/#{md.file.base_filename.txt}" + : "[#{@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],'Plaintext',tool).green_hi_blue + : SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'Plaintext',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,"#{md.file.output_path.txt.dir}/#{md.file.base_filename.txt}").flow + end + end + ao_array=SiSU_AO::Source.new(@opt).get # ao file drawn here + wrap_width=if defined? md.make.plaintext_wrap \ + and md.make.plaintext_wrap + md.make.plaintext_wrap + elsif defined? env.plaintext_wrap \ + and env.plaintext_wrap + env.plaintext_wrap + else 78 + end + #wrap_width=(defined? md.make.plaintext_wrap) ? md.make.plaintext_wrap : 78 + SiSU_Txt_Plain::Source::Scroll.new(md,ao_array,wrap_width).songsheet + rescue + SiSU_Errors::Rescued.new($!,$@,@opt.cmd,@opt.fns).location do + __LINE__.to_s + ':' + __FILE__ + end + ensure + end + end + private + class Scroll appropriately within plaintext, consider + n=n.dup.to_s + if n =~/#{Mx[:br_line]}|#{Mx[:br_nl]}/ + fix = n.split(/#{Mx[:br_line]}|#{Mx[:br_nl]}/) #watch #added + fix.each do |x| + unless x.empty?; @n << x + end + end + else @n << n + end + end + notes=@n.flatten + notes.each do |e| + util=(e.to_s =~/^\[[\d*+]+\]:/) \ + ? (SiSU_TextUtils::Wrap.new(e.to_s,@wrap_width,4,1)) + : (SiSU_TextUtils::Wrap.new(e.to_s,@wrap_width,1,1)) + wrap=util.line_wrap + wrap=if wrap =~ /^\s*[\d*+]+\s+.+?\s*\Z/m + wrap.gsub(/^(\s*)([\d*+]+)\s+(.+?)\s*\Z/m, <<-GSUB +\\1[\\2]: \\3 + GSUB + ) + else + wrap.gsub(/^(.+)\Z/m, <<-GSUB +\\1 + GSUB + ) + end + @@endnotes[:para] << "-#{wrap}" + @@endnotes[:end] << '' << wrap + end + @@endnotes + end + def plaintext_metadata + array=SiSU_Metadata::Summary.new(@md).plaintext.metadata + array.each do |meta| + tag,inf=meta.scan(/^.+?:\s|.+/) + if tag and inf + util=SiSU_TextUtils::Wrap.new(inf,@wrap_width,15,1) + txt=util.line_wrap + @plaintext[:metadata] <<< @wrap_width + @plaintext[:body] << case lv + when 1; wrapped.upcase << break_line << decorate.heading_underscore.l1*times + p_num << break_line*2 + when 2; wrapped.upcase << break_line << decorate.heading_underscore.l2*times + p_num << break_line*2 + when 3; wrapped.upcase << break_line << decorate.heading_underscore.l3*times + p_num << break_line*2 + when 4; wrapped.upcase << break_line << decorate.heading_underscore.l4*times + p_num << break_line*2 + when 5; wrapped.upcase << break_line << decorate.heading_underscore.l5*times + p_num << break_line*2 + when 6; wrapped.upcase << break_line << decorate.heading_underscore.l6*times + p_num << break_line*2 + end + else + @plaintext[:body] << wrapped + p_num << break_line # main text, contents, body KEEP + end + if @@endnotes[:para] \ + and not @@endnotes_ + @@endnotes[:para].each {|e| @plaintext[:body] << e << break_line} + elsif @@endnotes[:para] \ + and @@endnotes_ + end + @@endnotes[:para]=[] + end + def markup(data) # Used for major markup instructions + SiSU_Env::InfoEnv.new(@md.fns) + @data_mod,@endnotes,@level,@cont,@copen,@plaintext_contents_close=Array.new(6){[]} + (0..6).each { |x| @cont[x]=@level[x]=false } + (4..6).each { |x| @plaintext_contents_close[x]='' } + plaintext_tail #($1,$2) + plaintext_metadata + table_message='[table omitted, see other document formats]' + data.each do |dob| + dob.obj=dob.obj.gsub(/#{Mx[:gr_o]}Th?#{Mx[:tc_p]}.+/um,"#{break_line}#{table_message}"). #fix + gsub(/.+?#{Mx[:gl_o]}-##{Mx[:gl_c]}/,''). # remove dummy headings (used by html) #check also [~-]# + gsub(/#{Mx[:fa_bold_o]}(.+?)#{Mx[:fa_bold_c]}/, + "#{decorate.bold.open}\\1#{decorate.bold.close}"). + gsub(/#{Mx[:fa_italics_o]}(.+?)#{Mx[:fa_italics_c]}/, + "#{decorate.italics.open}\\1#{decorate.italics.close}"). + gsub(/#{Mx[:fa_underscore_o]}(.+?)#{Mx[:fa_underscore_c]}/, + "#{decorate.underscore.open}\\1#{decorate.underscore.close}"). + gsub(/#{Mx[:fa_subscript_o]}(.+?)#{Mx[:fa_subscript_c]}/, + "#{decorate.subscript.open}\\1#{decorate.subscript.close}"). + gsub(/#{Mx[:fa_superscript_o]}(.+?)#{Mx[:fa_superscript_c]}/, + "#{decorate.superscript.open}\\1#{decorate.superscript.close}"). + gsub(/#{Mx[:fa_insert_o]}(.+?)#{Mx[:fa_insert_c]}/, + "#{decorate.insert.open}\\1#{decorate.insert.close}"). + gsub(/#{Mx[:fa_cite_o]}(.+?)#{Mx[:fa_cite_c]}/, + "#{decorate.cite.open}\\1#{decorate.cite.close}"). + gsub(/#{Mx[:fa_strike_o]}(.+?)#{Mx[:fa_strike_c]}/, + "#{decorate.strike.open}\\1#{decorate.strike.close}"). + gsub(/#{Mx[:fa_monospace_o]}(.+?)#{Mx[:fa_monospace_c]}/, + "#{decorate.monospace.open}\\1#{decorate.monospace.close}") + unless dob.is==:code + dob.obj=dob.obj.gsub(/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}/,'\1'). + gsub(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/,'\1'). + gsub(/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,'\1 [link: <\2>]'). + gsub(/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}image/,'\1 [link: local image]'). + gsub(/#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,"#{@brace_url.txt_open}\\1#{@brace_url.txt_close}") + extract_endnotes(dob) + dob.obj=dob.obj.gsub(/#{Mx[:en_a_o]}([\d*+]+)\s+(?:.+?)#{Mx[:en_a_c]}/,'[^\1]'). # endnote marker marked up + gsub(/#{Mx[:en_b_o]}([\d*+]+)\s+(?:.+?)#{Mx[:en_b_c]}/,'[^\1]'). # endnote marker marked up + gsub(/#{Mx[:gl_o]}(?:#lt|#060)#{Mx[:gl_c]}/,'<'). + gsub(/#{Mx[:gl_o]}(?:#gt|#062)#{Mx[:gl_c]}/,'>'). + gsub(/#{Mx[:gl_o]}#(?:038|amp)#{Mx[:gl_c]}/,'&'). + gsub(/#{Mx[:gl_o]}#033#{Mx[:gl_c]}/,'!'). + gsub(/#{Mx[:gl_o]}#035#{Mx[:gl_c]}/,'#'). + gsub(/#{Mx[:gl_o]}#042#{Mx[:gl_c]}/,'*'). + gsub(/#{Mx[:gl_o]}#045#{Mx[:gl_c]}/,'-'). + gsub(/#{Mx[:gl_o]}#047#{Mx[:gl_c]}/,'/'). + gsub(/#{Mx[:gl_o]}#095#{Mx[:gl_c]}/,'_'). + gsub(/#{Mx[:gl_o]}#123#{Mx[:gl_c]}/,'{'). + gsub(/#{Mx[:gl_o]}#125#{Mx[:gl_c]}/,'}'). + gsub(/#{Mx[:gl_o]}#126#{Mx[:gl_c]}/,'~'). + gsub(/#{Mx[:gl_o]}#169#{Mx[:gl_c]}/,'©'). + gsub(/#{Mx[:gl_o]}#092#{Mx[:gl_c]}/,'\\') + end + dob.obj=if dob.of==:block # watch + dob.obj.gsub(/#{Mx[:gl_o]}●#{Mx[:gl_c]}/m,"* "). + gsub(/\n?#{Mx[:br_line]}\n?|\n?#{Mx[:br_nl]}\n?/m,break_line) + else dob.obj.gsub(/\n?#{Mx[:br_line]}\n?|\n?#{Mx[:br_nl]}\n?/m,break_line*2) + end + if dob.is==:code + dob.obj=dob.obj.gsub(/(^|[^}])_([<>])/m,'\1\2'). # _> _< + gsub(/(^|[^}])_([<>])/m,'\1\2') # _<_< + end + dob.obj=dob.obj.gsub(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/,'\1'). + gsub(/(.+?)<\/a>/m,'\1'). + gsub(/#{Mx[:mk_o]}:name#(\S+?)#{Mx[:mk_c]}/,''). # remove name links + gsub(/ |#{Mx[:nbsp]}/,' '). # decide on + gsub(/(?:^|[^_\\])#{Mx[:lnk_o]}(\S+?\.(?:png|jpg|gif)) .+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/,' [ \1 ]'). #"[ #{dir.url.images_local}\/\\1 ]") + gsub(/(?:^|[^_\\])#{Mx[:lnk_o]}(\S+?\.(?:png|jpg|gif)) .+?#{Mx[:lnk_c]}image/,' [ \1 ]'). + gsub(/(?:^|[^_\\])\{\s*\S+?\.(?:png|jpg|gif)\s+.+?"(.*?)"\s*\}\S+/,'[image: "\1"]') + if dob.obj !~/(^#{Rx[:meta]}|#{Mx[:br_eof]}|#{Mx[:br_endnotes]})/ + p_num='' + if @env.plaintext_ocn? + if defined? dob.ocn \ + and dob.ocn.is_a?(Fixnum) + p_num=SiSU_Plaintext_Format::ParagraphNumber.new(dob.ocn).display + end + end + if dob.is==:heading \ + or dob.is==:para + plaintext_structure(dob,p_num) + elsif dob.is==:group \ + or dob.is==:block \ + or dob.is==:verse \ + or dob.is==:code \ + or dob.is==:table + @plaintext[:body] << dob.obj + p_num << break_line + elsif dob.is==:break + sp=' ' + ln='-' + @plaintext[:body] <<=if dob.obj==Mx[:br_page] \ + or dob.obj==Mx[:br_page_new] \ + or dob.obj==Mx[:br_page_line] + "#{break_line}#{ln*40}#{break_line*2}" + elsif dob.obj ==Mx[:br_obj] + "#{break_line}#{sp*20}* * *#{break_line*2}" + end # following empty line (break_line) missing, fix + end + dob='' if (dob.obj =~// \ + and dob.obj =~/^(-\{{2}~\d+|)/) # -endnote + if dob ## Clean Prepared Text + dob.obj=dob.obj.gsub(//,' '). + gsub(/<:\S+>/,' ') + end + end + end + @plaintext + end + def publish(plaintext) + divider='=' + content=[] + content << plaintext[:open] + content << plaintext[:head] + content << plaintext[:body] + content << @@endnotes[:end] if @@endnotes_ + content << "#{break_line}#{divider*@wrap_width}#{break_line}" + content << plaintext[:metadata] + content << "#{break_line}#{divider*@wrap_width}#{break_line}" if @md.stmp =~/\w+/ #not used? + content << plaintext[:tail] + Output.new(content,@md).plaintext + @@endnotes={ para: [], end: [] } + end + end + class Output 0 + para.each do |line| + if line + line=line.gsub(/[ \t]+$/m,''). + gsub(/^\A[ ]*\Z/m,'') + (line=~/^\A\Z/) \ + ? (emptyline+=1) + : emptyline=0 + if emptyline < 2 #remove additional empty lines + file_plaintext.puts line + end + end + end + else file_plaintext.puts para #unix plaintext # /^([*=-]|\.){5}/ + end + end + file_plaintext.close + end + end + end +end +__END__ + bold_o: '*', bold_c: '*', + #bold_o: '!', bold_c: '!', + #emphasis_o: '*', emphasis_c: '*', + italics_o: '/', italics_c: '/', + underscore_o: '_', underscore_c: '_', + cite_o: '"', cite_c: '"', + insert_o: '+', insert_c: '+', + strike_o: '-', strike_c: '-', + superscript_o: '^', superscript_c: '^', + subscript_o: '[', subscript_c: ']', + hilite_o: '*', hilite_c: '*', + monospace_o: '', monospace_c: '', + po_bold_o: '!{', po_bold_c: '}!', + po_italics_o: '/{', po_italics_c: '}/', + po_underscore_o: '_{', po_underscore_c: '}_', + po_cite_o: '"{', po_cite_c: '}"', + po_insert_o: '+{', po_insert_c: '}+', + po_strike_o: '-{', po_strike_c: '}-', + po_superscript_o: '^{', po_superscript_c: '}^', + po_subscript_o: ',{', po_subscript_c: '},', + po_hilite_o: '*{', po_hilite_c: '}*', + po_monospace_o: '#{', po_monospace_c: '}#', diff --git a/lib/sisu/v5/txt_shared.rb b/lib/sisu/v5/txt_shared.rb new file mode 100644 index 00000000..31a976d2 --- /dev/null +++ b/lib/sisu/v5/txt_shared.rb @@ -0,0 +1,242 @@ +# 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: modules shared by flatfile output generators + +=end +module SiSU_TextUtils + class Wrap + def initialize(para='',n_char_max=76,n_indent=0,n_hang=nil) + @para,@n_char_max,@n_indent=para,n_char_max,n_indent + @n_char_max_extend = n_char_max + @n_hang=n_hang ? n_hang : @n_indent + end + def break_line + "\n" + end + def line_wrap + space=' ' + spaces_indent,spaces_hang="#{break_line}#{space*@n_indent}",space*@n_hang + line=0 + out=[] + out[line]='' + @para=@para.gsub(/
    /,' \\ '). + gsub(/#{Mx[:br_nl]}/,"\n\n") + words=@para.scan(/\n\n|\s+\\\s+|
    |\S+/m) + while words != '' + word=words.shift + if not word + out[line] unless out[line].empty? #check + break + elsif word =~/
    / + word=nil + out[line]=out[line].gsub(/
    /,'') + line=line + elsif word =~/\n\n/ + word="\n" + @n_char_max_extend = @n_char_max + line += 1 + elsif (out[line].length + word.length) > (@n_char_max_extend - @n_indent) \ + and out[line] =~/\S+/ + @n_char_max_extend = @n_char_max + out[line].squeeze!(' ') + line += 1 + end + if word + out[line]=if out[line] \ + and out[line] !~/\S+$/m + "#{out[line]}#{word}" + elsif out[line] \ + and out[line] =~/\S+/ + "#{out[line]} #{word}" + else "#{word.strip}" + end + end + @oldword=word if word =~/\S+/ + end + spaces_hang + out.join(spaces_indent) + end + def line_wrap_indent1 + @n_indent,@n_hang=2,2 + line_wrap + end + def line_wrap_endnote + @n_indent,@n_hang=4,2 + line_wrap + end + def array_wrap + if @para.is_a?(Array) + @arr=[] + @para.each do |line| + @arr << SiSU_TextUtils::Wrap.new(line,@n_char_max,@n_indent,@n_hang).line_wrap + end + end + @arr + end + def no_wrap + @para + end + def no_wrap_no_breaks + @para.gsub(/\n/m,' ').gsub(/\s\s+/,' ') + end + end + class HeaderScan + def initialize(md,para) + @md,@p=md,para + end + def extract(tag,tag_content,type,attrib) + if dc_tag \ + and dc_content + [dc_tag,dc_content,{dc_tag=>dc_content}] + else nil + end + end + def header(tag,tag_content,type='',attrib='') #this will break stuff and must be tested thoroughly 20060825 + @tag,@tag_content,@type,@attrib=tag,tag_content,type,attrib + def label #element + @tag + end + def type + @type + end + def text + @tag_content + end + def info #element text + @tag_content + end + def attribute + @attrib + end + def element + @tag + end + def attrib + @attrib + end + def el + @tag + end + self + end + def start_is_match + case @p + when /^#{Mx[:meta_o]}(title)#{Mx[:meta_c]}\s*(.+?)$/; header($1,@md.title.full,'meta','dc') #dc 1 + when /^#{Mx[:meta_o]}(creator|author)#{Mx[:meta_c]}\s*(.+?)$/; header('creator',$2,'meta','dc') #dc 2 + when /^#{Mx[:meta_o]}(subject)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','dc') #dc 3 + when /^#{Mx[:meta_o]}(description)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','dc') #dc 4 + when /^#{Mx[:meta_o]}(publisher)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','dc') #dc 5 + when /^#{Mx[:meta_o]}(contributor)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','dc') #dc 6 + when /^#{Mx[:meta_o]}(date)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','dc') #dc 7 + when /^#{Mx[:meta_o]}(date\.created)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','extra') + when /^#{Mx[:meta_o]}(date\.issued)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','extra') + when /^#{Mx[:meta_o]}(date\.available)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','extra') + when /^#{Mx[:meta_o]}(date\.valid)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','extra') + when /^#{Mx[:meta_o]}(date\.modified)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','extra') + when /^#{Mx[:meta_o]}(type)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','dc') #dc 8 + when /^#{Mx[:meta_o]}(format)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','dc') #dc 9 + when /^#{Mx[:meta_o]}(identifier)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','dc') #dc 10 + when /^#{Mx[:meta_o]}(source)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','dc') #dc 11 + when /^#{Mx[:meta_o]}(language)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','dc') #dc 12 + when /^#{Mx[:meta_o]}(relation)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','dc') #dc 13 + when /^#{Mx[:meta_o]}(coverage)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','dc') #dc 14 + when /^#{Mx[:meta_o]}(rights)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','dc') #dc 15 + when /^#{Mx[:meta_o]}(keywords)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','extra') + when /^#{Mx[:meta_o]}(copyright)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','extra') + when /^#{Mx[:meta_o]}(translator|translated_by)#{Mx[:meta_c]}\s*(.+?)$/; header('translator',$2) + when /^#{Mx[:meta_o]}(illustrator|illustrated_by)#{Mx[:meta_c]}\s*(.+?)$/; header('illustrator',$2) + when /^#{Mx[:meta_o]}(prepared_by)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','extra') + when /^#{Mx[:meta_o]}(digitized_by)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','extra') + when /^#{Mx[:meta_o]}(comments?)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','extra') + when /^#{Mx[:meta_o]}(abstract)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','extra') + when /^#{Mx[:meta_o]}(tags?)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','extra') + when /^#{Mx[:meta_o]}(catalogue)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'meta','extra') + when /^#{Mx[:meta_o]}(class(?:ify)?_loc)#{Mx[:meta_c]}\s*(.+?)$/; header('classify_loc',$2,'meta','extra') + when /^#{Mx[:meta_o]}(class(?:ify)?_dewey)#{Mx[:meta_c]}\s*(.+?)$/; header('classify_dewey',$2,'meta','extra') + when /^#{Mx[:meta_o]}(class(?:ify)?_pg)#{Mx[:meta_c]}\s*(.+?)$/; header('classify_pg',$2,'meta','extra') + when /^#{Mx[:meta_o]}(class(?:ify)?_isbn)#{Mx[:meta_c]}\s*(.+?)$/; header('classify_isbn',$2,'meta','extra') + when /^#{Mx[:meta_o]}(toc|structure)#{Mx[:meta_c]}\s*(.+?)$/; header('structure',$2,'process','instruct') + when /^#{Mx[:meta_o]}(level|page|markup)#{Mx[:meta_c]}\s*(.+?)$/; header('markup',$2,'process','instruct') + when /^#{Mx[:meta_o]}(bold)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'process','instruct') + when /^#{Mx[:meta_o]}(italics|itali[sz]e)#{Mx[:meta_c]}\s*(.+?)$/; header('italicize',$2,'process','instruct') + when /^#{Mx[:meta_o]}(vocabulary|wordlist)#{Mx[:meta_c]}\s*(.+?)$/; header('vocabulary',$2,'process','instruct') + when /^#{Mx[:meta_o]}(css|stylesheet)#{Mx[:meta_c]}\s*(.+?)$/; header('css',$2,'process','instruct') + when /^#{Mx[:meta_o]}(links)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'process','instruct') + when /^#{Mx[:meta_o]}(prefix)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'process','instruct') #add a & b + when /^#{Mx[:meta_o]}(suffix)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'process','instruct') + when /^#{Mx[:meta_o]}(information)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'process','instruct') + when /^#{Mx[:meta_o]}(contact)#{Mx[:meta_c]}\s*(.+?)$/; header($1,$2,'process','instruct') + when /^#{Mx[:meta_o]}(rcs|cvs)#{Mx[:meta_c]}\s*(.+?)$/; header('version',$2,'process','instruct') + else nil + end + end + def dublin + if @p =~/^#{Mx[:meta_o]}\S+?#{Mx[:meta_c]}/ + start_is_match + else nil + end + end + def meta + if @p =~/^#{Mx[:meta_o]}\S+?#{Mx[:meta_c]}/ + start_is_match + else nil + end + end + end +end +__END__ diff --git a/lib/sisu/v5/wikispeak.rb b/lib/sisu/v5/wikispeak.rb index 65e87c13..b87fef61 100644 --- a/lib/sisu/v5/wikispeak.rb +++ b/lib/sisu/v5/wikispeak.rb @@ -67,7 +67,7 @@ module SiSU_Wikispeak include SiSU_Viz require_relative 'plaintext_format' # plaintext_format.rb include Format - require_relative 'shared_txt' + require_relative 'txt_shared' @@alt_id_count,@@alt_id_count,@@tablehead,@@number_of_cols=0,0,0,0 @@tablefoot='' class Source @@ -149,7 +149,7 @@ module SiSU_Wikispeak end end class Scroll . + + 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: epub generation, processing + +=end +module SiSU_XHTML_EPUB2 + require 'pstore' + require_relative 'particulars' # particulars.rb + include SiSU_Particulars + require_relative 'defaults' # defaults.rb + include SiSU_Viz + require_relative 'xhtml_table' # xhtml_table.rb + require_relative 'xhtml_epub2_format' # xhtml_epub2_format.rb + include SiSU_XHTML_EPUB2_Format + require_relative 'xhtml_epub2_segments' # xhtml_epub2_segments.rb + include SiSU_XHTML_EPUB2_Seg + require_relative 'xhtml_epub2_tune' # xhtml_epub2_tune.rb + include SiSU_XHTML_EPUB2_Tune + require_relative 'xhtml_epub2_concordance' # xhtml_epub2_concordance.rb + class Source + def initialize(opt) + @opt=opt + @particulars=SiSU_Particulars::CombinedSingleton.instance.get_all(opt) + end + def read + songsheet + end + def songsheet + begin + @md=@particulars.md + @fnb=@md.fnb + @env=@particulars.env + 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.epub_viewer} #{@md.file.output_path.epub.dir}/#{@md.file.base_filename.epub}" + : "[#{@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],'EPUB',tool).green_hi_blue + : SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'EPUB',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,"#{@md.file.output_path.epub.dir}/#{@md.file.base_filename.epub}").flow + end + end + @env.processing_path.epub_bld #(@md) + @env.processing_path.epub_cp_images(@md) + data=nil + SiSU_Env::FileOp.new(@md).mkdir.output.epub + @tuned_file_array=SiSU_XHTML_EPUB2::Source::XHTML_Environment.new(@particulars).tuned_file_instructions + data=@tuned_file_array + toc=SiSU_XHTML_EPUB2::Source::Toc.new(@md,data).songsheet + data=@tuned_file_array + SiSU_XHTML_EPUB2::Source::ScrollHeadAndSegToc.new(@md,toc).in_common #watch + SiSU_XHTML_EPUB2::Source::Seg.new(@md,data).songsheet + SiSU_XHTML_EPUB2::Source::Output.new(@md).songsheet + rescue + SiSU_Errors::Rescued.new($!,$@,@opt.cmd,@opt.fns).location do + __LINE__.to_s + ':' + __FILE__ + end + ensure + unless (@opt.act[:verbose_plus][:set]==:on \ + || @opt.act[:maintenance][:set]==:on) + texfiles=Dir["#{@env.processing_path.tune}/#{@opt.fns}*"] + texfiles.each do |f| + if FileTest.file?(f) + File.unlink(f) + end + end + end + SiSU_Env::Clear.new(@opt.cmd,@opt.fns).param_instantiate + @@flag,@@scr,@@seg,@@seg_endnotes,@@seg_subtoc,@@seg_ad={},{},{},{},{},{} + @@seg_total,@@tracker,@@loop_count,@@tablehead,@@number_of_cols=0,0,0,0,0 + @@seg_name,@@seg_name_html,@@seg_subtoc_array,@@seg_endnotes_array,@@segtocband,@@tablefoot=Array.new(7){[]} + @@filename_seg,@@seg_url,@@fn,@@to_lev4,@@get_hash_to,@@get_hash_fn='','','','','','','' + @@is4=@@is3=@@is2=@@is1=@@heading1=@@heading2=@@heading3=@@heading4=0 + end + end + private + class XHTML_Environment + def initialize(particulars) + @particulars=particulars + @md,@env=particulars.md,particulars.env + @vz=SiSU_Viz::Defaults.new + @env,@css=particulars.env,SiSU_Style::CSS.new + end + def directories + SiSU_Env::FileOp.new(@md).mkdir.output.epub + end + def tuned_file_instructions + @tell=SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set]) + directories + ao_array=@particulars.ao_array # ao file drawn here + @tuned_file_array=SiSU_XHTML_EPUB2_Tune::Tune.new(ao_array,@md).songsheet + @tuned_file_array + end + end + class Endnotes + include SiSU_XHTML_EPUB2_Format + def initialize(md,data) + @md,@data=md,data + end + def scroll + @scr_endnotes=[] + @data.each do |dob| + pg=dob.dup + unless pg.is ==:code + if pg.obj =~/(?:#{Mx[:en_a_o]}|#{Mx[:en_b_o]})[\d*+]+ / + endnote_array=[] + if pg.obj=~/#{Mx[:en_a_o]}[\d*+].+?#{Mx[:en_a_c]}/m + endnote_array = pg.obj.scan(/#{Mx[:en_a_o]}[\d*+]+(.+?)#{Mx[:en_a_c]}/m) + end + if pg.obj=~/#{Mx[:en_b_o]}[\d*]+\s.+?#{Mx[:en_b_c]}/m + endnote_array = pg.obj.scan(/#{Mx[:en_b_o]}[\d*]+(.+?)#{Mx[:en_b_c]}/m) + end + if pg.obj=~/#{Mx[:en_b_o]}[\d+]+\s.+?#{Mx[:en_b_c]}/m + endnote_array = pg.obj.scan(/#{Mx[:en_b_o]}[\d+]+(.+?)#{Mx[:en_b_c]}/m) + end + endnote_array.flatten.each do |note| + txt_obj={ txt: note } + format_scroll=SiSU_XHTML_EPUB2_Format::FormatScroll.new(@md,txt_obj) + @scr_endnotes << format_scroll.endnote_body + end + end + end + end + @scr_endnotes + end + end + class Toc + @@toc={ seg: [], seg_mini: [], scr: [], ncx: [], opf: [] } + @@seg_url='' + @@firstseg=nil + def initialize(md=nil,data='') + @md,@data=md,data + @vz=SiSU_Viz::Defaults.new + @epub=SiSU_XHTML_EPUB2_Format::HeadInformation.new(@md) + @tell=SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set]) if @md + @make=SiSU_Env::ProcessingSettings.new(@md) + end + def songsheet #extracts toc for scroll & seg + if (@md.opt.act[:verbose][:set]==:on \ + || @md.opt.act[:verbose_plus][:set]==:on \ + || @md.opt.act[:maintenance][:set]==:on) + SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set],'Toc').txt_grey + end + toc=nil + @@firstseg=nil + @@toc={ seg: [], seg_mini: [], scr: [], ncx: [], opf: [] } + md_opf_a_content,md_opf_a_spine,md_opf_a_guide=[],[],[] + @nav_no=0 + @s_a_no,@s_b_no,@s_c_no,@lv5_no,@lv6_no=0,0,0,0,0 + @@toc[:ncx] << @epub.toc_ncx.open #epub ncx navmap + @@toc[:ncx] << @epub.toc_ncx.head_open << @epub.toc_ncx.head << @epub.toc_ncx.head_close + @@toc[:ncx] << @epub.toc_ncx.doc_title << @epub.toc_ncx.doc_author + @@toc[:ncx] << @epub.toc_ncx.navmap_open + @@toc[:opf] << @epub.metadata_opf.package_open + @@toc[:opf] << @epub.metadata_opf.metadata + @@toc[:opf] << @epub.metadata_opf.manifest_open + @@toc[:seg] << %{
    \n
    } + @@toc[:scr] << %{
    \n
    } + if defined? @md.make.cover_image \ + and @md.make.cover_image.is_a?(Hash) \ + and @md.make.cover_image[:cover] =~/\S+/ + md_opf_a_content << @epub.metadata_opf.manifest_cover_image_information(@md) + md_opf_a_spine << @epub.metadata_opf.spine_cover_image + md_opf_a_guide << @epub.metadata_opf.guide_cover_image + end + md_opf_a_content << @epub.metadata_opf.manifest_content_sisu_toc + if @make.build.toc? + md_opf_a_spine << @epub.metadata_opf.spine_sisu_toc + md_opf_a_guide << @epub.metadata_opf.guide_sisu_toc + end + @ncxo=[nil,false,false,false,false,false,false] + @dob_toc2,@dob_toc3=nil,nil + @ncx_cls=[] + @level_a_first_occurrence=true + @data.each do |dob| + if dob.is==:heading \ + || dob.is==:heading_insert + dob_toc=dob.dup + toc=case dob_toc.ln + when 1 + @s_a_no +=1 + lv_name='section_a' + @s_a_no.to_s + @nav_no+=1 + @nav_no2=@nav_no + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[6] + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[5] + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[4] + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[3] + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[2] + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[1] + @ncxo[1],@ncxo[2],@ncxo[3],@ncxo[4],@ncxo[5],@ncxo[6]=true,false,false,false,false,false + @epub.sections(dob_toc,lv_name) + @@toc[:ncx] << @epub.toc_ncx.navpoint(dob_toc,@nav_no,lv_name) if dob_toc + if @level_a_first_occurrence \ + && @make.build.toc? + @nav_no+=1 + @@toc[:ncx] << @epub.toc_ncx.navmap_sisu_toc(@nav_no) #epub ncx navmap, toc + @level_a_first_occurrence=false + end + md_opf_a_content << @epub.metadata_opf.manifest_content(dob_toc,lv_name) + md_opf_a_spine << @epub.metadata_opf.spine(dob_toc,lv_name) + md_opf_a_guide << @epub.metadata_opf.guide(dob_toc,lv_name) + SiSU_XHTML_EPUB2::Source::Toc.new(@md,dob_toc).level_1 + when 2 + @s_b_no +=1 + lv_name='section_b' + @s_b_no.to_s + @nav_no+=1 + @nav_no2=@nav_no + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[6] + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[5] + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[4] + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[3] + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[2] + @ncxo[2],@ncxo[3],@ncxo[4],@ncxo[5],@ncxo[6]=true,false,false,false,false + @epub.sections(dob_toc,lv_name) + @@toc[:ncx] << @epub.toc_ncx.navpoint(dob_toc,@nav_no,lv_name) if dob_toc + md_opf_a_content << @epub.metadata_opf.manifest_content(dob_toc,lv_name) + md_opf_a_spine << @epub.metadata_opf.spine(dob_toc,lv_name) + md_opf_a_guide << @epub.metadata_opf.guide(dob_toc,lv_name) + SiSU_XHTML_EPUB2::Source::Toc.new(@md,dob_toc).level_2 + when 3 + @s_c_no +=1 + lv_name='section_c' + @s_c_no.to_s + @nav_no+=1 + @nav_no3=@nav_no + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[6] + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[5] + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[4] + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[3] + @ncxo[3],@ncxo[4],@ncxo[5],@ncxo[6]=true,false,false,false + @epub.sections(dob_toc,lv_name) + @@toc[:ncx] << @epub.toc_ncx.navpoint(dob_toc,@nav_no,lv_name) if dob_toc + md_opf_a_content << @epub.metadata_opf.manifest_content(dob_toc,lv_name) + md_opf_a_spine << @epub.metadata_opf.spine(dob_toc,lv_name) + md_opf_a_guide << @epub.metadata_opf.guide(dob_toc,lv_name) + SiSU_XHTML_EPUB2::Source::Toc.new(@md,dob_toc).level_3 + when 4 + @ncx_cls=[] + lv_name=dob_toc.name + @nav_no+=1 + @dob_name=dob.name + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[6] + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[5] + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[4] + @ncxo[4],@ncxo[5],@ncxo[6]=true,false,false + @@toc[:ncx] << @epub.toc_ncx.navpoint(dob_toc,@nav_no,lv_name) if dob_toc + md_opf_a_content << @epub.metadata_opf.manifest_content(dob_toc,lv_name) + md_opf_a_spine << @epub.metadata_opf.spine(dob_toc,lv_name) + md_opf_a_guide << @epub.metadata_opf.guide(dob_toc,lv_name) + SiSU_XHTML_EPUB2::Source::Toc.new(@md,dob_toc).level_4 + when 5 + @ncx_cls=[] + hashtag='#o' + dob_toc.ocn.to_s + lv_name=@dob_name + @nav_no+=1 + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[6] + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[5] + @ncxo[5],@ncxo[6]=true,false + @@toc[:ncx] << @epub.toc_ncx.navpoint(dob_toc,@nav_no,lv_name,hashtag) if dob_toc + md_opf_a_content << @epub.metadata_opf.manifest_content(dob_toc,lv_name,hashtag) + md_opf_a_spine << @epub.metadata_opf.spine(dob_toc,lv_name,hashtag) + md_opf_a_guide << @epub.metadata_opf.guide(dob_toc,lv_name,hashtag) + SiSU_XHTML_EPUB2::Source::Toc.new(@md,dob_toc).level_5 + when 6 + @ncx_cls=[] + hashtag='#o' + dob_toc.ocn.to_s + lv_name=@dob_name + @nav_no+=1 + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[6] + @ncxo[6]=true + @@toc[:ncx] << @epub.toc_ncx.navpoint(dob_toc,@nav_no,lv_name,hashtag) if dob_toc + md_opf_a_content << @epub.metadata_opf.manifest_content(dob_toc,lv_name,hashtag) + md_opf_a_spine << @epub.metadata_opf.spine(dob_toc,lv_name,hashtag) + md_opf_a_guide << @epub.metadata_opf.guide(dob_toc,lv_name,hashtag) + SiSU_XHTML_EPUB2::Source::Toc.new(@md,dob_toc).level_6 + else nil + end + toc.each do |k,d| + d.gsub!(/(?:#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]})\s*/m,' ') + end if toc + if @@firstseg.nil? \ + and dob.ln==4 \ + and dob.name =~/\S+/ + @@firstseg=dob.name + end + if toc + begin + @@toc[:seg] << toc[:seg] + @@toc[:scr] << toc[:seg] + rescue + SiSU_Errors::Rescued.new($!,$@,@md.opt.cmd,@md.fns).location do + __LINE__.to_s + ':' + __FILE__ + end + end + end + end + end + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[6] + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[5] + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[4] + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[3] + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[2] + @@toc[:ncx] << @epub.toc_ncx.navpoint_close if @ncxo[1] + @ncxo[1],@ncxo[2],@ncxo[3],@ncxo[4],@ncxo[5],@ncxo[6]=false,false,false,false,false,false + md_opf_a_content << @epub.metadata_opf.manifest_images(@md.ec[:image]) + @@toc[:seg] << "
    \n
    " + @@toc[:scr] << "
    \n
    " + @@toc[:ncx] << @epub.toc_ncx.navmap_close + @@toc[:ncx] << @epub.toc_ncx.close + @@toc[:opf] << md_opf_a_content << @epub.metadata_opf.manifest_close + @@toc[:opf] << @epub.metadata_opf.spine_open << md_opf_a_spine << @epub.metadata_opf.spine_close + @@toc[:opf] << @epub.metadata_opf.guide_open << md_opf_a_guide << @epub.metadata_opf.guide_close + @@toc[:opf] << @epub.metadata_opf.package_close + @@toc[:opf]=@@toc[:opf].flatten + SiSU_XHTML_EPUB2::Source::Output.new(@md,@@toc[:opf]).epub_metadata_opf + SiSU_XHTML_EPUB2::Source::Output.new(@md,@@toc[:ncx]).epub_toc_ncx + @md.firstseg=@@firstseg + @@toc + end + protected + def level_1 + dob=@data + linkname,link=dob.obj.strip,dob.ocn + title=if dob.obj !~/Document Information/ + linkname + else + link='metadata' + %{
    #{linkname}} + end + toc={} + txt_obj={ txt: title } + format_toc=SiSU_XHTML_EPUB2_Format::FormatToc.new(@md,txt_obj) + toc[:seg]=if dob.name =~/^meta/ \ + and dob.obj =~/Document Information/ #check + format_toc.lev0 + else format_toc.lev1 + end + title=if dob.ocn ==0 + if dob.name =~/^meta/ \ + and dob.obj =~/Document Information/ + %{#{linkname}} + else linkname + end + else + @@toc[:scr] << '
    ' + link=(dob.ln) \ + ? dob.ln + : '' + %{#{linkname}} + end + txt_obj={ txt: title } + format_toc=SiSU_XHTML_EPUB2_Format::FormatToc.new(@md,txt_obj) + toc[:scr]=if dob.name =~/^meta/ \ + and dob.obj =~/Document Information/ + format_toc.lev0 + else format_toc.lev1 + end + toc + end + def level_2 + dob=@data + linkname,ocn=dob.obj.strip,dob.ocn + if ocn \ + and ocn !~/#/ + p_num=SiSU_XHTML_EPUB2_Format::ParagraphNumber.new(@md,ocn) + end + txt_obj={ txt: linkname } + format_toc=SiSU_XHTML_EPUB2_Format::FormatToc.new(@md,txt_obj) + toc={} + toc[:seg]=format_toc.lev2 + if p_num + title=%{#{p_num.goto}#{linkname}} + txt_obj={ txt: title } + format_toc=SiSU_XHTML_EPUB2_Format::FormatToc.new(@md,txt_obj) + toc[:scr]=format_toc.lev2 + end + toc + end + def level_3 + dob=@data + linkname,ocn=dob.obj.strip,dob.ocn + if ocn \ + and ocn !~/#/ + p_num=SiSU_XHTML_EPUB2_Format::ParagraphNumber.new(@md,ocn) + end + txt_obj={ txt: linkname } + format_toc=SiSU_XHTML_EPUB2_Format::FormatToc.new(@md,txt_obj) + toc={} + toc[:seg]=format_toc.lev3 + if p_num + title=%{#{p_num.goto}#{linkname}} + txt_obj={ txt: title } + format_toc=SiSU_XHTML_EPUB2_Format::FormatToc.new(@md,txt_obj) + toc[:scr]=format_toc.lev3 + end + toc + end + def level_4 + dob=@data + linkname,ocn=dob.obj.strip,dob.ocn + p_num=SiSU_XHTML_EPUB2_Format::ParagraphNumber.new(@md,ocn) if ocn + if dob.ln==4 + seg_link=%{ + #{dob.obj} + } + @@seg_url=dob.name + elsif dob.obj =~/\d+.\d+.\d+.\d+|\d+.\d+.\d+|\d+.\d+|\d+/ + seg_link=dob.obj.gsub(/^(\d+.\d+.\d+.\d+|\d+.\d+.\d+|\d+.\d+|\d+)(.*)/, + %{} + + %{\\1 \\2 }) + end + p_num=SiSU_XHTML_EPUB2_Format::ParagraphNumber.new(@md,ocn) if ocn + txt_obj={ txt: seg_link } + format_toc=SiSU_XHTML_EPUB2_Format::FormatToc.new(@md,txt_obj) + toc={} + toc[:seg]=format_toc.lev4 + title=%{#{p_num.goto}#{linkname}} if p_num + txt_obj={ txt: title } + format_toc=SiSU_XHTML_EPUB2_Format::FormatToc.new(@md,txt_obj) + toc[:scr]=format_toc.lev4 + toc + end + def level_5 + dob=@data + linkname,ocn=dob.obj.strip,dob.ocn + toc={} + if ocn \ + and ocn !~/#/ + p_num=SiSU_XHTML_EPUB2_Format::ParagraphNumber.new(@md,ocn) + lnk_n_txt=%{ + #{linkname} + } + txt_obj={ txt: lnk_n_txt } + format_toc=SiSU_XHTML_EPUB2_Format::FormatToc.new(@md,txt_obj) + toc[:seg]=format_toc.lev5 + title=%{#{p_num.goto}#{linkname}} + txt_obj={ txt: title } + format_toc=SiSU_XHTML_EPUB2_Format::FormatToc.new(@md,txt_obj) + toc[:scr]=format_toc.lev5 + end + toc + end + def level_6 + dob=@data + linkname,ocn=dob.obj.strip,dob.ocn + toc={} + if ocn \ + and ocn !~/#/ + p_num=SiSU_XHTML_EPUB2_Format::ParagraphNumber.new(@md,ocn) + lnk_n_txt=%{ + #{linkname} +} + txt_obj={ txt: lnk_n_txt } + format_toc=SiSU_XHTML_EPUB2_Format::FormatToc.new(@md,txt_obj) + toc[:seg]=format_toc.lev6 + title=%{#{p_num.goto}#{linkname}} + txt_obj={ txt: title } + format_toc=SiSU_XHTML_EPUB2_Format::FormatToc.new(@md,txt_obj) + toc[:scr]=format_toc.lev6 + end + toc + end + end + class ScrollHeadAndSegToc < Toc + def initialize(md='',toc='',links_guide_toc='') + @md,@toc,@links_guide_toc=md,toc,links_guide_toc + @vz=SiSU_Viz::Defaults.new + end + def in_common + toc_shared=[] + segtoc=[] + if (@md.opt.act[:verbose][:set]==:on \ + || @md.opt.act[:verbose_plus][:set]==:on \ + || @md.opt.act[:maintenance][:set]==:on) + SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set],'Scroll & Segtoc').txt_grey + end + format_head_toc=SiSU_XHTML_EPUB2_Format::HeadToc.new(@md) + dochead=format_head_toc.head + dochead=dochead.gsub(/toc\.(html)/,'doc.\1') #kludge + toc_shared << dochead #<< ads.div.major + segtoc << format_head_toc.head #<< ads.div.major + if defined? @md.rights.all \ + and @md.rights.all + rights=format_head_toc.rights.all + rights=SiSU_XHTML_EPUB2_Tune::CleanXHTML.new(rights).clean + end + if defined? @md.notes.prefix_b \ + and @md.notes.prefix_b + prefix_b=format_head_toc.prefix_b + prefix_b=SiSU_XHTML_EPUB2_Tune::CleanXHTML.new(prefix_b).clean + end + tmp_head=nil + doc_title_endnote=@md.title.full.gsub(/(\*+)/,'\1') + tmp_head=doc_title_endnote + "\n" + txt_obj={ txt: tmp_head } + format_txt_obj=SiSU_XHTML_EPUB2_Format::FormatTextObject.new(@md,txt_obj) + toc_shared << format_txt_obj.center_bold + segtoc << format_txt_obj.center_bold + if defined? @md.creator.author \ + and @md.creator.author + creator_endnote=@md.creator.author.gsub(/(\*+)/,%{#{$ep[:hsp]}\\1}) + tmp_head=creator_endnote + "\n" + txt_obj={ txt: tmp_head } + format_txt_obj=SiSU_XHTML_EPUB2_Format::FormatTextObject.new(@md,txt_obj) + toc_shared << format_txt_obj.center_bold + segtoc << format_txt_obj.center_bold + end + tmp_head=nil + if defined? @md.prefix_a \ + and @md.prefix_a + tmp_head ||= %{#{@md.prefix_a}\n} + toc_shared << tmp_head.dup + segtoc << tmp_head.dup + end + tmp_head=nil + toc_shared << @links_guide_toc + if defined? @md.rights.all \ + and @md.rights.all + toc_shared << rights + end + if defined? @md.prefix_b \ + and @md.prefix_b + toc_shared << prefix_b + end + #Table of Contents added/appended here + toc_shared << @toc[:scr] + segtoc << @links_guide_toc + segtoc << @toc[:seg] + if defined? @md.rights.all \ + and @md.rights.all + segtoc << rights + end + if defined? @md.prefix_b \ + and @md.prefix_b + segtoc << prefix_b + end + #Segtoc tail added here + segtoc << format_head_toc.xhtml_close + segtoc=segtoc.flatten.compact #watch + SiSU_XHTML_EPUB2::Source::Output.new(@md).make_cover_image + SiSU_XHTML_EPUB2::Source::Output.new(@md,segtoc).make_segtoc + segtoc=[] + @toc[:scr],@toc[:seg]=[],[] + toc_shared + end + end + class Table < SiSU_XHTML_Table::TableXHTML + end + class Seg < SiSU_XHTML_EPUB2_Seg::Seg + end + class Output + def initialize(md,output='') + @md,@output=md,output + @epub_doc="#{@md.fnb}.epub" + @epub_header=SiSU_XHTML_EPUB2_Format::HeadInformation.new(@md) + @make=SiSU_Env::ProcessingSettings.new(@md) + @make_file=SiSU_Env::CreateFile.new(@md.fns) + end + def songsheet + mimetype + metainf_container + css + images if @md.ec[:image] + #concordance #uncomment to enable inclusion of concordance file + output_zip + end + def mimetype + out=@make_file.epub.mimetype + out<<@epub_header.mimetype + out.close + end + def metainf_container #container.xml file in META-INF directory + out=@make_file.epub.metainf_cont + out<<@epub_header.metainf_container + out.close + end + def css + out=@make_file.epub.xhtml_css + out << SiSU_XHTML_EPUB2_Format::CSS.new.css_epub_xhtml + out.close + end + def epub_toc_ncx + begin + out=@make_file.epub.toc_ncx + @output.each do |para| + unless para =~/\A\s*\Z/ + out.puts para + end + end + out.close + rescue + SiSU_Errors::Rescued.new($!,$@,@md.opt.cmd,@md.fns).location do + __LINE__.to_s + ':' + __FILE__ + end + end + end + def epub_metadata_opf + begin + out=@make_file.epub.metadata + @output.each do |para| + unless para =~/\A\s*\Z/ + out.puts para + end + end + out.close + rescue + SiSU_Errors::Rescued.new($!,$@,@md.opt.cmd,@md.fns).location do + __LINE__.to_s + ':' + __FILE__ + end + end + end + def images + img_pth=@md.env.path.image_source_include + img_src_pth=unless @md.opt.f_pth[:pth] =~/\/\S+?\/sisupod\/\S+?\/sisupod\/doc/ + @md.file.output_path.epub.rel_image + else + pt=/(\/\S+?\/sisupod\/\S+?\/sisupod)\/doc/.match(@md.opt.f_pth[:pth])[1] + pt + '/image' + end + @md.ec[:image].each do |x| + if FileTest.directory?("#{@md.env.processing_path.epub}/#{Ep[:d_oebps]}/image") \ + && FileTest.file?("#{img_src_pth}/#{x}") + FileUtils::cp("#{img_src_pth}/#{x}","#{@md.env.processing_path.epub}/#{Ep[:d_oebps]}/image") + elsif FileTest.directory?("#{@md.env.processing_path.epub}/#{Ep[:d_oebps]}/image") \ + && FileTest.file?("#{img_pth}/#{x}") + FileUtils::cp("#{img_pth}/#{x}","#{@md.env.processing_path.epub}/#{Ep[:d_oebps]}/image") + else STDERR.puts %{\t*WARN* did not find image - "#{x}" in #{img_src_pth} or #{img_pth} [#{__FILE__}:#{__LINE__}]} + end + end + end + def concordance + SiSU_XHTML_EPUB2_Concordance::Source.new(@md.opt).read + end + def output_zip + FileUtils::mkdir_p(@md.file.output_path.epub.dir) unless FileTest.directory?(@md.file.output_path.epub.dir) + if FileTest.directory?(@md.env.processing_path.epub) + pwd=Dir.pwd + Dir.chdir(@md.env.processing_path.epub) + system(" + zip -qXr9D #{@epub_doc} * + ") + FileUtils::mv(@epub_doc, @md.file.place_file.epub.dir) + Dir.chdir(pwd) + unless @md.opt.act[:maintenance][:set]==:on + FileUtils::rm_r(@md.env.processing_path.epub) + end + end + end + def make_cover_image + begin + if @md.make.cover_image? \ + and @md.make.cover_image.is_a?(Hash) \ + and @md.make.cover_image[:cover] =~/\S+/ + filename_xhtml=@make_file.epub.xhtml_cover_image + cover_image=< + + + + Cover + + + + + +
    +
    + + + +
    +
    + + +WOK + filename_xhtml.puts cover_image,"\n" + filename_xhtml.close + end + rescue + SiSU_Errors::Rescued.new($!,$@,@md.opt.cmd,@md.fns).location do + __LINE__.to_s + ':' + __FILE__ + end + end + end + def make_segtoc + begin + if @make.build.toc? + filename_xhtml=@make_file.epub.xhtml_index + @output.each do |para| + para=para.strip + unless para =~/\A\s*\Z/ + filename_xhtml.puts para,"\n" + end + end + filename_xhtml.close + end + rescue + SiSU_Errors::Rescued.new($!,$@,@md.opt.cmd,@md.fns).location do + __LINE__.to_s + ':' + __FILE__ + end + end + end + end + end +end +__END__ diff --git a/lib/sisu/v5/xhtml_epub2_concordance.rb b/lib/sisu/v5/xhtml_epub2_concordance.rb new file mode 100644 index 00000000..5668521b --- /dev/null +++ b/lib/sisu/v5/xhtml_epub2_concordance.rb @@ -0,0 +1,324 @@ +# 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: epub concordance file (html concordance, wordmap, linked index + of words in document) + +=end +module SiSU_XHTML_EPUB2_Concordance + require_relative 'particulars' # particulars.rb + include SiSU_Particulars + require_relative 'sysenv' # sysenv.rb + include SiSU_Env + require_relative 'defaults' # defaults.rb + include SiSU_Viz + require_relative 'xhtml_epub2_format' # xhtml_epub2_format.rb + include SiSU_XHTML_EPUB2_Format + class Source + def initialize(opt) + @opt=opt + @particulars=SiSU_Particulars::CombinedSingleton.instance.get_all(opt) + end + def read + begin + @env,@md=@particulars.env,@particulars.md + wordmax=@env.concord_max + unless @md.wc_words.nil? + if @md.wc_words < wordmax + SiSU_XHTML_EPUB2_Concordance::Source::Words.new(@particulars).songsheet + else + SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set],"*WARN* concordance skipped, large document has over #{wordmax} words (#{@md.wc_words})").warn unless @md.opt.act[:quiet][:set]==:on + end + else + SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set],"*WARN* wc (word count) is off, concordance will be processed for all files including those over the max set size of: #{wordmax} words").warn unless @md.opt.act[:quiet][:set]==:on + SiSU_XHTML_EPUB2_Concordance::Source::Words.new(@particulars).songsheet + end + rescue + SiSU_Errors::Rescued.new($!,$@,@md.opt.cmd,@md.fns).location do + __LINE__.to_s + ':' + __FILE__ + end + ensure + end + end + private + class DocTitle + include SiSU_Viz + #revisit, both requires (html & xml_shared) needed for stand alone operation (sisu -w [filename]) + require_relative 'xhtml_epub2' # xhtml_epub2.rb + def initialize(particulars) + @particulars,@md=particulars,particulars.md + @data=SiSU_XHTML_EPUB2::Source::XHTML_Environment.new(particulars).tuned_file_instructions + @vz=SiSU_Viz::Defaults.new + @fnb=@md.fnb + @lex_button=%{SiSU home} + @doc_details =<
    } + - %{#{para_table}}). - gsub(/#{Mx[:tc_p]}#{Mx[:tc_p]}(\d+?)#{Mx[:tc_p]}/u, - %{} + - %{#{para_table}}). - gsub(/#{Mx[:tc_c]}/, '
    } + - %{#{para_table}}). - gsub(/#{Mx[:tc_p]}#{Mx[:tc_p]}(\d+?)#{Mx[:tc_p]}/u, - %{} + - %{#{para_table}}). - gsub(/#{Mx[:tc_c]}/, '
    #{$ep[:hsp]}

    #{@md.title.full}

    #{@md.creator.author}

    +WOK + end + def create + @css=SiSU_Env::CSS_Stylesheet.new(@particulars.md) + format_head_toc=SiSU_XHTML_EPUB2_Format::HeadToc.new(@md) + dochead=format_head_toc.head + < + #{@doc_details} +

    Word index links are to html versions of the text the segmented version followed by the scroll (single document) version.
    [For segmented text references [T1], [T2] or [T3] appearing without a link, indicates that the word appears in a title (or subtitle) of the text (that is identifiable by the appended object citation number).]

    +

    (The word listing/index is Case sensitive: Capitalized words appear before lower case)

    +

    + word (number of occurences)
    linked references to word within document
    + [if number of occurences exceed number of references - word occurs more than once in at least one reference. Footnote/endnotes are either assigned to the paragraph from which they are referenced or ignored, so it is relevant to check the footnotes referenced from within a paragraph as well.] +

    +

    + (After the page is fully loaded) you can jump directly to a word by appending a hash (#) and the word to the url for this text, (do not forget that words are case sensitive, and may be listed twice (starting with and without an upper case letter)), #your_word # [#{$ep[:hsp]}http://[web host]/#{@fnb}/concordance.html#your_word#{$ep[:hsp]}] +

    +WOK + end + end + class Word + @@word_previous='' + def initialize(word,freq) + @word,@freq=word,freq + end + def html + w=if @word.capitalize==@@word_previous + %{\n

    #{@word}

    (#{@freq})

    \n\t

    } + else n=@word.strip.gsub(/\s+/,'_') #also need to convert extended character set to html + %{\n

    #{@word}

    (#{@freq})

    \n\t

    } + end + @@word_previous=@word.capitalize + w + end + end + class Words + require_relative 'defaults' # defaults.rb + include SiSU_Viz + require_relative 'xhtml_epub2_format' # xhtml_epub2_format.rb + include SiSU_XHTML_EPUB2_Format + require_relative 'sysenv' # sysenv.rb + include SiSU_Screen + def initialize(particulars) + @particulars=particulars + begin + @vz=SiSU_Viz::Defaults.new + @env,@md,@ao_array=particulars.env,particulars.md,particulars.ao_array + @path="#{@env.processing_path.epub}" + @freq=Hash.new(0) + @rxp_lv1=/^#{Mx[:lv_o]}1:/ #fix Mx[:lv_o] + @rxp_lv2=/^#{Mx[:lv_o]}2:/ #fix Mx[:lv_o] + @rxp_lv3=/^#{Mx[:lv_o]}3:/ #fix Mx[:lv_o] + @rxp_seg=/^#{Mx[:lv_o]}4:(\S+?)#{Mx[:lv_c]}/ + @rxp_title=Regexp.new("^#{Mx[:meta_o]}title#{Mx[:meta_c]}\s*(.+?)\s*$") + @rxp_t1=Regexp.new('^T1') + @rxp_t2=Regexp.new('^T2') + @rxp_t3=Regexp.new('^T3') + @rxp_excluded1=/(?:https?|file|ftp):\/\/\S+/ + @rxp_excluded0=/^(?:#{Mx[:fa_bold_o]}|#{Mx[:fa_italics_o]})?(?:to\d+|\d+| |#{Mx[:br_endnotes]}|EOF|#{Mx[:br_eof]}|thumb_\S+|snap_\S+|_+|-+|[(]?(?:ii+|iv|vi+|ix|xi+|xiv|xv|xvi+|xix|xx)[).]?|\S+?_\S+|[\d_]+\w\S+|[\w\d]{1,2}|\d{1,3}\w?|[0-9a-f]{16,64}|\d{2,3}x\d{2,3}|\S{0,2}sha\d|\S{0,3}\d{4}w\d\d|\b\w\d+|\d_all\b|e\.?g\.?)(?:#{Mx[:fa_bold_c]}|#{Mx[:fa_italics_c]})?$/mi #this regex causes and cures a stack dump in ruby 1.9 !!! + @rgx_splitlist=%r{[—.,;:-]+|#{Mx[:nbsp]}+}mi + @rgx_scanlist=%r{#{Mx[:fa_italics_o]}[a-zA-Z0-9"\s]{2,12}#{Mx[:fa_italics_c]}|#{Mx[:fa_bold_o]}[a-zA-Z0-9"\s]{2,12}#{Mx[:fa_bold_c]}|#{Mx[:url_o]}https?://\S+?#{Mx[:url_c]}|file://\S+|<\S+?>|\w+|[a-zA-Z]+}mi + rescue + SiSU_Errors::Rescued.new($!,$@,@md.opt.cmd,@md.fns).location do + __LINE__.to_s + ':' + __FILE__ + end + end + end + def songsheet + begin + #fix to use + p __LINE__.to_s + ':' + __FILE__ + p "#{@path}/content/#{@md.fn[:epub_concord]}" + p "#{@md.file.output_path.epub.dir}/#{@md.file.base_filename.epub}" + @file_concordance=File.open("#{@path}/content/#{@md.fn[:epub_concord]}",'w') + map_para + rescue + SiSU_Errors::Rescued.new($!,$@,@md.opt.cmd,@md.fns).location do + __LINE__.to_s + ':' + __FILE__ + end + ensure + @file_concordance.close + end + end + protected + def location_scroll(wordlocation,show) + @wordlocation=wordlocation + %{#{@wordlocation}; } + end + def location_seg(wordlocation,show) + @wordlocation,@show=wordlocation,show + @word_location_seg=wordlocation.gsub(/(.+?)\#(\d+)/,"\\1#{Sfx[:epub_xhtml]}#o\\2") unless wordlocation.nil? + case @wordlocation + when @rxp_t1 + %{[H]#{@show}, } + when @rxp_t2 + %{[H]#{@show}, } + when @rxp_t3 + %{[H]#{@show}, } + else %{#{@show}, } + end + end + def map_para + @seg,toy=nil,nil + @word_map={} + @ao_array.each do |line| + if defined? line.ocn + if (line.is ==:heading \ + || line.is ==:heading_insert) \ + && line.ln==4 + @seg=line.name + end + if line.ocn.to_s =~/\d+/ then toy=line.ocn.to_s + end + if toy =~/\d+/ \ + and toy !~/^0$/ + line.obj=line.obj.split(@rgx_splitlist).join(' ') #%take in word or other match + for word in line.obj.scan(@rgx_scanlist) #%take in word or other match + word=word.gsub(/#{Mx[:lnk_o]}|#{Mx[:lnk_c]}|#{Mx[:url_o]}|#{Mx[:url_c]}/,''). + gsub(/#{Mx[:fa_o]}\S+?#{Mx[:fa_o_c]}/,''). + gsub(/#{Mx[:fa_c_o]}\S+?#{Mx[:fa_c]}/,''). + gsub(/#{Mx[:gl_o]}#[a-z]+#{Mx[:gl_c]}/,''). + gsub(/#{Mx[:gl_o]}#[0-9]+#{Mx[:gl_c]}/,''). + gsub(/^\S$/,'') + word=nil if word.empty? + word=nil if word =~@rxp_excluded0 #watch + word=nil if word =~@rxp_excluded1 #watch + word=nil if word =~/^\S$/ + if word + word=word.gsub(/#{Mx[:br_nl]}|#{Mx[:br_line]}/,' '). + gsub(/#{Mx[:fa_o]}[a-z]{1,7}#{Mx[:fa_o_c]}|#{Mx[:fa_c_o]}[a-z]{1,7}#{Mx[:fa_c]}/,''). + gsub(/#{Mx[:mk_o]}(?:[0-9a-f]{32}:[0-9a-f]{32}|[0-9a-f]{64}:[0-9a-f]{64})#{Mx[:mk_c]}/,''). + gsub(/#{Mx[:mk_o]}(?:[0-9a-f]{32}|[0-9a-f]{64})#{Mx[:mk_c]}/,''). + gsub(/#{Mx[:en_a_o]}(?:\d|[*+])*|#{Mx[:en_b_o]}(?:\d|[*+])*|#{Mx[:en_a_c]}|#{Mx[:en_b_c]}/mi,''). + gsub(/#{Mx[:fa_o]}\S+?#{Mx[:fa_o_c]}/,'').gsub(/#{Mx[:fa_c_o]}\S+?#{Mx[:fa_c]}/,''). + gsub(/<\/?\S+?>/,''). + gsub(/^\@+/,''). + strip. + gsub(/#{Mx[:tc_p]}.+/,''). + gsub(/[\.,;:"]$/,''). + gsub(/["]/,''). + gsub(/^\s*[\(]/,''). + gsub(/[\(]\s*$/,''). + gsub(/^(?:See|e\.?g\.?).+/,''). + gsub(/^\s*[.,;:]\s*/,''). + strip. + gsub(/^\(?[a-zA-Z]\)$/,''). + gsub(/^\d+(st|nd|rd|th)$/,''). + gsub(/^(\d+\.?)+$/, ''). + gsub(/#{Mx[:mk_o]}|#{Mx[:mk_c]}/,''). + gsub(/:name#\S+/,''). + gsub(/^\S$/,'') + word=nil if word =~/^\S$/ + word=nil if word =~/^\s*$/ #watch + if word + unless word =~/[A-Z][A-Z]/ \ + or word =~/\w+\s\w+/ + word=word.capitalize + end + @freq[word] +=1 + @word_map[word] ||= [] + if line !~@rxp_lv1 \ + and line !~@rxp_lv2 \ + and line !~@rxp_lv3 + @word_map[word] << location_seg("#{@seg}\##{toy}",toy) + else + @word_map[word] << case line + when @rxp_lv1; location_seg('T1',toy) + when @rxp_lv2; location_seg('T2',toy) + when @rxp_lv3; location_seg('T3',toy) + end + end + end + end + end + end + end + end + seg='' + @file_concordance << SiSU_XHTML_EPUB2_Concordance::Source::DocTitle.new(@particulars).create + alph=%W[A B C D E F G H I J K L M N O P Q R S T U V W X Y Z] + @file_concordance << '

    ' + alph.each {|x| @file_concordance << %{#{x},#{$ep[:hsp]}}} + @file_concordance << '

    ' + letter=alph.shift + @file_concordance << %{\n

    A

    } + for word in @freq.keys.sort! {|a,b| a.downcase<=>b.downcase} + f=/^(\S)/.match(word)[1] + if letter < f.upcase + while letter < f.upcase + if alph.length > 0 + letter=alph.shift + @file_concordance << %{\n

    #{letter}

    } + else break + end + end + end + keyword=SiSU_XHTML_EPUB2_Concordance::Source::Word.new(word,@freq[word]).html + if keyword !~ @rxp_excluded0 + if @word_map[word][0] =~ /\d+/ + @file_concordance << %{#{keyword}#{seg}#{@word_map[word].uniq.compact.join}} + end + @file_concordance << '

    ' + end + # special cases endnotes and header levels 1 - 3 + end + credits=@vz.credits_sisu_epub + @file_concordance << %{>#{credits}\n} # footer + end + end + end +end +__END__ diff --git a/lib/sisu/v5/xhtml_epub2_format.rb b/lib/sisu/v5/xhtml_epub2_format.rb new file mode 100644 index 00000000..e53c3bfe --- /dev/null +++ b/lib/sisu/v5/xhtml_epub2_format.rb @@ -0,0 +1,2236 @@ +# 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: epub formating, css template + +=end +module SiSU_XHTML_EPUB2_Format + include SiSU_Viz + class ParagraphNumber + def initialize(md,ocn) + @md,@ocn=md,ocn.to_s + @ocn ||='' + end + def ocn_display + make=SiSU_Env::ProcessingSettings.new(@md) + if make.build.ocn? + ocn_class='ocn' + if @ocn==nil \ + or @ocn.to_i==0 \ + or @ocn.empty? + %{} + else + @ocn.gsub(/^(\d+|)$/, + %{}) + end + else + %{} + end + end + def name + (@ocn==nil || @ocn.empty?) ? '' : %{} + end + def id #w3c? "tidy" complains about numbers as identifiers ! annoying + (@ocn==nil || @ocn.empty?) ? '' : %{id="o#{@ocn}"} + end + def goto + (@ocn==nil || @ocn.empty?) ? '' : %{} + end + end + class CSS + def css_epub_xhtml + <<-WOK +/* SiSU epub css default stylesheet */ + body { + color: black; + background: #ffffff; + background-color: #ffffff; + } +/* + table { + margin-left: 5%; + display: block; + } + tr { + display: block; + } + th,td { + display: inline; + vertical-align: top; + } +*/ + a:link { + color: #003399; + text-decoration: none; + } + a:visited { + color: #003399; + text-decoration: none; + } + a:hover { + color: #000000; + background-color: #f9f9aa; + } +/* + a:hover { + border-bottom: 2px solid #777777; + background-color: #fff3b6; + } +*/ + a:hover img { + background-color: #ffffff; + } + a:active { + color: #003399; + text-decoration: underline; + } + a.lnkocn:link { + color: #777777; + text-decoration: none; + } + div { + margin-left: 0; + margin-right: 0; + } + div.p { + margin-left: 5%; + margin-right: 1%; + } + + .norm, .bold, .verse, .group, .block, .alt { + line-height: 133%; + margin-left: 0em; + margin-right: 2em; + margin-top: 12px; + margin-bottom: 0px; + padding-left: 0em; + text-indent: 0mm; + } + p, h0, h1, h2, h3, h4, h5, h6 { + display: block; + font-family: verdana, arial, georgia, tahoma, sans-serif, helvetica, times, roman; + font-size: 100%; + font-weight: normal; + line-height: 133%; + text-align: justify; + margin-left: 0em; + margin-right: 2em; + text-indent: 0mm; + margin-top: 0.8em; + margin-bottom: 0.8em; + } + p.norm { } + p.i1 {padding-left: 1em;} + p.i2 {padding-left: 2em;} + p.i3 {padding-left: 3em;} + p.i4 {padding-left: 4em;} + p.i5 {padding-left: 5em;} + p.i6 {padding-left: 6em;} + p.i7 {padding-left: 7em;} + p.i8 {padding-left: 8em;} + p.i9 {padding-left: 9em;} + + p.h0i0 { + padding-left: 0em; + text-indent: 0em; + } + p.h0i1 { + padding-left: 1em; + text-indent: -1em; + } + p.h0i2 { + padding-left: 2em; + text-indent: -2em; + } + p.h0i3 { + padding-left: 3em; + text-indent: -3em; + } + p.h0i4 { + padding-left: 4em; + text-indent: -4em; + } + p.h0i5 { + padding-left: 5em; + text-indent: -5em; + } + p.h0i6 { + padding-left: 6em; + text-indent: -6em; + } + p.h0i7 { + padding-left: 7em; + text-indent: -7em; + } + p.h0i8 { + padding-left: 8em; + text-indent: -8em; + } + p.h0i9 { + padding-left: 9em; + text-indent: -9em; + } + + p.h1i0 { + padding-left: 0em; + text-indent: 1em; + } + p.h1i1 { + padding-left: 1em; + text-indent: 0em; + } + p.h1i2 { + padding-left: 2em; + text-indent: -1em; + } + p.h1i3 { + padding-left: 3em; + text-indent: -2em; + } + p.h1i4 { + padding-left: 4em; + text-indent: -3em; + } + p.h1i5 { + padding-left: 5em; + text-indent: -4em; + } + p.h1i6 { + padding-left: 6em; + text-indent: -5em; + } + p.h1i7 { + padding-left: 7em; + text-indent: -6em; + } + p.h1i8 { + padding-left: 8em; + text-indent: -7em; + } + p.h1i9 { + padding-left: 9em; + text-indent: -8em; + } + + p.h2i0 { + padding-left: 0em; + text-indent: 2em; + } + p.h2i1 { + padding-left: 1em; + text-indent: 1em; + } + p.h2i2 { + padding-left: 2em; + text-indent: 0em; + } + p.h2i3 { + padding-left: 3em; + text-indent: -1em; + } + p.h2i4 { + padding-left: 4em; + text-indent: -2em; + } + p.h2i5 { + padding-left: 5em; + text-indent: -3em; + } + p.h2i6 { + padding-left: 6em; + text-indent: -4em; + } + p.h2i7 { + padding-left: 7em; + text-indent: -5em; + } + p.h2i8 { + padding-left: 8em; + text-indent: -6em; + } + p.h2i9 { + padding-left: 9em; + text-indent: -7em; + } + + p.h3i0 { + padding-left: 0em; + text-indent: 3em; + } + p.h3i1 { + padding-left: 1em; + text-indent: 2em; + } + p.h3i2 { + padding-left: 2em; + text-indent: 1em; + } + p.h3i3 { + padding-left: 3em; + text-indent: 0em; + } + p.h3i4 { + padding-left: 4em; + text-indent: -1em; + } + p.h3i5 { + padding-left: 5em; + text-indent: -2em; + } + p.h3i6 { + padding-left: 6em; + text-indent: -3em; + } + p.h3i7 { + padding-left: 7em; + text-indent: -4em; + } + p.h3i8 { + padding-left: 8em; + text-indent: -5em; + } + p.h3i9 { + padding-left: 9em; + text-indent: -6em; + } + + p.h4i0 { + padding-left: 0em; + text-indent: 4em; + } + p.h4i1 { + padding-left: 1em; + text-indent: 3em; + } + p.h4i2 { + padding-left: 2em; + text-indent: 2em; + } + p.h4i3 { + padding-left: 3em; + text-indent: 1em; + } + p.h4i4 { + padding-left: 4em; + text-indent: 0em; + } + p.h4i5 { + padding-left: 5em; + text-indent: -1em; + } + p.h4i6 { + padding-left: 6em; + text-indent: -2em; + } + p.h4i7 { + padding-left: 7em; + text-indent: -3em; + } + p.h4i8 { + padding-left: 8em; + text-indent: -4em; + } + p.h4i9 { + padding-left: 9em; + text-indent: -5em; + } + + p.h5i0 { + padding-left: 0em; + text-indent: 5em; + } + p.h5i1 { + padding-left: 1em; + text-indent: 4em; + } + p.h5i2 { + padding-left: 2em; + text-indent: 3em; + } + p.h5i3 { + padding-left: 3em; + text-indent: 2em; + } + p.h5i4 { + padding-left: 4em; + text-indent: 1em; + } + p.h5i5 { + padding-left: 5em; + text-indent: 0em; + } + p.h5i6 { + padding-left: 6em; + text-indent: -1em; + } + p.h5i7 { + padding-left: 7em; + text-indent: -2em; + } + p.h5i8 { + padding-left: 8em; + text-indent: -3em; + } + p.h5i9 { + padding-left: 9em; + text-indent: -4em; + } + + p.h6i0 { + padding-left: 0em; + text-indent: 6em; + } + p.h6i1 { + padding-left: 1em; + text-indent: 5em; + } + p.h6i2 { + padding-left: 2em; + text-indent: 4em; + } + p.h6i3 { + padding-left: 3em; + text-indent: 3em; + } + p.h6i4 { + padding-left: 4em; + text-indent: 2em; + } + p.h6i5 { + padding-left: 5em; + text-indent: 1em; + } + p.h6i6 { + padding-left: 6em; + text-indent: 0em; + } + p.h6i7 { + padding-left: 7em; + text-indent: -1em; + } + p.h6i8 { + padding-left: 8em; + text-indent: -2em; + } + p.h6i9 { + padding-left: 9em; + text-indent: -3em; + } + + p.h7i0 { + padding-left: 0em; + text-indent: 7em; + } + p.h7i1 { + padding-left: 1em; + text-indent: 6em; + } + p.h7i2 { + padding-left: 2em; + text-indent: 5em; + } + p.h7i3 { + padding-left: 3em; + text-indent: 4em; + } + p.h7i4 { + padding-left: 4em; + text-indent: 3em; + } + p.h7i5 { + padding-left: 5em; + text-indent: 2em; + } + p.h7i6 { + padding-left: 6em; + text-indent: 1em; + } + p.h7i7 { + padding-left: 7em; + text-indent: 0em; + } + p.h7i8 { + padding-left: 8em; + text-indent: -1em; + } + p.h7i9 { + padding-left: 9em; + text-indent: -2em; + } + + p.h8i0 { + padding-left: 0em; + text-indent: 8em; + } + p.h8i1 { + padding-left: 1em; + text-indent: 7em; + } + p.h8i2 { + padding-left: 2em; + text-indent: 6em; + } + p.h8i3 { + padding-left: 3em; + text-indent: 5em; + } + p.h8i4 { + padding-left: 4em; + text-indent: 4em; + } + p.h8i5 { + padding-left: 5em; + text-indent: 3em; + } + p.h8i6 { + padding-left: 6em; + text-indent: 2em; + } + p.h8i7 { + padding-left: 7em; + text-indent: 1em; + } + p.h8i8 { + padding-left: 8em; + text-indent: 0em; + } + p.h8i9 { + padding-left: 9em; + text-indent: -1em; + } + + p.h9i0 { + padding-left: 0em; + text-indent: 9em; + } + p.h9i1 { + padding-left: 1em; + text-indent: 8em; + } + p.h9i2 { + padding-left: 2em; + text-indent: 7em; + } + p.h9i3 { + padding-left: 3em; + text-indent: 6em; + } + p.h9i4 { + padding-left: 4em; + text-indent: 5em; + } + p.h9i5 { + padding-left: 5em; + text-indent: 4em; + } + p.h9i6 { + padding-left: 6em; + text-indent: 3em; + } + p.h9i7 { + padding-left: 7em; + text-indent: 2em; + } + p.h9i8 { + padding-left: 8em; + text-indent: 1em; + } + p.h9i9 { + padding-left: 9em; + text-indent: 0em; + } + + p.it0 { + margin-left: 0em; + margin-top: 6px; + margin-bottom: 0px; + line-height: 100%; + } + p.it1 { + margin-left: 1em; + margin-top: 0px; + margin-bottom: 0px; + line-height: 100%; + } + p.it2 { + margin-left: 2em; + margin-top: 0px; + margin-bottom: 0px; + line-height: 100%; + } + p.it3 { + margin-left: 3em; + margin-top: 0px; + margin-bottom: 0px; + line-height: 100%; + } + p.it4 { + margin-left: 4em; + margin-top: 0px; + margin-bottom: 0px; + line-height: 100%; + } + p.it5 { + margin-left: 5em; + margin-top: 0px; + margin-bottom: 0px; + line-height: 100%; + } + p.it6 { + margin-left: 6em; + margin-top: 0px; + margin-bottom: 0px; + line-height: 100%; + } + p.it7 { + margin-left: 7em; + margin-top: 0px; + margin-bottom: 0px; + line-height: 100%; + } + p.it8 { + margin-left: 8em; + margin-top: 0px; + margin-bottom: 0px; + line-height: 100%; + } + p.it9 { + margin-left: 9em; + margin-bottom: 0px; + margin-top: 0px; + line-height: 100%; + } + + p.group { } + + p.block { } + + p.alt { } + + p.verse { + margin-bottom: 6px; + } + + p.code { + font-family: inconsolata, andale mono, courier new, courier, monospace; + font-size: 90%; + text-align: left; + background-color: #eeeeee; + } + + p.caption { + text-align: left; + font-size: 80%; + display: inline; + } + + p.endnote { + font-size: 96%; + line-height: 120%; + text-align: left; + margin-right: 2em; + } + p.endnote_indent { + font-size: 96%; + line-height: 120%; + text-align: left; + margin-left: 2em; + margin-right: 2em; + } + + p.center { + text-align: center; + } + p.align_right { + text-align: right; + } + p.bold { + font-weight: bold; + } + p.bold_left { + font-weight: bold; + text-align: left; + } + p.centerbold { + text-align: center; + font-weight: bold; + } + p.em { + font-weight: bold; + font-style: normal; + background: #fff3b6; + } + + p.small { + font-size: 80%; + margin-top: 0px; + margin-bottom: 0px; + margin-right: 6px; + text-align: left; + } + + .tiny, .tiny_left, .tiny_right, .tiny_center { + font-size: 10px; + margin-top: 0px; + margin-bottom: 0px; + color: #777777; + margin-right: 6px; + text-align: left; + } + p.tiny { } + p.tiny_left { + margin-left: 0px; + margin-right: 0px; + text-align: left; + } + p.tiny_right { + margin-right: 1em; + text-align: right; + } + p.tiny_center { + margin-left: 0px; + margin-right: 0px; + text-align: center; + } + + p.concordance_word { + line-height: 150%; + font-weight: bold; + display: inline; + margin-top: 4px; + margin-bottom: 1px; + } + p.concordance_count { + font-size: 80%; + color: #777777; + display: inline; + margin-left: 0em; + } + p.concordance_object { + font-size: 80%; + line-height: 120%; + text-align: left; + margin-left: 3em; + margin-top: 1px; + margin-bottom: 3px; + } + p.book_index_lev1 { + line-height: 100%; + margin-top: 4px; + margin-bottom: 1px; + } + p.book_index_lev2 { + line-height: 100%; + text-align: left; + margin-left: 3em; + margin-top: 1px; + margin-bottom: 3px; + } + + p.quickref { + font-size: 10px; + font-style: italic; + margin-top: 0px; + margin-bottom: 0px; + color: #777777; + margin-right: 5px; + text-align: left; + } + p.bigref { + font-size: 11px; + font-weight: bold; + margin-top: 0px; + margin-bottom: 0px; + color: #777777; + margin-right: 5px; + text-align: center; + } + + p.letter { + font-weight: bold; + font-size: 80%; + margin-left: 0em; + margin-top: 2px; + margin-bottom: 2px; + margin-right: 6px; + text-align: left; + color: white; + background: #880000; + } + + tt { + font-family: inconsolata, andale mono, courier new, courier, monospace; + background-color: #eeeeee; + } + + label.ocn { + width: 2%; + float: right; + top: 0; + font-size: 10px; + margin-top: 0px; + margin-bottom: 5px; + color: #777777; + margin-right: 5px; + text-align: right; + background-color: #ffffff; + } + + table { } + tr { } + th,td { + vertical-align: top; + text-align: left; + } + th { + font-weight: bold; + } + + p.left, th.left, td.left { + text-align: left; + } + p.small_left, th.small_left, td.small_left { + text-align: left; + font-size: 80%; + } + p.right, th.right, td.right { + text-align: right; + } + + #horizontal_links { + background: #eeeeee; + margin-left: 5%; + margin-right: 5%; + } + #horizontal { + margin: 0; + padding: 0 0 0 10px; + border-top: 1px solid #000077; + border-bottom: 1px solid #000077; + } + #horizontal li { + margin: 0 0 0 0; + padding: 0 16px 0 0; + display: inline; + list-style-type: none; + text-align: left; + background: none; + } + #horizontal a { + line-height: 12px; + margin: 0 0 0 0; + text-decoration: none; + color: #000077; + } + #horizontal a.active, #horizontal a:hover { + border-bottom: 2px solid #777777; + padding-bottom: 2px; + color: #000077; + } + #horizontal a:hover { + color: #000077; + } + + #document_versions { + position: absolute; + top: 10mm; + right: 2%; + width: 12%; + float: right; + } + + #vertical_links { + position: absolute; + top: 10mm; + right: 0px; + width: 20%; + background: #dddddd; + float: right; + } + #vertical { + padding: 0 12px 0px 0px; + margin-left: 2%; + margin-right: 2%; + } + #vertical li { + display: block; + list-style-type: none; + } + #vertical a { + line-height: 12px; + text-decoration: none; + color: #000077; + } + #vertical a.active, #vertical a:hover { + border-bottom: 2px solid #777777; + padding-bottom: 2px; + color: #000077; + } + + ul, li { + list-style-type: none; + list-style: none; + padding-left: 20px; + display: block; + font-family: verdana, arial, georgia, tahoma, sans-serif, helvetica, times, roman; + font-weight: normal; + line-height: 150%; + text-align: justify; + text-indent: 0mm; + margin-left: 1em; + margin-right: 2em; + margin-top: 3px; + margin-bottom: 3px; + } + + li { + background: url(../image/bullet_09.png) no-repeat 0px 6px; + } + + ul { + } + li.bullet { margin-left: 0em; } + li.i1 { margin-left: 1em; } + li.i2 { margin-left: 2em; } + li.i3 { margin-left: 3em; } + li.i4 { margin-left: 4em; } + li.i5 { margin-left: 5em; } + li.i6 { margin-left: 6em; } + li.i7 { margin-left: 7em; } + li.i8 { margin-left: 8em; } + li.i9 { margin-left: 9em; } + + li.doc, li.ref, li.refcenter { + margin-top: 0px; + margin-bottom: 0px; + margin-right: 0px; + font-size: 8px; + font-style: normal; + text-align: left; + } + li.doc { + background: url(../image/bullet_09.png) no-repeat 0px 6px; + padding-left: 16px; + margin-left: 10px; + margin-right: 0px; + } + li.ref { + background: none; + padding-left: 0; + margin-left: 0; + color: #777777; + } + li.refcenter { + background: url(../image/bullet_09.png) no-repeat 0px 6px; + padding-left: 20px; + margin-left: 10%; + font-size: 9px; + color: #777777; + text-align: center; + } + li.refbold { + list-style-type: none; + padding-left: 16px; + margin-left: 0; + margin-right: 10mm; + font-weight: bold; + } + + h0, h1, h2, h3, h4, h5, h6 { + font-weight: bold; + line-height: 120%; + text-align: left; + margin-top: 20px; + margin-bottom: 10px; + } + h4.norm, h5.norm, h6.norm { + margin-top: 10px; + margin-bottom: 0px; + } + h1.center, h2.center, h3.center, h4.center, h5.center, h6.center { + text-align: center; + } + h1 { font-size: 120%; } + h2 { font-size: 115%; } + h3 { font-size: 110%; } + h4 { font-size: 105%; } + h5 { font-size: 100%; } + h6 { font-size: 100%; } + h0 { font-size: 80%; } + + h1.i {margin-left: 2em;} + h2.i {margin-left: 3em;} + h3.i {margin-left: 4em;} + h4.i {margin-left: 5em;} + h5.i {margin-left: 6em;} + h6.i {margin-left: 7em;} + h7.i {margin-left: 8em;} + h8.i {margin-left: 9em;} + h9.i {margin-left: 10em;} + + .toc { + font-weight: normal; + margin-top: 6px; + margin-bottom: 6px; + } + h1.toc { + margin-left: 1em; + font-size: 115%; + line-height: 150%; + } + h2.toc { + margin-left: 2em; + font-size: 110%; + line-height: 140%; + } + h3.toc { + margin-left: 3em; + font-size: 105%; + line-height: 120%; + } + h4.toc { + margin-left: 4em; + font-size: 100%; + line-height: 120%; + } + h5.toc { + margin-left: 5em; + font-size: 95%; + line-height: 110%; + } + h6.toc { + margin-left: 6em; + font-size: 90%; + line-height: 110%; + } + + .microtoc { + margin-top: 2px; + margin-bottom: 2px; + } + + h1.microtoc { + margin-left: 0mm; + font-size: 115%; + } + h2.microtoc { + margin-left: 5mm; + font-size: 110%; + } + h3.microtoc { + margin-left: 10mm; + font-size: 105%; + } + h4.microtoc { + margin-left: 15mm; + font-weight: normal; + font-size: 100%; + } + h5.microtoc { + margin-left: 20mm; + font-weight: normal; + font-size: 95%; + } + h6.microtoc { + margin-left: 25mm; + font-weight: normal; + font-size: 90%; + } + + .subtoc { + margin-right: 34%; + font-weight: normal; + } + h5.subtoc { + margin-left: 2em; + font-size: 80%; + margin-top: 2px; + margin-bottom: 2px; + } + h6.subtoc { + margin-left: 3em; + font-size: 75%; + margin-top: 0px; + margin-bottom: 0px; + } + + div.substance { + width: 100%; + background-color: #ffffff; + } + div.ocn { + width: 5%; + float: right; + top: 0; + background-color: #ffffff; + } + div.endnote { + width: 100%; + background-color: #fffffff; + } + div.toc { + position: absolute; + float: left; + margin: 0; + padding: 0; + padding-top: 0.5em; + border: 0; + width: 5%; + background-color: #eeeeee; + margin-right:1em; + } + div.summary { + margin: 0; + padding: 0; + border-left: 2em solid #eeeeee; + padding-left: 0em; + background-color: #eeeeee; + } + div.content, div.main_column { + margin: 0; + padding: 0; + border-left: 0% solid #ffffff; + padding-left: 5%; + } + div.content:after { + content:' '; + clear:both; + display:block; + height:0; + overflow:hidden + } + div.footer { + clear:left; + padding: 0.5em; + font-size: 80%; + margin: 0; + } + div.toc ul { + list-style: none; + padding: 0; + margin: 0; + } + div.toc li ul a, li ul span.currentlink + { + font-weight: normal; + font-size: 90%; + padding-left: 2em; + background-color: #eeeeee; + } + div.toc a, span.currentlink{ + display:block; + text-decoration: none; + padding-left: 0.5em; + color: #0000aa; + } + hr { + width: 90%; + } + + span.currentlink { + text-decoration: none; + background-color: #aaaaf9; + } + + div.toc a:visited { + color: #0000aa; + } + div.toc a:hover { + color: #000000; + background-color: #f9f9aa; + } + + h1.c, h2.c, h3.c, h4.c, h5.c, h6.c, p.c { + text-align: center + } + h1.red, h2.red, h3.red, h4.red, h5.red, h6.red { + text-align: center; + color: #ff0000; + margin-left: 5mm; + text-indent: 5mm; + margin-top: 30px; + margin-bottom: 20px; + margin-right: 15mm; + } + h1.ruby, h2.ruby, h3.ruby, h4.ruby, h5.ruby, h6.ruby { + text-align: center; + color: #990000; + margin-left: 5mm; + text-indent: 5mm; + margin-top: 30px; + margin-bottom: 20px; + margin-right: 15mm; + } + WOK + end + end + module SanitizeXML + def self.xml(x) + if x.is_a?(String) + x=x.gsub(/ /,' ') if Ep[:alt]==:on + x.gsub(/&/,'&'). + gsub(//,">"). + gsub(/#{Dx[:url_o]}/,Dx[:url_o_xml]).gsub(/#{Dx[:url_c]}/,Dx[:url_o_xml]). + #gsub(//,'>'). + gsub(/\\\\/,'
    '). + gsub(/<br(?: \/)?>/,'
    ') + else x + end + end + end + class HeadInformation + include SiSU_Viz + attr_reader :md,:rdf,:vz + def initialize(md) + @md=md + # DublinCore 1 - title + @vz=SiSU_Viz::Defaults.new + @css=SiSU_Env::CSS_Stylesheet.new(md) + @seg_name_xhtml=(SiSU_XHTML_EPUB2::Source::Seg.new.seg_name_xhtml || []) + @seg_name_xhtml_tracker=(SiSU_XHTML_EPUB2::Source::Seg.new.seg_name_xhtml_tracker || []) + @tocband_scroll,@tocband_segtoc=nil,nil + @index,@metalink='index','#metadata' + end + def doc_type_xhtml + <<-WOK + + + WOK + end +=begin +~/epub + |-- META-INF + | `-- container.xml # simple, make sure full-path of rootfile points to metadata.opf + |-- content + | |-- 1.xhtml + | |-- 2.xhtml + | |-- 3.xhtml + | |-- ... .xhtml + | |-- concordance.xhtml + | |-- css + | | `-- xhtml.css + | |-- endnotes.xhtml + | |-- image + | | |-- arrow_next_red.png + | | |-- arrow_prev_red.png + | | |-- arrow_up_red.png + | | `-- bullet_09.png + | |-- index.xhtml + | |-- meta.xhtml + | |-- metadata.xhtml + | `-- toc.xhtml + |-- metadata.opf #(i) metadata dc; (ii) manifest (contents); (iii) spine (mimetypes) + |-- mimetype # application/epub+zip + `-- toc.ncx #(i) head (ii) doc title (iii) navmap, list of navigation points (like chapters) +=end + def doc_type + doc_type_xhtml + end + def mimetype + <<-WOK +application/epub+zip + WOK + end + def metainf_container #container.xml file in META-INF directory + #simple, make sure full-path of rootfile points to metadata.opf + #epub_metadata.opf content.opf + <<-WOK + + + + + + + WOK + end + def sections(dob,fn_base) + name=fn_base + Sfx[:epub_xhtml] + dir_epub_cont=@md.env.processing_path.epub + '/' + Ep[:d_oebps] + segfilename=dir_epub_cont + '/' + name + output_epub_cont_seg=File.new(segfilename,'w') + output_epub_cont_seg << %{#{doc_type} + + + #{dob.obj} - + #{@md.html_title} + + + #{@css.xhtml_epub} + + #{@vz.color_body} +
    +
    + #{dob.ocn} +

    + #{dob.obj} +

    +
    +
    + + } +output_epub_cont_seg.close + end + def toc_ncx #list of navigation points (like chapters), table of contents, listing each navigation point (chapters and such) under the navigation map + def structure + open + head_open + head + head_close + doc_title + doc_author + navmap_open + #navmap ... + navmap_close + close + end + def open + <<-WOK + + + WOK + end + def close + <<-WOK + + WOK + end + def head_open + <<-WOK + + WOK + end + def head + depth=@md.lvs[1] + @md.lvs[2] + @md.lvs[3] + @md.lvs[4] + title=SanitizeXML.xml(@md.title.full) + author=SanitizeXML.xml(@md.author) + <<-WOK + + #{title} by #{author} + + + + + + + WOK + end + def head_close + <<-WOK + + WOK + end + def doc_title + txt=SanitizeXML.xml(@md.title.full) + <<-WOK + + #{txt} + + WOK + end + def doc_author + txt=SanitizeXML.xml(@md.author) + <<-WOK + + #{txt} + + WOK + end + def navmap_open + <<-WOK + + WOK + end + def navmap_sisu_toc(no) + id_u=DISABLE[:epub][:ncx_navpoint_unique_id] \ + ? '' + : "-#{no}" + <<-WOK + + + Table of Contents + + + + WOK + end + def navpoint(dob,no,fn_base,hashtag=nil) + fn=fn_base + Sfx[:epub_xhtml] + name=hashtag ? fn + hashtag : fn + id_u=DISABLE[:epub][:ncx_navpoint_unique_id] \ + ? '' + : "-#{no}" + <<-WOK + + + #{dob.obj} + + + WOK + end + def navpoint_close + <<-WOK + + WOK + end + def navmap_close + <<-WOK + + WOK + end + self + end + def metadata_opf #(i) metadata dc; (ii) manifest (contents); (iii) spine (mimetypes) + def structure + package_open + metadata_open + metadata_close + manifest_open + manifest_close + spine_open + spine_close + guide_open + guide_close + package_close + end + def package_open + <<-WOK + + + WOK + end + def package_close + <<-WOK + + WOK + end + def metadata #metadata dc + cover_image=if defined? @md.make.cover_image \ + and @md.make.cover_image.is_a?(Hash) \ + and @md.make.cover_image[:cover] =~/\S+/ + %{\n <#{$ep[:o]}meta name="cover" content="cover_image" />} + else '' + end + author=if defined? @md.creator.author \ + and @md.creator.author =~/\S+/ + m='' + @md.creator.author_detail.each do |i| + surname=i[:the] \ + ? i[:the] + : '' + other_names=i[:others] \ + ? ', ' + i[:others] + : '' + m=(m.empty?) \ + ? (surname + other_names) + : (m + '; ' + surname + ', ' + other_names) + m=SanitizeXML.xml(m) + end + x=@md.creator.author.dup + x=SanitizeXML.xml(x) + %{\n #{x}} + else '' + end + editor=if defined? @md.creator.editor \ + and @md.creator.editor =~/\S+/ + m='' + @md.creator.editor_detail.each do |i| + surname=i[:the] \ + ? i[:the] + : '' + other_names=i[:others] \ + ? ', ' + i[:others] + : '' + m=(m.empty?) \ + ? (surname + other_names) + : (m + '; ' + surname + ', ' + other_names) + m=SanitizeXML.xml(m) + end + x=@md.creator.editor.dup + x=SanitizeXML.xml(x) + %{\n #{x}} + else '' + end + translator=if defined? @md.creator.translator \ + and @md.creator.translator =~/\S+/ + m='' + @md.creator.translator_detail.each do |i| + surname=i[:the] \ + ? i[:the] + : '' + other_names=i[:others] \ + ? ', ' + i[:others] + : '' + m=(m.empty?) \ + ? (surname + other_names) + : (m + '; ' + surname + ', ' + other_names) + m=SanitizeXML.xml(m) + end + x=@md.creator.translator.dup + x=SanitizeXML.xml(x) + %{\n #{x}} + else '' + end + illustrator=if defined? @md.creator.illustrator \ + and @md.creator.illustrator =~/\S+/ + m='' + @md.creator.illustrator_detail.each do |i| + surname=i[:the] \ + ? i[:the] + : '' + other_names=i[:others] \ + ? ', ' + i[:others] + : '' + m=(m.empty?) \ + ? (surname + other_names) + : (m + '; ' + surname + ', ' + other_names) + m=SanitizeXML.xml(m) + end + x=@md.creator.illustrator.dup + x=SanitizeXML.xml(x) + %{\n #{x}} + else '' + end + date_published=if defined? @md.date.published \ + and @md.date.published =~/\S+/ + x=@md.date.published.dup + x=SanitizeXML.xml(x) + %{\n #{x}} + else '' + end + subject=if defined? @md.classify.subject \ + and @md.classify.subject =~/\S+/ + x=@md.classify.subject.dup + x=SanitizeXML.xml(x) + %{\n #{x}} + else '' + end + language=if defined? @md.opt.lng \ + and @md.opt.lng =~/\S+/ + language=@md.opt.lng.gsub(/
    /,'
    ') + %{\n #{language}} + else '' + end + rights=if defined? @md.rights.all \ + and @md.rights.all =~/\S+/ + rights=SanitizeXML.xml(@md.rights.all) + rights=rights.gsub(//,' ') + %{\n #{rights}} + else '' + end + f=SiSU_Env::FileOp.new(@md) + <<-WOK + <#{$ep[:o]}metadata + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:opf="http://www.idpf.org/2007/opf" + xmlns:dcterms="http://purl.org/dc/terms/" + xmlns:dc="http://purl.org/dc/elements/1.1/" + unique-identifier="urn:uuid:#{@md.dgst[1]}" version="2.0"> + #{@md.title.full} + #{cover_image}#{author}#{editor}#{translator}#{illustrator}#{language}#{date_published}#{subject}#{rights} + #{f.output_path.epub.url.gsub(/http:\/\//,'')}/#{f.base_filename.epub} + urn:uuid:#{@md.dgst[1]} + + + WOK + end + def manifest_open + <<-WOK + + + + + + + WOK + end + def manifest_content_sisu_toc + <<-WOK + + WOK + end + def manifest_cover_image_information(md) + if defined? md.make.cover_image \ + and @md.make.cover_image.is_a?(Hash) \ + and md.make.cover_image[:cover] =~/\S+/ + <<-WOK + + WOK + else '' + end + end + def manifest_content(dob,fn_base,hashtag=nil) + fn=fn_base + Sfx[:epub_xhtml] + name=hashtag ? fn + hashtag : fn + <<-WOK + + WOK + end + def manifest_images(imgs) + imgs=imgs + ['arrow_next_red.png','arrow_prev_red.png','arrow_up_red.png','bullet_09.png'] + images=[" \n"] + imgs.each do |i| + image,type=/(\S+?)\.(png|jpg|gif)/.match(i)[1,2] + type=type.sub(/jpg/,'jpeg') + images<<<<-WOK + + WOK + end + images=images.join('') + images + end + def manifest_close + <<-WOK + + WOK + end + def spine_open + #spine: reading order of XHTML files from manifest, idref attribute refers back to id in manifest (exclude images, CSS etc.). + <<-WOK + + WOK + end + def spine_cover_image + <<-WOK + + WOK + end + def spine_sisu_toc + <<-WOK + + WOK + end + def spine(dob,fn_base,hashtag=nil) + fn=fn_base + Sfx[:epub_xhtml] + name=hashtag ? fn + hashtag : fn + <<-WOK + + WOK + end + def spine_close + <<-WOK + + WOK + end + def guide_open + #guide: presentation order of XHTML files by reader). + <<-WOK + + WOK + end + def guide_cover_image + <<-WOK + + WOK + end + def guide_sisu_toc + <<-WOK + + WOK + end + def guide(dob,fn_base,hashtag=nil) + fn=fn_base + Sfx[:epub_xhtml] + name=hashtag ? fn + hashtag : fn + name=name ? name : dob.name + guide_name=(name =~/#{Sfx[:epub_xhtml]}/) ? name : (name + Sfx[:epub_xhtml]) + <<-WOK + + WOK + end + def guide_close + <<-WOK + + WOK + end + self + end + def table_close + %{
    +#{@vz.table_close}} + end + def xhtml_close + %{#{@vz.credits_sisu_epub} + +} + end + end + class HeadToc < HeadInformation + def initialize(md) + super(md) + @md=md + @tocband_segtoc=make_seg + end + def manifest_link(text) + %{ #{text}} + end + def concordance_link(text) + if @md.concord_make + %{ + #{text} + } + else '' + end + end + def head + %{#{doc_type} + + + #{@css.xhtml_epub} + + #{@vz.color_body}} + end + def concordance + if @md.concord_make + %{#{@vz.margin_css} +

    + + Concordance + +

    +#{@vz.table_close}} + else + %{#{@vz.margin_css} +#{@vz.table_close}} + end + end + def links_guide_open(type='horizontal') + (type=='vertical') \ + ? links_guide_vertical_open + : links_guide_horizontal_open + end + def prefix_a + end + def rights + def all + rights=SanitizeXML.xml(@md.rights.all) + %{

    Rights: #{rights}

    } + end + self + end + def prefix_b + %{

    Prefix: #{@md.prefix_b}} + end + def make_seg + concord=concordance_link(@vz.nav_txt_concordance) + %{ + +
    + #{@vz.nav_txt_toc_link} + + + #{concord} +#{@vz.table_close}} + end + def manifest #check structure + manifest=manifest_link(@vz.nav_txt_manifest) + %{#{@vz.margin_txt_3} + #{@vz.paragraph_font_small} + #{manifest} + +#{@vz.table_close}} + end + def concordance #check structure + concord=concordance_link(@vz.nav_txt_concordance) + %{#{@vz.margin_txt_3} + #{@vz.paragraph_font_small} + #{concord} + +#{@vz.table_close}} + end + def metadata + %{#{@vz.margin_css} +

    + + MetaData + +

    +#{@vz.table_close}} + end + end + class HeadSeg < HeadInformation + def initialize(md) + super(md) + end + def head + %{#{doc_type} + + + #{@seg_name_xhtml[@seg_name_xhtml_tracker]} - + #{@md.html_title} + + + #{@css.xhtml_epub} + + #{@vz.color_body}} + end + def endnote_mark +%{ +
    +} + end + end + class HeadScroll < HeadToc + def initialize(md) + super(md) + end + def toc_owner_details + %{#{@vz.margin_txt_3} +#{@vz.paragraph_font_small} + + Owner Details + + #{$ep[:hsp]*3} + + + +#{@vz.table_close}} + end + end + class FormatTextObject + @vz=SiSU_Viz::Defaults.new + attr_accessor :md,:t_o,:txt,:ocn,:format,:table,:link,:linkname,:paranum,:p_num,:headname,:banner,:url + def initialize(md,t_o) + @md,@t_o=md,t_o + if t_o.is_a?(Hash) + @txt =t_o[:txt] || nil + @ocn =t_o[:ocn] || nil + @ocn_display =t_o[:ocn_display] || nil + @headname =t_o[:headname] || nil + @trailer =t_o[:trailer] || nil + @endnote_part_a =t_o[:endnote_part_a] || nil + @endnote_part_b =t_o[:endnote_part_b] || nil + @lnk_url =t_o[:lnk_url] || nil + @lnk_txt =t_o[:lnk_txt] || nil + @format =t_o[:format] || nil + @target =t_o[:target] || nil #occasionally passed but not used + if @format and not @format.empty? + if @format=~/^\d:(\S+)/ #need more reliable marker #if @format =~ /#{Rx[:lv]}/ + headname=$1 #format[/\d~(\S+)/m,1] + @headname=(headname =~/^[a-zA-Z]/) \ + ? %{} + : %{} + @headname=(headname =~/^[a-zA-Z]/) \ + ? %{} + : %{} + end + end + elsif t_o.class.inspect =~/Object/ + @dob=t_o if defined? t_o.is + @named=nametags_seg(@dob) + @txt=((defined? t_o.obj) ? t_o.obj : nil) + @ocn=((defined? t_o.ocn) ? t_o.ocn.to_s : nil) + @headname=((t_o.is==:heading and defined? t_o.name) ? t_o.name : nil) + else + if @md.opt.act[:maintenance][:set]==:on + p __FILE__ << ':' << __LINE__.to_s + p t_o.class + p caller + end + end + if @txt and not @txt.empty? + @txt=@txt.gsub(/#{Mx[:mk_o]}[-~]##{Mx[:mk_c]}/,'') + end + @p_num=ParagraphNumber.new(@md,@ocn) + @vz=SiSU_Viz::Defaults.new + end + def nametags_seg(dob) #FIX + tags='' + if defined? dob.tags \ + and dob.tags.length > 0 # insert tags "hypertargets" + dob.tags.each do |t| + tags=tags << %{} + end + end + tags + end + def endnote_body + %{ +

    + #{@txt} +

    +} + end + def endnote_body_indent + %{ +

    + #{@txt} +

    +} + end + def no_paranum + %{ +
    + +

    + #{@txt} +

    +
    +} + end + def para_form_css(tag,attrib,txt) # regular paragraphs shaped here + ul=ulc='' + ul,ulc="
      \n ","\n
    " if @tag =~/li/ + %{ +
    + #{@p_num.ocn_display} + #{ul}<#{tag} class="#{attrib}" #{@p_num.id}> + #{@named}#{txt} + #{ulc} +
    +} + end + def para + para_form_css('p','norm',@txt) + end + def group + para_form_css('p','group',@txt) + end + def block + para_form_css('p','block',@txt) + end + def alt + para_form_css('p','alt',@txt) + end + def verse + para_form_css('p','verse',@txt) + end + def code + para_form_css('p','code',@txt) + end + def center + para_form_css('p','center',@txt) + end + def bold + para_form_css('p','bold',@txt) + end + def bullet + para_form_css('li','bullet',@txt) + end + def table + @txt=if @t_o.obj !~/^
    '). + gsub(/#{Mx[:br_obj]}/,'

    ') + para_form_css('p','norm',@txt) + end + def format(tag,attrib) + para_form_css(tag,attrib,@txt) + end + def title_heading(tag,attrib) + %{ +
    +<#{tag} class="#{attrib}"> + #{@named}#{@txt} + +
    +} + end + def title_heading1 + DISABLE[:epub][:per_section_title] \ + ? '' + : title_heading('h1','tiny') + end + def title_heading2 + DISABLE[:epub][:per_section_title] \ + ? '' + : title_heading('h2','tiny') + end + def title_heading3 + DISABLE[:epub][:per_section_title] \ + ? '' + : title_heading('h3','tiny') + end + def title_heading4 + '' + end + def seg_heading_sub(tag,attrib,txt) + txt=txt.gsub(/(?:#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]})\s*/m,' ') + %{ +
    + #{@p_num.ocn_display} + <#{tag} class="#{attrib}" #{@p_num.id}>#{@p_num.name} + #{@named}#{@txt} + +
    +} + end + def seg_heading4 + %{ +
    + #{@p_num.ocn_display} +

    + #{@txt} +

    +
    +} + end + def seg_heading5 + seg_heading_sub('p','bold',@txt) + end + def seg_heading6 + seg_heading_sub('p','bold',@txt) + end + def dl #check :trailer + "
    #{@txt} #{@trailer}
    " + end + def table_css_end + '
    +

    + ' + end + def gsub_body #unused + @txt=case @txt + when /^(?:#{Mx[:pa_o]}i[1-9]#{Mx[:pa_c]}\s*)?\((i+|iv|v|vi+|ix|x|xi+)\)/ + @txt.gsub(/^\((i+|iv|v|vi+|ix|x|xi+)\)/,'(\1)'). + gsub(/^(#{Mx[:pa_o]}i[1-9]#{Mx[:pa_c]})\s*\((i+|iv|v|vi+|ix|x|xi+)\)/,'\1(\2)') + when /^(?:#{Mx[:pa_o]}i[1-9]#{Mx[:pa_c]}\s*)?\(?(\d|[a-z])+\)/ + @txt.gsub(/^\((\d+|[a-z])+\)/,'(\1)'). + gsub(/^(#{Mx[:pa_o]}i[1-9]#{Mx[:pa_c]})\s*\((\d+|[a-z])+\)/,'\1(\2)') + when /^\s*\d{1,3}\.\s/ + @txt.gsub(/^\s*(\d+\.)/,'\1') + when /^\s*[A-Z]\.\s/ + @txt.gsub(/^\s*([A-Z]\.)/,'\1') + else @txt + end + end + def bold_para + %{#{@vz.margin_txt_0} +

    + #{@txt} +

    +#{@vz.margin_num_css} + #{$ep[:hsp]*3} +#{@vz.table_close}} + end + def bold_heading #unused + @txt=@txt.gsub(/[1-9]~\S+/,''). + gsub(/[1-9]~/,'') + %{

    + #{@txt} +

    +#{@vz.margin_num_css} + #{$ep[:hsp]*3} +#{@vz.table_close}} + end + def toc_head_copy_at + @txt=SanitizeXML.xml(@txt) + %{

    #{@txt}

    \n} + end + def center + @txt=SanitizeXML.xml(@txt) + %{

    #{@txt}

    \n} + end + def bold + @txt=SanitizeXML.xml(@txt) + %{

    #{@txt}

    \n} + end + def center_bold + @txt=SanitizeXML.xml(@txt) + %{

    #{@txt}

    \n} + end + end + class FormatScroll < FormatTextObject + def initialize(md,txt) + super(md,txt) + @vz=SiSU_Viz::Defaults.new + end + end + class FormatSeg < FormatTextObject + def initialize(md,txt) + super(md,txt) + end + def endnote_seg_body(fn='') #FIX #url construction keep within single line... BUG WATCH 200408 + fn='doc' if fn.to_s.empty? #you may wish to reconsider, sends to 'doc' where no segment info + %{ +

    + #{@endnote_part_a}#{fn}#{Sfx[:epub_xhtml]}#{@endnote_part_b} +

    +} + end + def clean(txt) + txt=txt.gsub(/#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}/,''). + gsub(/#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]}/,'') + end + def subtoc_lev(tag,attrib) + @txt=clean(@txt) + txt=if @txt \ + and @txt =~/<\/?i>|/mi + @txt.gsub(/<\/?i>|/mi,'') #removes name markers from subtoc, go directly to substantive text + else @txt + end + note='' + if txt =~/(#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]})/m # had \s* at end + note=$1 + note=note.gsub(/[\n\s]+/m,' ') + txt=txt.gsub(/(?:#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]})\s*/m,' '). + gsub(/#{$ep[:hsp]}\d+<\/sup>#{$ep[:hsp]}/m,''). + gsub(/#{$ep[:hsp]}\d+<\/sup>#{$ep[:hsp]}/m,'') #remove + end + %{<#{tag} class="#{attrib}"> + #{txt} #{note} + } + end + def subtoc_lev5 + subtoc_lev('h5','subtoc') if @txt + end + def subtoc_lev6 + subtoc_lev('h6','subtoc') if @txt + end + def heading_sub(tag,attrib,txt) + txt=txt.gsub(/(?:#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]})\s*/m,' ') + %{ +
    + #{@p_num.ocn_display} + <#{tag} class="#{attrib}" #{@p_num.id}> #{@headname} + #{@txt} + +
    +} + end + def heading4 + %{ +
    + #{@p_num.ocn_display} +

    + #{@t_o[:format]} + #{@txt} +

    +
    +} + end + def heading5 + heading_sub('p','bold',@txt) + end + def heading6 + heading_sub('p','bold',@txt) + end + def navigation_heading4 + %{ +
    +

    + #{@txt} +

    +#{@vz.table_close}} + end + def navigation_heading5 + %{

    + #{@txt} +

    } + end + def navigation_heading6 + %{

    + #{@txt} +

    } + end + def navigation_center + %{

    #{@txt}

    } + end + end + class FormatToc < FormatTextObject + def initialize(md,txt) + super(md,txt) + end + def links_guide + %{
  • + + #{@lnk_txt} + +
  • +} + end + def lev(tag,attrib) + if @txt + %{<#{tag} class="#{attrib}"> + #{@txt} + +} + else '' + end + end + def lev1 + lev('h1','toc') + end + def lev2 + lev('h2','toc') + end + def lev3 + lev('h3','toc') + end + def lev4 + lev('h4','toc') + end + def lev5 + lev('h5','toc') + end + def lev6 + lev('h6','toc') + end + def lev0 #docinfo + lev('h0','toc') + end + end +end +__END__ diff --git a/lib/sisu/v5/xhtml_epub2_segments.rb b/lib/sisu/v5/xhtml_epub2_segments.rb new file mode 100644 index 00000000..d16e98e8 --- /dev/null +++ b/lib/sisu/v5/xhtml_epub2_segments.rb @@ -0,0 +1,543 @@ +# 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: epub segment generation, processing + +=end +module SiSU_XHTML_EPUB2_Seg + require_relative 'xhtml_shared' # xhtml_shared.rb + require_relative 'xhtml_epub2' # xhtml_epub2.rb + require_relative 'shared_metadata' # shared_metadata.rb + class Output + def initialize(md,outputfile,seg,type='') + @md,@output_epub_cont_seg,@seg,@type=md,outputfile,seg,type + end + def output #CONSIDER + if @seg[:title] =~/\S/ + filename_seg=[] + filename_seg << @seg[:title] << @seg[:nav] + if @type=='endnotes' + @seg[:headings]=[] #watch + txt_obj={ txt: 'Endnotes', ocn_display: ''} + format_seg=SiSU_XHTML_EPUB2_Format::FormatSeg.new(@md,txt_obj) + @seg[:headings] << format_seg.title_heading1 + filename_seg << @seg[:heading_endnotes] << @seg[:headings] << %{\n
    \n} << @seg[:endnote_all] << '
    ' + elsif @type=='idx' + @seg[:headings]=[] + format_seg=SiSU_XHTML_EPUB2_Format::FormatSeg.new(@md,txt_obj) + @seg[:headings] << format_seg.title_heading1 + filename_seg << @seg[:heading_idx] << @seg[:headings] << %{\n
    \n} << @seg[:idx] << '
    ' + elsif @type=='metadata' + metadata=SiSU_Metadata::Summary.new(@md).xhtml_display.metadata + @seg[:headings]=[] + txt_obj={ txt: 'Metadata', ocn_display: ''} + format_seg=SiSU_XHTML_EPUB2_Format::FormatSeg.new(@md,txt_obj) + @seg[:headings] << format_seg.title_heading1 + filename_seg << @seg[:heading_idx] << @seg[:headings] << %{\n
    \n} << metadata << '
    ' + elsif @type=='sisu_manifest' + env=SiSU_Env::InfoEnv.new(@md.fns) + path_and_name,url_and_name="#{env.path.output}/#{@md.fnb}/sisu_manifest.html","#{env.url.root}/#{@md.fnb}/sisu_manifest.html" + manifest=if FileTest.file?("#{path_and_name}")==true + <A list of available output types may be available at the following url:

    +

    #{url_and_name}

    +WOK + else '' + end + @seg[:headings]=[] + txt_obj={ txt: 'Manifest', ocn_display: ''} + format_seg=SiSU_XHTML_EPUB2_Format::FormatSeg.new(@md,txt_obj) + @seg[:headings] << format_seg.title_heading1 + filename_seg << @seg[:heading_idx] << @seg[:headings] << %{\n
    \n} << manifest << '
    ' + else + filename_seg << @seg[:headings] << @seg[:main] << "\n\n" + end + filename_seg << @seg[:tail] << @seg[:nav] << @seg[:close] + filename_seg=filename_seg.flatten.compact #watch + filename_seg.each do |str| + unless str =~/\A\s*\Z/ + @output_epub_cont_seg << str.strip + end + end + @output_epub_cont_seg.close + end + end + end + class Seg + @@seg,@@seg_subtoc,@@seg_endnotes,@@seg_ad={},{},{},{} + @@seg_name,@@seg_name_xhtml=[],[] + @@seg_url=@@fn=@@get_hash_to=@@get_hash_fn='' + @@loop_count=@@seg_total=@@tracker=0 + @@is4=@@is3=@@is2=@@is1=0 + @@heading1=@@heading2=@@heading3=@@heading4=0 + @@seg[:headings],@@seg[:main],@@seg[:idx],@@seg[:tail],@@seg_subtoc_array,@@seg_endnotes_array,@@seg[:endnote_all]=Array.new(7){[]} + @@seg[:heading_endnotes]='' + @@tablehead,@@number_of_cols=0,0 + @@fns_previous='' + attr_reader :seg_name_xhtml,:seg_name_xhtml_tracker + def initialize(md='',data='') + @md,@data=md,data + @vz=SiSU_Viz::Defaults.new + @seg_name_xhtml=@@seg_name_xhtml || nil + @seg_name_xhtml_tracker=@@tracker || nil + @make=SiSU_Env::ProcessingSettings.new(@md) if @md + end + def songsheet + begin + data=get_subtoc_endnotes(@data) + data=articles(data) + SiSU_XHTML_EPUB2_Seg::Seg.new.cleanup # (((( added )))) + #### (((( END )))) #### + rescue + SiSU_Errors::Rescued.new($!,$@,@md.opt.cmd,@md.fns).location do + __LINE__.to_s + ':' + __FILE__ + end + ensure + @@seg_name=[] + end + end + protected + def articles(data) + tracking,newfile=0,0 + @@is4=@@is3=@@is2=@@is1=0 + printed_endnote_seg='n' + idx_xhtml=nil + if @md.book_idx + idx_xhtml=SiSU_Particulars::CombinedSingleton.instance.get_idx_xhtml(@md).xhtml_idx + idx_xhtml.each {|x| @@seg[:idx] << x } + @@seg[:heading_idx]='' + end + data.each do |dob| + if (dob.is==:heading \ + || dob.is==:heading_insert) \ + and dob.ln==4 + @@seg_name << dob.name + dob.name + end + end + @@seg_name_xhtml=@@seg_name + @@seg_total=@@seg_name.length + testforartnum=@@seg_name_xhtml + if (@md.opt.act[:verbose][:set]==:on \ + || @md.opt.act[:verbose_plus][:set]==:on \ + || @md.opt.act[:maintenance][:set]==:on) + SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set],@@seg_name.length) + end + SiSU_Particulars::CombinedSingleton.instance.get_map_nametags(@md).nametags_map #p map_nametags + data.each do |dob| + #if defined? dob.obj \ + #and dob.obj =~/href="#{Xx[:segment]}#+\S+?"/ + # ##Consider: remove, reinstate earlier? + # #while dob.obj =~/href="#{Xx[:segment]}#+(\S+?)"/ + # # m=$1 + # # if map_nametags[m][:segname] + # # dob.obj=dob.obj.sub(/href="#{Xx[:segment]}#+(\S+?)"/,%{href="#{map_nametags[m][:segname]}#{Sfx[:html]}#\\1"}) + # # else + # # p "NOT FOUND name_tags: #{m}" + # # dob.obj=dob.obj.sub(/href="#{Xx[:segment]}#+(\S+?)"/,%{href="#\\1"}) # not satisfactory + # # end + # #end + #end + if (dob.is==:heading \ + || dob.is==:heading_insert) \ + and dob.ln==4 + if dob.ocn==0 + @@heading4=dob.obj + else @@heading4=dob.obj + end + @@is4=newfile=1 + end + if (dob.is==:heading \ + || dob.is==:heading_insert) \ + and dob.ln==3 + @@heading3=dob.obj + @@is4,@@is3=0,1 + end + if (dob.is==:heading \ + || dob.is==:heading_insert) \ + and dob.ln==2 + @@heading2=dob.obj + @@is4,@@is3,@@is2=0,0,1 + end + if (dob.is==:heading \ + || dob.is==:heading_insert) \ + and dob.ln==1 + @@heading1=dob.obj + @@is4,@@is3,@@is2,@@is1=0,0,0,1 + end + if (@@is1 && !@@is2 && !@@is3 && !@@is4) + if not (dob.is==:heading \ + || dob.is==:heading_insert) \ + and dob.ln==1 + $_ #; check + end + end + if @@is4==1 + dir_epub_cont="#{@md.env.processing_path.epub}/#{Ep[:d_oebps]}" + if newfile==1 \ + or dob.obj =~/^#{Mx[:br_endnotes]}|^#{Mx[:br_eof]}/ + newfile=0 + if (dob.is==:heading \ + || dob.is==:heading_insert) \ + and dob.ln==4 + if tracking != 0 + SiSU_XHTML_EPUB2_Seg::Seg.new(@md).tail + segfilename="#{dir_epub_cont}/#{@@seg_name_xhtml[tracking-1]}#{Sfx[:epub_xhtml]}" + output_epub_cont_seg=File.new(segfilename,'w') if @@seg_name_xhtml[tracking-1] + if dob.is==:heading \ + or @@seg_name_xhtml[tracking-1] !~/endnotes|book_index|metadata/ + SiSU_XHTML_EPUB2_Seg::Output.new(@md,output_epub_cont_seg,@@seg).output + elsif dob.is==:heading_insert + if @@seg_name_xhtml[tracking-1]=='endnotes' + SiSU_XHTML_EPUB2_Seg::Output.new(@md,output_epub_cont_seg,@@seg,'endnotes').output + elsif @@seg_name_xhtml[tracking-1]=='book_index' + SiSU_XHTML_EPUB2_Seg::Output.new(@md,output_epub_cont_seg,@@seg,'idx').output + @@seg[:idx]=[] + elsif @@seg_name_xhtml[tracking-1]=='metadata' # navigation bug FIX + SiSU_XHTML_EPUB2_Seg::Output.new(@md,output_epub_cont_seg,@@seg,'metadata').output + else puts "#{__FILE__}::#{__LINE__}" + end + else puts "#{__FILE__}::#{__LINE__}" + end + SiSU_XHTML_EPUB2_Seg::Seg.new.reinitialise + heading_art(dob) + head(dob) + if @@seg_name_xhtml[tracking] =='metadata' + segfilename="#{dir_epub_cont}/#{@@seg_name_xhtml[tracking]}#{Sfx[:epub_xhtml]}" + output_epub_cont_seg=File.new(segfilename,'w') + SiSU_XHTML_EPUB2_Seg::Output.new(@md,output_epub_cont_seg,@@seg,'metadata').output + SiSU_XHTML_EPUB2_Seg::Seg.new.reinitialise #BUG navigation bug with items following metadata, and occurring before manifest, this becomes a bug ... work area for book index, FIX + end + #@output_epub_cont_seg.close #%(((( EOF )))) --> + end + if tracking==0 + heading_art(dob) + head(dob) + end + end + tracking=tracking+1 + end + if (dob.is==:heading \ + || dob.is==:heading_insert) \ + and dob.ln==4 \ + and dob.name + @@get_hash_to=dob.name + @@get_hash_fn=dob.name + end + if dob.obj.is_a?(String) + markup(dob) + elsif dob.obj.is_a?(Array) + dob.obj.each do |pg| + markup(pg) + end + end + if testforartnum[tracking-1] =~/endnote/ + if printed_endnote_seg=='n' + printed_endnote_seg='y' + end + end + end + end + data + end + def heading_art(dob) + @@seg[:title]=SiSU_XHTML_EPUB2_Format::HeadSeg.new(@md).head + end + def head(dob) + clean=/|<:.*?>$/ + @p_num ||= '' + if @@is1==1 + if defined? @md.creator.author \ + and @md.creator.author + @author=%{#{@md.creator.author}\n} + end + ocn=(@@heading1[/.+?#{Mx[:id_o]}~(\d+);(?:[oh]|[0-6]:)\d+;\w\d+#{Mx[:id_c]}#{Mx[:id_o]}#{@dp}:#{@dp}#{Mx[:id_c]}$/]) \ + ? $1 + : '' + @p_num=SiSU_XHTML_EPUB2_Format::ParagraphNumber.new(@md,ocn) + txt_obj={ txt: @@heading1, ocn_display: @p_num.ocn_display } + format_seg=SiSU_XHTML_EPUB2_Format::FormatSeg.new(@md,txt_obj) + @@seg[:headings] << format_seg.title_heading1.gsub(clean,'') + @@heading1=@@heading1.gsub(/#{$ep[:hsp]}#{$ep[:hsp]}[\d*+]+<\/sup>#{$ep[:hsp]}<\/a>/,'') + end + if @@is2==1 + heading2=@@heading2 + ocn=(heading2[/.+?#{Mx[:id_o]}~(\d+);(?:[oh]|[0-6]:)\d+;\w\d+#{Mx[:id_c]}#{Mx[:id_o]}#{@dp}:#{@dp}#{Mx[:id_c]}$/]) \ + ? $1 + : '' + @p_num=SiSU_XHTML_EPUB2_Format::ParagraphNumber.new(@md,ocn) + txt_obj={ txt: heading2, ocn_display: @p_num.ocn_display } + format_seg=SiSU_XHTML_EPUB2_Format::FormatSeg.new(@md,txt_obj) + @@seg[:headings] << format_seg.title_heading2.gsub(clean,'') + @@heading2=@@heading2.gsub(/#{$ep[:hsp]}#{$ep[:hsp]}[\d*+]+<\/sup>#{$ep[:hsp]}<\/a>/,'') + end + if @@is3==1 + heading3=@@heading3 + ocn=(heading3[/.+?#{Mx[:id_o]}~(\d+);(?:[oh]|[0-6]:)\d+;\w\d+#{Mx[:id_c]}#{Mx[:id_o]}#{@dp}:#{@dp}#{Mx[:id_c]}$/]) \ + ? $1 + : '' + @p_num=SiSU_XHTML_EPUB2_Format::ParagraphNumber.new(@md,ocn) + txt_obj={ txt: heading3, ocn_display: @p_num.ocn_display } + format_seg=SiSU_XHTML_EPUB2_Format::FormatSeg.new(@md,txt_obj) + @@seg[:headings] << format_seg.title_heading3.gsub(clean,'') + @@heading3=@@heading3.gsub(/#{$ep[:hsp]}#{$ep[:hsp]}[\d*+]+<\/sup>#{$ep[:hsp]}<\/a>/,'') + end + if @@is4==1 + heading4=@@heading4 + ocn=(heading4[/.+?#{Mx[:id_o]}~(\d+);(?:[oh]|[0-6]:)\d+;\w\d+#{Mx[:id_c]}#{Mx[:id_o]}#{@dp}:#{@dp}#{Mx[:id_c]}$/]) \ + ? $1 + : '' + @p_num=SiSU_XHTML_EPUB2_Format::ParagraphNumber.new(@md,ocn) + txt_obj={ txt: heading4, ocn_display: @p_num.ocn_display } + format_seg=SiSU_XHTML_EPUB2_Format::FormatSeg.new(@md,txt_obj) + @@seg[:headings] << format_seg.title_heading4.gsub(clean,'') + end + @@tracker=@@tracker+1 + end + def markup(dob) + @debug=[] + if dob.is ==:heading \ + || dob.is ==:heading_insert \ + || dob.is ==:para + #extend as necessary FIX + @p_num=SiSU_XHTML_EPUB2_Format::ParagraphNumber.new(@md,dob.ocn) + end + sto=SiSU_XHTML_EPUB2_Format::FormatTextObject.new(@md,dob) + dob_xhtml=if dob.is==:heading \ + || dob.is==:heading_insert \ + || dob.is==:para + dob_xhtml=if dob.is==:heading \ + or dob.is==:heading_insert + if dob.ln==4 + sto.seg_heading4 # work on see SplitTextObject + elsif dob.ln==5 + sto.seg_heading5 + elsif dob.ln==6 + sto.seg_heading6 + end + elsif dob.is==:para + if dob.indent \ + and dob.hang \ + and dob.indent =~/[0-9]/ \ + and dob.hang =~/[0-9]/ + if dob.bullet_ + (dob.indent =~/[1-9]/) \ + ? sto.format('li',"i#{dob.indent}") + : sto.format('li','bullet') + elsif dob.indent == dob.hang + sto.format('p',"i#{dob.indent}") + elsif dob.indent != dob.hang + sto.format('p',"h#{dob.hang}i#{dob.indent}") + else sto.para + end + else sto.para + end + end + elsif dob.is ==:block \ + || dob.is ==:group \ + || dob.is ==:alt + sto.para #fix this should be block type specific #FIX + elsif dob.is==:verse + sto.verse + elsif dob.is==:code + sto.code + elsif dob.is==:table + sto.table + elsif dob.is==:break + sto.break + end + if @md.flag_separate_endnotes # may need to revisit, check + dob.obj=dob.obj.gsub(/"\s+href="#note_ref(\d+)">/,%{" href=\"endnotes#{Sfx[:epub_xhtml]}#note_ref\\1">}) #endnote- twice #removed file type + end + if (dob.is ==:heading \ + || dob.is==:heading_insert \ + || dob.is==:para) \ + && (not dob.ocn or dob.ocn.to_s.empty?) + format_seg=SiSU_XHTML_EPUB2_Format::FormatSeg.new(@md,dob) + end + if (dob.is==:heading \ + || dob.is==:heading_insert \ + || dob.is==:para) \ + and dob.note_ #dob.obj =~/ \n} + @@seg[:main] << dob_xhtml + if @make.build.segsubtoc? + @@seg[:main] << @@seg_subtoc[@@get_hash_fn] #% insertion of sub-toc + end + else + @@seg[:main] << dob_xhtml + end + end + def tail + format_head_seg=SiSU_XHTML_EPUB2_Format::HeadSeg.new(@md) + if @md.flag_auto_endnotes \ + and @@seg_endnotes[@@get_hash_fn] + @@seg[:tail] << %{\n
    \n
    \n} + if @@seg_endnotes[@@get_hash_fn].flatten.length > 0 + @@seg[:tail] << format_head_seg.endnote_mark + @@seg[:tail] << @@seg_endnotes[@@get_hash_fn].flatten #endnotes deposited at end of individual segments ||@|EXTRACTION OF ENDNOTES| + end + @@seg[:tail] << '
    ' + @@seg[:tail] << '
    ' #this div closes div class content + end + @@seg[:close]=[] + @@seg[:close] << format_head_seg.xhtml_close + end + def reinitialise + @@seg[:headings],@@seg[:main],@@seg[:tail],@@seg[:credits]=Array.new(4){[]} + end + def cleanup + reinitialise + @@seg_total,@@tracker=0,0 + @@seg_endnotes,@@seg_subtoc={},{} + @@seg_endnotes_array,@@seg_subtoc_array=[],[] + @@seg[:endnote_all]=[] + end + def get_subtoc_endnotes(data) #get endnotes & sub-table of contents subtoc + data.each do |dob| + dob.obj=dob.obj.gsub(/
    (.+?)<\/a>/mi,'\1') + if @md.flag_auto_endnotes + if (dob.is==:heading \ + || dob.is==:heading_insert) \ + and dob.ln.to_s =~/^[1234]/ \ + and not @@fn.to_s.empty? + @@seg_endnotes[@@fn]=[] + @@seg_endnotes[@@fn] << @@seg_endnotes_array + @@seg_endnotes_array=[] if dob.ln==4 + @@fns_previous=@md.fns if dob.ln==4 and dob.name =~/^meta/ + end + if (dob.is==:heading \ + || dob.is==:heading_insert) \ + and dob.ln==4 #% EXTRACTION OF SUB-TOCs & SEGMENT NAME, after EXTRACTION OF ENDNOTES & SUB-TOCs + @@seg_subtoc[@@fn]=@@seg_subtoc_array + @@seg_subtoc_array=[] + if dob.name \ + and dob.obj + @@fn=dob.name + else + @@fn=(dob.name =~/\S+/) \ + ? dob.name + : '' + end + end + end + if dob.is==:heading \ + and dob.ln.to_s =~/^[56]/ + case dob.ln + when 5 + format_seg=SiSU_XHTML_EPUB2_Format::FormatSeg.new(@md,dob) + subtoc=format_seg.subtoc_lev5 #keep and make available, this is the subtoc + when 6 + format_seg=SiSU_XHTML_EPUB2_Format::FormatSeg.new(@md,dob) + subtoc=format_seg.subtoc_lev6 #keep and make available, this is the subtoc + end + @@seg_subtoc_array << subtoc + end + if @md.flag_auto_endnotes + ast,pls='*','+' + if dob.obj =~/(?:#{Mx[:en_a_o]}|#{Mx[:en_b_o]})(?:\d|#{ast}|#{pls})+ / \ + and dob.is !=:code # endnote- + endnote_array=[] + if dob.obj=~/#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}/m + endnote_array << dob.obj.scan(/#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}/m) + end + if dob.obj=~/#{Mx[:en_b_o]}#{ast}\d+\s.+?#{Mx[:en_b_c]}/m + endnote_array << dob.obj.scan(/#{Mx[:en_b_o]}#{ast}\d+\s.+?#{Mx[:en_b_c]}/m) + end + if dob.obj=~/#{Mx[:en_b_o]}#{pls}\d+\s.+?#{Mx[:en_b_c]}/m + endnote_array << dob.obj.scan(/#{Mx[:en_b_o]}#{pls}\d+\s.+?#{Mx[:en_b_c]}/m) + end + endnote_array=endnote_array.flatten #.compact #check compacting + endnote_array.each do |note| + note_match=note.dup + note_match_seg=note.dup + e_n=note_match_seg[/(?:#{Mx[:en_a_o]}(?:\d|#{ast}|#{pls})+|#{Mx[:en_b_o]}(?:#{ast}|#{pls})\d+)\s+(.+?)(?:#{Mx[:en_a_c]}|#{Mx[:en_b_c]})/m,1] + try=e_n.split(/
    /) + try.each do |e| + txt_obj={ txt: e } + format_seg=SiSU_XHTML_EPUB2_Format::FormatSeg.new(@md,txt_obj) + note_match=if e =~/#{Mx[:pa_o]}i[1-9]#{Mx[:pa_c]}/ + format_seg.endnote_body_indent + else format_seg.endnote_body + end + @@seg_endnotes_array << note_match + end + try.join('
    ') + #% creation of separate end segment/page of all endnotes referenced back to reference segment + m=/(?:#{Mx[:en_a_o]}(?:\d|#{ast}|#{pls})+|#{Mx[:en_b_o]}(?:#{ast}|#{pls})\d+)\s+(.+?href=")(#note_ref(?:\d|_a|_b)+".+)(?:#{Mx[:en_a_c]}|#{Mx[:en_b_c]})/mi + endnote_part_a=note_match_seg[m,1] + endnote_part_b=note_match_seg[m,2] + txt_obj={ endnote_part_a: endnote_part_a, endnote_part_b: endnote_part_b } + format_seg=SiSU_XHTML_EPUB2_Format::FormatSeg.new(@md,txt_obj) + note_match_all_seg=format_seg.endnote_seg_body(@@fn) #BUG WATCH 200408 + @@seg[:endnote_all] << note_match_all_seg + end + dob.obj=dob.obj.gsub(/(?:#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]})\s*/m,' ') + end + end + end + end + end +end +__END__ diff --git a/lib/sisu/v5/xhtml_epub2_tune.rb b/lib/sisu/v5/xhtml_epub2_tune.rb new file mode 100644 index 00000000..b46f49f0 --- /dev/null +++ b/lib/sisu/v5/xhtml_epub2_tune.rb @@ -0,0 +1,333 @@ +# 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: epub generation, epub pre-processing + +=end +require_relative 'param' +module SiSU_XHTML_EPUB2_Tune + require_relative 'sysenv' # sysenv.rb + include SiSU_Env; include SiSU_Screen + require_relative 'xhtml_epub2_format' # xhtml_epub2_format.rb #watch + @@line_mode='' + @@endnote_array=[] + @@endnote_call_counter=1 + @@table_align=' + + +
    + \;' + @@table_align_close=' + +   
    ' + @@counter,@@column,@columns=0,0,0 + class Output + def initialize(data,md) + @data,@md=data,md + @file=SiSU_Env::FileOp.new(@md) + @cX=SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set]).cX + end + def hard_output + @filename_tune=@file.write_file_processing.html_tune + data=[] + @data.each {|x| x.obj.strip; data << x if not x.obj.empty?} #1.9 array? + data.each do |dob| + @filename_tune.puts dob, "\n" #check + end + end + def marshal + File.open(@file.marshal.html_tune,'w') {|f| Marshal.dump(@data.to_a,f)} + end + end + class CleanXHTML + def initialize(html='') + @html=html + end + def clean + html=@html + str=if html.is_a?(String) + html + else html.obj + end + str=str.gsub(/#{Mx[:gl_o]}(#[0-9]{3})#{Mx[:gl_c]}/u,'&\1;'). + gsub(/#{Mx[:gl_o]}#([a-z]{2,4})#{Mx[:gl_c]}/u,'&\1;'). + gsub(/
    /u,'
    '). + gsub(/#{Mx[:nbsp]}/u,$ep[:hsp]) + end + end + class Tune + def initialize(data,md) + @data,@md=data,md + @vz=SiSU_Viz::Defaults.new + @env=SiSU_Env::InfoEnv.new(@md.fns) + @sys=SiSU_Env::SystemCall.new + @env=SiSU_Env::InfoEnv.new(@md.fns) + @brace_url=SiSU_Viz::Defaults.new.url_decoration + end + def songsheet + begin + @cX=SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set]).cX + if (@md.opt.act[:verbose][:set]==:on \ + || @md.opt.act[:verbose_plus][:set]==:on \ + || @md.opt.act[:maintenance][:set]==:on) + SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set],'Tune').txt_grey + end + data=SiSU_XHTML_EPUB2_Tune::Tune.new(@data,@md).amp_angle_brackets + data=SiSU_XHTML_EPUB2_Tune::Tune.new(data,@md).endnotes_html + data=SiSU_XHTML_EPUB2_Tune::Tune.new(data,@md).url_markup + data=SiSU_XHTML_EPUB2_Tune::Tune.new(data,@md).markup + if @md.opt.act[:maintenance][:set]==:on #Hard Output Tune Optional on/off here + data=SiSU_XHTML_EPUB2_Tune::Output.new(data,@md).hard_output + SiSU_XHTML_EPUB2_Tune::Output.new(data,@md).marshal + end + SiSU_XHTML_EPUB2_Tune::Tune.new(@data,@md).output + rescue + SiSU_Errors::Rescued.new($!,$@,@md.opt.cmd,@md.fns).location do + __LINE__.to_s + ':' + __FILE__ + end + ensure + end + end + def markup + @tuned_file=[] + @data.each do |dob| + dob.obj=dob.obj.gsub(/#{Mx[:mk_o]}#([a-zA-Z]+)#{Mx[:mk_c]}/,'&\1;'). + gsub(/#{Mx[:mk_o]}(#[0-9]+)#{Mx[:mk_c]}/,'&\1;') + dob.obj=dob.obj.gsub(/#{Mx[:br_line]}|#{Mx[:br_nl]}/,'
    ') unless dob.is==:table + dob.obj=dob.obj.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_insert_o]}(.+?)#{Mx[:fa_insert_c]}/,'\1'). + gsub(/#{Mx[:fa_cite_o]}(.+?)#{Mx[:fa_cite_c]}/,'\1'). + gsub(/#{Mx[:fa_strike_o]}(.+?)#{Mx[:fa_strike_c]}/,'\1'). + gsub(/#{Mx[:fa_monospace_o]}(.+?)#{Mx[:fa_monospace_c]}/,'\1'). # tt, kbd + gsub(/#{Mx[:mk_o]}:name#(\S+?)#{Mx[:mk_c]}/,''). + gsub(/#{Mx[:gl_bullet]}/m,"●#{$ep[:hsp]*2}"). + gsub(/#{Dx[:url_o]}/,Dx[:url_o_xml]).gsub(/#{Dx[:url_c]}/,Dx[:url_o_xml]). + gsub(/#{Mx[:nbsp]}/,$ep[:hsp]). + gsub(/<(p|br)>/,'<\1 />') + dob.obj=SiSU_XHTML_EPUB2_Tune::CleanXHTML.new(dob.obj).clean + @tuned_file << dob + end + end + def urls(data) + @words=[] + map_nametags=SiSU_Particulars::CombinedSingleton.instance.get_map_nametags(@md).nametags_map #p map_nametags + data.each do |word| + @words << if word=~/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}|image)/ + http_=true + if word =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/ + m,u=/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/.match(word).captures + elsif word =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}/ + http_=false + m,u=/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:rel_o]}(\S+?)#{Mx[:rel_c]}/.match(word).captures + elsif word =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}image/ + m,u=/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}(image)/.match(word).captures + end + case m + when /\.png|\.jpg|\.gif|c=|\s\d+x\d+/ + w,h=/\s(\d+)x(\d+)/.match(m).captures if m =~/\s\d+x\d+/ + w=%{width="#{w}"} if w + h=%{height="#{h}"} if h + c=m[/"(.+?)"/m,1] + caption=%{

    #{c}

    } if c + png=m.scan(/\S+/)[0] + image_path=@md.file.output_path.epub.rel_image #image_path=@env.url.images_epub + ins=if u \ + and u.strip !~/^image$/ + %{
    #{caption}} + else %{#{caption}} + end + word=word.gsub(/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|image)/,ins) + else + link=m[/(.+)/m] + png=m.scan(/\S+/)[0].strip + link=link.strip + u=u.sub(/^#*/,'') #make neater + if map_nametags[u] \ + and map_nametags[u][:segname] + u=unless http_ + u=if u=~/^\d+$/ + u.gsub(/^(\d+)$/,"#{map_nametags[u][:segname]}#{Sfx[:xhtml]}#o\\1") if u !~/\// + else + u.gsub(/(\S+)/,"#{map_nametags[u][:segname]}#{Sfx[:xhtml]}#\\1") if u !~/\// + end + else u + end + elsif u =~/^:/ + u=u.gsub(/^:/,"#{@env.url.root}/") + elsif u =~/^\.\.\// + u=u.gsub(/^\.\.\//,"#{@env.url.root}/") + elsif u =~/https?:\/\// + else p "NOT FOUND name_tags: #{u}" + end + ins=%{#{link}} + word=word.gsub(/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/,ins). + gsub(/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}/,ins) + end + word + else word + end + word + end + @words=@words.join(' ') + end + def url_markup + data=@data + @tuned_file=[] + data.each do |dob| + unless dob.is==:code + if dob.obj =~/<::\s+/ #watch + dob.obj=dob.obj.gsub(/<::\s+(\S+?)\s+!>/, + %{\\1}) + end + if dob.obj =~/<:image\s+/ + dob.obj=dob.obj.gsub(/<:image\s+(http\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+>/, + %{}). + gsub(/<:image\s+(http\S+)\s+(\S+)\s+>/, + %{}). + gsub(/<:image\s+(\S+)\s+(\S+)\s+(\S+)\s+>/, + %{}). + gsub(/<:image\s+(\S+)\s+>/, + %{}) + end + if dob.obj =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}|image)/ + @word_mode=dob.obj.scan(/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}|image)[()\[\]]*[,.;:!?'"]{0,2}|(?:#{Mx[:gl_o]}\S+?#{Mx[:gl_c]})+|[^#{Mx[:lnk_o]}#{Mx[:lnk_c]}]+/mu) + words=urls(@word_mode) + dob.obj=dob.obj.gsub(/.+/m,words) + end + dob.obj=dob.obj.gsub(/\\copyright/i,%{©}) + dob.obj=if (dob.obj !~/\<:ad\s+\.\.\//) + dob.obj.gsub(/\<:ad\s+(\S+)?\s+(\S+\.png)\s+(.+)?\;\s+(.+)?\;\s*!\>/, + %{\n
    \\3
    \n}) + else + dob.obj.gsub(/\<:ad\s+(\S+)?\s+(\S+\.png)\s+(.+)?\;\s+(.+)?\;\s*\>/, + %{\n
    \\3
    \n}) + end + dob.obj=dob.obj.gsub(/!pick/,%{stellar}). + gsub(/!new/,%{#{$ep[:hsp]}new}). + gsub(/<:h(.{1,7}?)>/,'\1'). + gsub(/<:to(\d{1,7}?)>/,%{to#{$ep[:hsp]}\{#{$ep[:hsp]}\\1#{$ep[:hsp]}\} }). + 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 + if dob.obj =~/..\/\S+/ \ + and dob.obj !~/(\"..\/\S+?\"|>\s*..\/\S+<)/ + dob.obj=dob.obj.gsub(/(\.\.\/\S+)/,'\1') + end + dob.obj=dob.obj.gsub(//m,'>') + end + @tuned_file << dob + end + end + def amp_angle_brackets + data,data_new=@data,[] + data.each do |dob| + dob.obj=dob.obj. + gsub(/&/u,'&'). + gsub(//u,'>') + data_new << dob + end + data_new + end + def endnotes_html + data=@data + @tuned_file=[] + a,s='_a','_s' + ast,pls='*','+' + data.each do |dob| + unless dob.is ==:code + dob.obj=dob.obj.gsub(/(#{Mx[:en_a_o]}|#{Mx[:en_b_o]})(\d+)\s+(.+?)(#{Mx[:en_a_c]}|#{Mx[:en_b_c]})/, + %{#{Mx[:nbsp]}#{Mx[:nbsp]}\\2#{Mx[:nbsp]} } + #note- endnote- + %{\\1\\2 #{Mx[:nbsp]}\\2. \\3 \\4}). #endnote- note- (careful may have switched) + gsub(/(#{Mx[:en_b_o]})[*](\d+)\s+(.+?)(#{Mx[:en_b_c]})/, + %{#{Mx[:nbsp]}#{Mx[:nbsp]}#{ast}\\2#{Mx[:nbsp]} } + #note- endnote- + %{\\1#{ast}\\2 #{Mx[:nbsp]}#{ast}\\2. \\3 \\4}). #endnote- note- (careful may have switched) + gsub(/(#{Mx[:en_b_o]})[+](\d+)\s+(.+?)(#{Mx[:en_b_c]})/, + %{#{Mx[:nbsp]}#{Mx[:nbsp]}#{pls}\\2#{Mx[:nbsp]} } + #note- endnote- + %{\\1#{pls}\\2 #{Mx[:nbsp]}#{pls}\\2. \\3 \\4}) #endnote- note- (careful may have switched) # double-check there may here be a bug + if dob.obj =~/#{Mx[:en_a_o]}([*+]+)\s+.+?#{Mx[:en_a_c]}/ + m=$1.length.to_i + dob.obj=dob.obj.gsub(/(#{Mx[:en_a_o]})[*]+\s+(.+?)(#{Mx[:en_a_c]})/, + %{#{Mx[:nbsp]}#{Mx[:nbsp]}#{ast*m}#{Mx[:nbsp]} } + #note- endnote- + %{\\1#{ast*m} #{Mx[:nbsp]}#{ast*m} \\2 \\3}). #endnote- note- (careful may have switched) + gsub(/(#{Mx[:en_a_o]})([+]+)\s+(.+?)(#{Mx[:en_a_c]})/, + %{#{Mx[:nbsp]}#{Mx[:nbsp]}#{pls*m}#{Mx[:nbsp]} } + #note- endnote- + %{\\1#{pls*m} #{Mx[:nbsp]}#{pls*m} \\2 \\3}) #endnote- note- (careful may have switched) + end + end + @tuned_file << dob + end + end + def output + data=@data + @tuned_file=[] + data.each do |dob| + dob.obj=dob.obj.strip.chomp + @tuned_file << dob + end + @tuned_file << "\n" if (@md.fns =~/\.sst0/) #remove + @tuned_file + end + end +end +__END__ diff --git a/lib/sisu/v5/xhtml_shared.rb b/lib/sisu/v5/xhtml_shared.rb new file mode 100644 index 00000000..27ddba4b --- /dev/null +++ b/lib/sisu/v5/xhtml_shared.rb @@ -0,0 +1,68 @@ +# 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: shared html parts + +=end +module SiSU_XHTML_Shared + require_relative 'defaults' # defaults.rb + require_relative 'xhtml_table' # xhtml_table.rb + class TableXHTML < SiSU_XHTML_Table::TableXHTML + end +end +__END__ diff --git a/lib/sisu/v5/xml_dom.rb b/lib/sisu/v5/xml_dom.rb index 6a2d7505..6f0391f1 100644 --- a/lib/sisu/v5/xml_dom.rb +++ b/lib/sisu/v5/xml_dom.rb @@ -67,7 +67,7 @@ module SiSU_XML_DOM require_relative 'sysenv' # sysenv.rb include SiSU_Env require_relative 'ao' # ao.rb - require_relative 'shared_xml' # shared_xml.rb + require_relative 'xml_shared' # xml_shared.rb include SiSU_XML_Munge require_relative 'xml_format' # xml_format.rb include SiSU_XML_Format @@ -135,9 +135,9 @@ module SiSU_XML_DOM end end class Scroll - require_relative 'shared_txt' # shared_txt.rb + require_relative 'txt_shared' # txt_shared.rb include SiSU_TextUtils - require_relative 'shared_xhtml' # decide use, whether xml rather than xhtml + require_relative 'xhtml_shared' # decide use, whether xml rather than xhtml @@xml={ body: [], open: [], close: [], head: [], sc: [] } def initialize(particulars) @env,@md,@ao_array=particulars.env,particulars.md,particulars.ao_array diff --git a/lib/sisu/v5/xml_fictionbook.rb b/lib/sisu/v5/xml_fictionbook.rb deleted file mode 100644 index 446e12e2..00000000 --- a/lib/sisu/v5/xml_fictionbook.rb +++ /dev/null @@ -1,305 +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: extract and print an XML rendition of document structure to screen - -=end -module SiSU_XML_Fictionbook - require_relative 'dal' # dal.rb - require_relative 'sysenv' # sysenv.rb - include SiSU_Env - require_relative 'shared_txt' # shared_txt.rb - include SiSU_TextUtils - require_relative 'shared_xml' # shared_xml.rb - include SiSU_XML_Munge - include SiSU_Param - class Source - def initialize(opt) - @opt=opt - @sp=' ' - end - def read - begin - @md=SiSU_Param::Parameters.new(@opt).get - @dal_array=SiSU_DAL::Source.new(@opt).get - SiSU_XML_Fictionbook::Source::Scroll.new(@dal_array,@md).songsheet - rescue - SiSU_Errors::Rescued.new($!,$@,@opt.cmd,@opt.fns).location do - __LINE__.to_s + ':' + __FILE__ - end - ensure - end - end - private - class Scroll #{@md.date.available} Initial version

    " - else '' - end - date_modified=if defined? @md.date.modified; "\n

    #{@md.date.modified} Last Modified

    " - else '' - end - head=< - - - - *** - - *** - *** - *** - - #{@md.title.full} - - - yyyy - - - - - - - - #{version[:project]} #{version[:version]} and #{rb_ver} - #{version[:date]} - - 1.0 - #{date_available}#{date_modified} - - - - -WOK - put(head) - end - def extract_endnotes - @endnotes=[] - @data.each do |para| - @endnotes << para.scan(/~\{(.+?)\}~/m) - end - @endnotes=@endnotes.flatten - end - def endnotes - @endnotes.each do |endnote| - endnote=endnote.strip - endnote=@trans.markup_fictionbook(endnote) - endnote="

    #{endnote}

    " - util=SiSU_TextUtils::Wrap.new(endnote,80,10) - endnote=util.line_wrap - put(endnote) - end - end - def tail - tail=< -
    -WOK - put(tail) - end - def markup(para,type='') - para=para.strip - para=@trans.markup_fictionbook(para) - para=if type.empty?; "

    #{para}

    " - else "<#{type}>

    #{para}

    " - end - util=SiSU_TextUtils::Wrap.new(para,80,10) - util.line_wrap - end - def put(line) - @file_fictionbook.puts line - puts line if @md.opt.act[:verbose_plus][:set]==:on - end - def structure_build_tag_close(lev,h) - @sp=' ' - case h[0] - when 1 - put("#{@sp*1}") if (lev <= 1) and h[1] - put("") if (lev==0) - when 2 - put("#{@sp*2}") if (lev <= 2) and h[2] - put("#{@sp*1}") if (lev <= 1) and h[1] - put("") if (lev==0) - when 3 - put("#{@sp*3}") if (lev <= 3) and h[3] - put("#{@sp*2}") if (lev <= 2) and h[2] - put("#{@sp*1}") if (lev <= 1) and h[1] - put("") if (lev==0) - when 4 - put("#{@sp*4}") if (lev <= 4) - put("#{@sp*3}") if (lev <= 3) and h[3] - put("#{@sp*2}") if (lev <= 2) and h[2] - put("#{@sp*1}") if (lev <= 1) and h[1] - put("") if (lev==0) - when 5 - put("#{@sp*5}") if (lev <= 5) - put("#{@sp*4}") if (lev <= 4) - put("#{@sp*3}") if (lev <= 3) and h[3] - put("#{@sp*2}") if (lev <= 2) and h[2] - put("#{@sp*1}") if (lev <= 1) and h[1] - put("") if (lev==0) - when 6 - put("#{@sp*6}") if (lev <= 6) - put("#{@sp*5}") if (lev <= 5) - put("#{@sp*4}") if (lev <= 4) - put("#{@sp*3}") if (lev <= 3) and h[3] - put("#{@sp*2}") if (lev <= 2) and h[2] - put("#{@sp*1}") if (lev <= 1) and h[1] - put("") if (lev==0) - end - end - def structure_build(ds) - @h=[0,false,false,false] - put("<#{@s[0]}>") - ds.each_with_index do |x,i| - @ef=false - case x[:lev] - when /^1/ - structure_build_tag_close(1,@h) - y="#{@sp*1}<#{@s[1]}>\n#{x[:para]}" - @h=[1,true,false,false] - when /^2/ - structure_build_tag_close(2,@h) - y="#{@sp*2}<#{@s[2]}>\n#{x[:para]}" - @h=[2,true,true,false] - when /^0:0/ #endnotes and metadata - structure_build_tag_close(2,@h) - y="#{@sp*2}<#{@s[2]}>\n#{x[:para]}" - @h=[2,true,true,false] - @ef=true if x[:hdr] =~/u0/ - when /^3/ - structure_build_tag_close(3,@h) - y="#{@sp*3}<#{@s[3]}>\n#{x[:para]}" - @h=[3,true,true,true] - when /^4/ - structure_build_tag_close(4,@h) - y="#{@sp*4}<#{@s[4]}>\n#{x[:para]}" - @h[0]=4 - when /^m2/ #metadata - structure_build_tag_close(4,@h) - y="#{@sp*4}<#{@s[4]}>\n#{x[:para]}" - @h[0]=4 - when /^5/ - structure_build_tag_close(5,@h) - y="#{@sp*5}<#{@s[5]}>\n#{x[:para]}" - @h[0]=5 - when /^6/ - structure_build_tag_close(6,@h) - y="#{@sp*6}<#{@s[6]}>\n#{x[:para]}" - @h[0]=6 - else - y=if @md.opt.act[:verbose_plus][:set]==:on; "#{x[:para]}" - else nil - end - end - put(y) if y - endnotes if @ef - end - structure_build_tag_close(0,@h) - end - def structure - data=@data - @ds=[] - c=0 - data.each do |para| - rgx_headers=/#{Mx[:id_o]}~(\d+);((?:\w|[0-6]:)\d+);(\w\d+)#{Mx[:id_c]}/ #fix - if para =~rgx_headers - x=(rgx_headers).match(para) - if x[3] =~/^[hum]\d+/ - @ds[c]={} - @ds[c][:ocn]=x[1] - @ds[c][:lev]=x[2] - @ds[c][:hdr]=x[3] - @ds[c][:para]=markup(para,'title') - else - @ds[c]={} - @ds[c][:para]=markup(para) if @md.opt.act[:verbose_plus][:set]==:on - end - c+=1 - end - end - structure_build(@ds) - @ds - end - end - end -end -__END__ diff --git a/lib/sisu/v5/xml_odf_odt.rb b/lib/sisu/v5/xml_odf_odt.rb new file mode 100644 index 00000000..e7389110 --- /dev/null +++ b/lib/sisu/v5/xml_odf_odt.rb @@ -0,0 +1,820 @@ +# 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_XML_ODF_ODT + require_relative 'particulars' # particulars.rb + include SiSU_Particulars + require_relative 'ao' # ao.rb + require_relative 'sysenv' # sysenv.rb + include SiSU_Env + include SiSU_Viz + 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 + @@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,@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.cmd,@opt.fns).location 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_XML_ODF_ODT_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 + 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) + 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 + 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) + 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) + 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.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}/#{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.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 + 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]}/, + %{#{@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) + 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]}/, + %{#{@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 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]}/, + %{#{@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 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 @env.odt_ocn? + if defined? dob.ocn \ + and dob.ocn.is_a?(Fixnum) + p_num=SiSU_XML_ODF_ODT_Format::ParagraphNumber.new(dob.ocn).set_bookmark_and_display + end + end + end + 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 + @@odf[:toc] << toc(dob,p_num).obj + end + end + elsif dob.is ==:verse + @@odf[:body] << poem(dob,p_num).obj << break_line*2 + elsif dob.is==:group + @@odf[:body] << group(dob,p_num).obj << break_line*2 + elsif dob.is==:block + @@odf[:body] << block(dob,p_num).obj << break_line*2 + elsif dob.is==:code + @@odf[: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..6).each { |x| @cont[x]=@level[x]=false } + (4..6).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.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_XML_ODF_ODT_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.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 + @@odf[:head] << x + end + def publish + content=[] + br_pg=' ' + content << + @@odf[:head] << + @@odf[:toc] << + br_pg << + @@odf[:body] << + @@odf[:book_idx] << + br_pg << + @@odf[:metadata] << + @@odf[:tail] + SiSU_XML_ODF_ODT::Source::Output.new(content,@md,@env).odf + @@odf={ head: [], toc: [], body: [], tail: [], book_idx: [], metadata: [] } + end + end + class Output . + + 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 formatting, default opendocument template + +=end +module SiSU_XML_ODF_ODT_Format + require_relative 'param' # param.rb + include SiSU_Param + include SiSU_Viz + class ParagraphNumber + def initialize(paranum) + @paranum=/(\d+)/m.match(paranum.to_s)[1] + end + def set_ref_and_display + set_ref=@paranum.gsub(/(\d+)/,' ') + disp=@paranum.gsub(/(\d+)/,%{ #{Dx[:ocn_o]}\\1#{Dx[:ocn_c]}}) + { display: disp, set_ref: set_ref } + end + def set_bookmark_and_display + set_ref=@paranum.gsub(/(\d+)/,' ') + disp=@paranum.gsub(/(\d+)/,%{ #{Dx[:ocn_o]}\\1#{Dx[:ocn_c]}}) + { display: disp, set_ref: set_ref } + end + def name + @paranum.gsub(/(\d+)/,'') + end + def goto + @paranum.gsub(/(\d+)/,'') + end + end + class FormatBookIndex + def initialize(idx_str) + @idx_str=idx_str + end + def book_idx_bookmark + map_nametags=SiSU_Particulars::CombinedSingleton.instance.get_map_nametags(@md).nametags_map #p map_nametags + rgx_bookmark=/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:rel_o]}#?\S+?#{Mx[:rel_c]}/m + while @idx_str =~/#{Mx[:lnk_o]}([^#{Mx[:lnk_o]}#{Mx[:lnk_c]}]+)#{Mx[:lnk_c]}#{Mx[:rel_o]}#?(\S+?)#{Mx[:rel_c]}/m + link,url=$1,$2 + link,url=link.strip,url.strip + @idx_str=@idx_str.gsub(/&/m,"&") + ocn_lnk=if map_nametags[url] \ + and map_nametags[url][:ocn] + map_nametags[url][:ocn] + else nil + end + ocn_lnk=(url=~/^\d+$/ ? url : ocn_lnk) + if ocn_lnk and not ocn_lnk.empty? + @idx_str=@idx_str.sub(/#{Mx[:fa_bold_o]}(.+?)#{Mx[:fa_bold_c]}/, + '\1'). + sub(rgx_bookmark, + %{#{link.strip}}) + else + puts %{name tag: "#{url}" not found} + @idx_str.sub!(rgx_bookmark,"#{link}") + end + end + @idx_str=@idx_str.gsub(/#{Xx[:protect]}/m,''). + sub(/,\s*$/m,''). + gsub(/\n/,'') + @idx_str='' + @idx_str + '' + end + end + class Tags + def set_bookmark_tag(dob) + tags='' + if dob.tags.length > 0 + dob.tags.each do |tag| + tags +=%{ } + end + end + tags + end + end + class FormatTextObject + def initialize(md,t_o) + @md,@t_o=md,t_o + if t_o.is_a?(Hash) + @txt =t_o[:txt] || nil + else + p t_o.class + p caller + end + rgx=/#{Mx[:en_a_o]}\d+\s+(.+?)#{Mx[:en_a_c]}/ + @txt=@txt.gsub(rgx,'\1') if @txt =~rgx + @vz=SiSU_Viz::Defaults.new + end + def scr_endnote_body + "#{@txt} " + end + def heading_body1 + end + def heading_body2 + end + def heading_body3 + end + def heading_body4 + end + def heading_body5 + end + def heading_body6 + end + end + class Table + @@tablehead,@@table_counter=0,0 #reinitialise on new file + @@tablefoot=[] #watch + @@fns='' + def initialize(md,dob,p_num) + @md,@dob,@p_num=md,dob,p_num + @txt=dob.obj + @vz=SiSU_Viz::Defaults.new + if @md.fns != @@fns + @@table_counter=0 + @@fns=@md.fns + end + end + def break_line + (@md.opt.act[:maintenance][:set]==:on) \ + ? "\n" : '' + end + def table_head_open(count) + type=(@dob.head_) \ + ? 1 + : 2 + alpha=case @dob.cols + when 1; 'A' + when 2; 'B' + when 3; 'C' + when 4; 'D' + when 5; 'E' + when 6; 'F' + when 7; 'G' + when 8; 'H' + when 9; 'I' + when 10; 'J' + when 11; 'K' + when 12; 'L' + when 13; 'M' + when 14; 'N' + else 'D' + end + tag=SiSU_XML_ODF_ODT_Format::Tags.new.set_bookmark_tag(@dob) + %{#{@p_num[:set_ref]}#{tag}#{break_line}} + + %{#{break_line}} + end + def table_close(tablefoot='') + '' \ + + %{#{@p_num[:display]}} + end + def table_tag_cell(str,i) + txt_name_cell=if i==0 \ + and @dob.head_ + 'Table_Heading' + else 'P_table_cell' + end + str=str.gsub(/^~$/,'') # tilde / empty cell + %{#{break_line}} + + %{#{break_line}} + + %{#{str}} + + %{#{break_line}} + + %{#{break_line}} + end + def table_tag_row(str,i) + %{#{break_line}} + + %{#{str}} + + %{#{break_line}} + end + def table_tag_row_dump(str,i) + txt_name_row=if i==0 \ + and @dob.head_ + 'Table_Heading' + else 'P_table_cell' + end + %{#{break_line}} + + %{#{break_line}} + + %{#{break_line}} + + %{#{str}} + + %{#{break_line}} + + %{#{break_line}} + + %{#{break_line}} + end + def table_row(row,i) + row='' if row =~/^/,1] + @@tablefoot << m if m + row=row.gsub(//,'') + @cells=[] + row.split(/\s*#{Mx[:tc_p]}/).each do |cell| + @cells << table_tag_cell(cell,i) + end + row=@cells.join + row=table_tag_row(row,i) + row + end + def table + @@table_counter+=1 + table_head_open(@@table_counter) + @table=[] + @dob.obj.split(/\s*#{Mx[:tc_c]}/).each_with_index do |r,i| + @table << table_row(r,i) + end + @dob.obj= table_head_open(@@table_counter) + @table.join + table_close + @dob + end + end + class ODT_Head_1_2 + def initialize(md) + @md=md + @generator="#{@md.sisu_version[:project]} #{@md.sisu_version[:version]} #{@md.sisu_version[:date_stamp]} (#{@md.sisu_version[:date]})" + end + def manifest_rdf + x=< + + + + + + + + + + + + + + + + + +WOK + x=x.strip + x=x.gsub(/\n+/m,'') unless @md.opt.act[:maintenance][:set]==:on + x + end + def meta_inf_manifest_xml(md) + images=[' '] + if md.ec[:image].length > 0 + md.ec[:image].each do |i| + images<<< +WOK + end + end + images=images.join('') + x=< + + + + + #{images} + + + + + + + + +WOK + x=x.strip + x=x.gsub(/\n+/m,'') unless @md.opt.act[:maintenance][:set]==:on + x + end + def meta_xml + x=< + + + #{@generator} + #{@md.generated} + #{@md.generated} + en-US + + +WOK + x=x.strip + x=x.gsub(/\n+/m,'') unless @md.opt.act[:maintenance][:set]==:on + x + end + def settings_xml + x=< + + + + 0 + 0 + 0 + 0 + true + false + + + view2 + 0 + 0 + 0 + 0 + 0 + 0 + 0 + 2 + true + 100 + false + + + + + true + false + false + true + true + false + true + false + false + + false + false + false + true + true + 0 + false + false + false + false + true + false + false + false + false + true + true + false + false + true + false + true + false + high-resolution + 1 + 0 + true + + + false + true + + false + true + false + true + false + true + false + + true + true + false + true + true + true + false + false + + false + 0 + false + false + true + true + + + +WOK + x=x.strip + x=x.gsub(/\n+/m,'') unless @md.opt.act[:maintenance][:set]==:on + x + end + def styles_xml + x=< + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +WOK + x=x.strip + x=x.gsub(/\n+/m,'') unless @md.opt.act[:maintenance][:set]==:on + x + end + def mimetype + x=<#{sep*60}
    } + @t_o + end + def obj_sep #center later + sep='--- ' + @t_o.obj=%{#{sep*20}} + @t_o + end + end + class XML + end +end +__END__ diff --git a/lib/sisu/v5/xml_sax.rb b/lib/sisu/v5/xml_sax.rb index a53abdd6..aa701822 100644 --- a/lib/sisu/v5/xml_sax.rb +++ b/lib/sisu/v5/xml_sax.rb @@ -66,7 +66,7 @@ module SiSU_XML_SAX include SiSU_Particulars require_relative 'sysenv' # sysenv.rb include SiSU_Env - require_relative 'shared_xml' # shared_xml.rb + require_relative 'xml_shared' # xml_shared.rb include SiSU_XML_Munge require_relative 'xml_format' # xml_format.rb include SiSU_XML_Format @@ -135,10 +135,10 @@ module SiSU_XML_SAX end end class Scroll - require_relative 'shared_txt' # shared_txt.rb + require_relative 'txt_shared' # txt_shared.rb include SiSU_TextUtils require_relative 'css' # css.rb - require_relative 'shared_xhtml' # decide use, whether xml rather than xhtml + require_relative 'xhtml_shared' # decide use, whether xml rather than xhtml @@xml={ body: [], open: [], close: [], head: [] } def initialize(particulars) @env,@md,@ao_array=particulars.env,particulars.md,particulars.ao_array diff --git a/lib/sisu/v5/xml_shared.rb b/lib/sisu/v5/xml_shared.rb new file mode 100644 index 00000000..caad8be0 --- /dev/null +++ b/lib/sisu/v5/xml_shared.rb @@ -0,0 +1,751 @@ +# 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: common file for xml generation +=end +module SiSU_XML_Munge + class Trans + require_relative 'defaults' # defaults.rb + def initialize(md) + @md=md + @sys=SiSU_Env::SystemCall.new + @dir=SiSU_Env::InfoEnv.new(@md.fns) + @brace_url=SiSU_Viz::Defaults.new.url_decoration + if @md.sem_tag + @ab ||=semantic_tags.default + end + end + def semantic_tags + def default + { + pub: 'publication', + conv: 'convention', + vol: 'volume', + pg: 'page', + cty: 'city', + org: 'organization', + uni: 'university', + dept: 'department', + fac: 'faculty', + inst: 'institute', + co: 'company', + com: 'company', + conv: 'convention', + dt: 'date', + y: 'year', + m: 'month', + d: 'day', + ti: 'title', + au: 'author', + ed: 'editor', #editor? + v: 'version', #edition + n: 'name', + fn: 'firstname', + mn: 'middlename', + ln: 'lastname', + in: 'initials', + qt: 'quote', + ct: 'cite', + ref: 'reference', + ab: 'abreviation', + def: 'define', + desc: 'description', + trans: 'translate', + } + end + self + end + def char_enc #character encode + def utf8(dob='') + if @sys.locale =~/utf-?8/i # instead ucs for utf8 # String#encode Iñtërnâtiônàlizætiøn + str=if defined? dob.obj then dob.obj + elsif dob.is_a?(String) then dob + end + if str + #¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûü + #¢£¥§©ª«®°±²³µ¶¹º»¼½¾×÷ + str=str.gsub(//um,'>'). # '>' # > + gsub(/¢/um,'¢'). # '¢' # ¢ + gsub(/£/um,'£'). # '£' # £ + gsub(/¥/um,'¥'). # '¥' # ¥ + gsub(/§/um,'§'). # '§' # § + gsub(/©/um,'©'). # '©' # © + gsub(/ª/um,'ª'). # 'ª' # ª + gsub(/«/um,'«'). # '«' # « + gsub(/®/um,'®'). # '®' # ® + gsub(/°/um,'°'). # '°' # ° + gsub(/±/um,'±'). # '±' # ± + gsub(/²/um,'²'). # '²' # ² + gsub(/³/um,'³'). # '³' # ³ + gsub(/µ/um,'µ'). # 'µ' # µ + gsub(/¶/um,'¶'). # '¶' # ¶ + gsub(/¹/um,'¹'). # '¹' # ¹ + gsub(/º/um,'º'). # 'º' # º + gsub(/»/um,'»'). # '»' # » + gsub(/¼/um,'¼'). # '¼' # ¼ + gsub(/½/um,'½'). # '½' # ½ + gsub(/¾/um,'¾'). # '¾' # ¾ + gsub(/×/um,'×'). # '×' # × + gsub(/÷/um,'÷'). # '÷' # ÷ + gsub(/¿/um,'¿'). # '¿' # ¿ + gsub(/À/um,'À'). # 'À' # À + gsub(/Á/um,'Á'). # 'Á' # Á + gsub(/Â/um,'Â'). # 'Â' #  + gsub(/Ã/um,'Ã'). # 'Ã' # à + gsub(/Ä/um,'Ä'). # 'Ä' # Ä + gsub(/Å/um,'Å'). # 'Å' # Å + gsub(/Æ/um,'Æ'). # 'Æ' # Æ + gsub(/Ç/um,'Ç'). # 'Ç' # Ç + gsub(/È/um,'È'). # 'È' # È + gsub(/É/um,'É'). # 'É' # É + gsub(/Ê/um,'Ê'). # 'Ê' # Ê + gsub(/Ë/um,'Ë'). # 'Ë' # Ë + gsub(/Ì/um,'Ì'). # 'Ì' # Ì + gsub(/Í/um,'Í'). # 'Í' # Í + gsub(/Î/um,'Î'). # 'Î' # Î + gsub(/Ï/um,'Ï'). # 'Ï' # Ï + gsub(/Ð/um,'Ð'). # 'Ð' # Ð + gsub(/Ñ/um,'Ñ'). # 'Ñ' # Ñ + gsub(/Ò/um,'Ò'). # 'Ò' # Ò + gsub(/Ó/um,'Ó'). # 'Ó' # Ó + gsub(/Ô/um,'Ô'). # 'Ô' # Ô + gsub(/Õ/um,'Õ'). # 'Õ' # Õ + gsub(/Ö/um,'Ö'). # 'Ö' # Ö + gsub(/Ø/um,'Ø'). # 'Ø' # Ø + gsub(/Ù/um,'Ù'). # 'Ù' # Ù + gsub(/Ú/um,'Ú'). # 'Ú' # Ú + gsub(/Û/um,'Û'). # 'Û' # Û + gsub(/Ü/um,'Ü'). # 'Ü' # Ü + gsub(/Ý/um,'Ý'). # 'Ý' # Ý + gsub(/Þ/um,'Þ'). # 'Þ' # Þ + gsub(/ß/um,'ß'). # 'ß' # ß + gsub(/à/um,'à'). # 'à' # à + gsub(/á/um,'á'). # 'á' # á + gsub(/â/um,'â'). # 'â' # â + gsub(/ã/um,'ã'). # 'ã' # ã + gsub(/ä/um,'ä'). # 'ä' # ä + gsub(/å/um,'å'). # 'å' # å + gsub(/æ/um,'æ'). # 'æ' # æ + gsub(/ç/um,'ç'). # 'ç' # ç + gsub(/è/um,'è'). # 'è' # è + gsub(/é/um,'é'). # '´' # é + gsub(/ê/um,'ê'). # 'ˆ' # ê + gsub(/ë/um,'ë'). # 'ë' # ë + gsub(/ì/um,'ì'). # 'ì' # ì + gsub(/í/um,'í'). # '´' # í + gsub(/î/um,'î'). # 'î' # î + gsub(/ï/um,'ï'). # 'ï' # ï + gsub(/ð/um,'ð'). # 'ð' # ð + gsub(/ñ/um,'ñ'). # 'ñ' # ñ + gsub(/ò/um,'ò'). # 'ò' # ò + gsub(/ó/um,'ó'). # 'ó' # ó + gsub(/ô/um,'ô'). # 'ô' # ô + gsub(/õ/um,'õ'). # 'õ' # õ + gsub(/ö/um,'ö'). # 'ö' # ö + gsub(/ø/um,'ø'). # 'ø' # ø + gsub(/ù/um,'ú'). # 'ù' # ú + gsub(/ú/um,'û'). # 'ú' # û + gsub(/û/um,'ü'). # 'û' # ü + gsub(/ü/um,'ý'). # 'ü' # ý + gsub(/þ/um,'þ'). # 'þ' # þ + gsub(/ÿ/um,'ÿ'). # 'ÿ' # ÿ + gsub(/‘/um,'‘'). # '‘' # ‘ + gsub(/’/um,'’'). # '’' # ’ + gsub(/“/um,'“'). # “ # “ + gsub(/”/um,'”'). # ” # ” + gsub(/–/um,'–'). # – # – + gsub(/—/um,'—'). # — # — + gsub(/∝/um,'∝'). # ∝ # ∝ + gsub(/∞/um,'∞'). # ∞ # ∞ + gsub(/™/um,'™'). # ™ # ™ + gsub(/✠/um,'✠'). # ✗ # ✠ + gsub(/ /um,' '). # space identify + gsub(/ /um,' ') # space identify + end + dob=if defined? dob.obj + dob.obj=str + dob + elsif dob.is_a?(String) + str + end + dob + end + end + def html(dob='') + if @sys.locale =~/utf-?8/i # instead ucs for utf8 # String#encode Iñtërnâtiônàlizætiøn + dob.obj=dob.obj.gsub(/ /u,' '). # space identify + gsub(/ /u,' ') # space identify + else + dob.obj=dob.obj.gsub(/¢/u,'¢'). # ¢ + gsub(/£/u,'£'). # £ + gsub(/¥/u,'¥'). # ¥ + gsub(/§/u,'§'). # § + gsub(/©/u,'©'). # © + gsub(/ª/u,'ª'). # ª + gsub(/«/u,'«'). # « + gsub(/®/u,'®'). # ® + gsub(/°/u,'°'). # ° + gsub(/±/u,'±'). # ± + gsub(/²/u,'²'). # ² + gsub(/³/u,'³'). # ³ + gsub(/µ/u,'µ'). # µ + gsub(/¶/u,'¶'). # ¶ + gsub(/¹/u,'¹'). # ¹ + gsub(/º/u,'º'). # º + gsub(/»/u,'»'). # » + gsub(/¼/u,'¼'). # ¼ + gsub(/½/u,'½'). # ½ + gsub(/¾/u,'¾'). # ¾ + gsub(/×/u,'×'). # × + gsub(/÷/u,'÷'). # ÷ + gsub(/¿/u,'¿'). # ¿ + gsub(/À/u,'À'). # À + gsub(/Á/u,'Á'). # Á + gsub(/Â/u,'Â'). #  + gsub(/Ã/u,'Ã'). # à + gsub(/Ä/u,'Ä'). # Ä + gsub(/Å/u,'Å'). # Å + gsub(/Æ/u,'Æ'). # Æ + gsub(/Ç/u,'Ç'). # Ç + gsub(/È/u,'È'). # È + gsub(/É/u,'É'). # É + gsub(/Ê/u,'Ê'). # Ê + gsub(/Ë/u,'Ë'). # Ë + gsub(/Ì/u,'Ì'). # Ì + gsub(/Í/u,'Í'). # Í + gsub(/Î/u,'Î'). # Î + gsub(/Ï/u,'Ï'). # Ï + gsub(/Ð/u,'Ð'). # Ð + gsub(/Ñ/u,'Ñ'). # Ñ + gsub(/Ò/u,'Ò'). # Ò + gsub(/Ó/u,'Ó'). # Ó + gsub(/Ô/u,'Ô'). # Ô + gsub(/Õ/u,'Õ'). # Õ + gsub(/Ö/u,'Ö'). # Ö + gsub(/Ø/u,'Ø'). # Ø + gsub(/Ù/u,'Ù'). # Ù + gsub(/Ú/u,'Ú'). # Ú + gsub(/Û/u,'Û'). # Û + gsub(/Ü/u,'Ü'). # Ü + gsub(/Ý/u,'Ý'). # Ý + gsub(/Þ/u,'Þ'). # Þ + gsub(/ß/u,'ß'). # ß + gsub(/à/u,'à'). # à + gsub(/á/u,'á'). # á + gsub(/â/u,'â'). # â + gsub(/ã/u,'ã'). # ã + gsub(/ä/u,'ä'). # ä + gsub(/å/u,'å'). # å + gsub(/æ/u,'æ'). # æ + gsub(/ç/u,'ç'). # ç + gsub(/è/u,'è'). # è + gsub(/é/u,'´'). # é + gsub(/ê/u,'ˆ'). # ê + gsub(/ë/u,'ë'). # ë + gsub(/ì/u,'ì'). # ì + gsub(/í/u,'´'). # í + gsub(/î/u,'î'). # î + gsub(/ï/u,'ï'). # ï + gsub(/ð/u,'ð'). # ð + gsub(/ñ/u,'ñ'). # ñ + gsub(/ò/u,'ò'). # ò + gsub(/ó/u,'ó'). # ó + gsub(/ô/u,'ô'). # ô + gsub(/õ/u,'õ'). # õ + gsub(/ö/u,'ö'). # ö + gsub(/ø/u,'ø'). # ø + gsub(/ù/u,'ù'). # ú + gsub(/ú/u,'ú'). # û + gsub(/û/u,'û'). # ü + gsub(/ü/u,'ü'). # ý + gsub(/þ/u,'þ'). # þ + gsub(/ÿ/u,'ÿ'). # ÿ + gsub(/‘/u,'&#lsquo;'). # ‘ # ‘ + gsub(/’/u,'&#rsquo;'). # ’ # ’ + gsub(/“/u,'“'). # “ # “ + gsub(/”/u,'”'). # ” # ” + gsub(/–/u,'–'). # – # – + gsub(/—/u,'—'). # — # — + gsub(/∝/u,'∝'). # ∝ # ∝ + gsub(/∞/u,'∞'). # ∞ # ∞ + gsub(/™/u,'™'). # ™ # ™ + gsub(/✠/u,'✠'). # ✠ + #gsub(/✠/u '†'). # † # † incorrect replacement † + gsub(/ /u,' '). # space identify + gsub(/ /u,' ') # space identify + end + end + self + end + def tidywords(wordlist) + wordlist_new=[] + wordlist.each do |x| + #imperfect solution will not catch all possible cases + x=x.gsub(/&/,'&') unless x =~/&\S+;/ + x=x.gsub(/&([A-Z])/,'&\1') + wordlist_new << x + end + wordlist_new + end + def markup(dob='') + wordlist=dob.obj.scan(/&[#0-9a-z]+;|\S+|\n/) #\n needed for tables, check though added 2005w17 + dob.obj=tidywords(wordlist).join(' ').strip + unless dob.is==:table + dob.obj=dob.obj.gsub(/#{Mx[:br_line]}/u,'
    '). + gsub(/#{Mx[:br_paragraph]}/u,'
    '). + gsub(/#{Mx[:br_line]}|#{Mx[:br_nl]}/,'
    ') + end + dob.obj=dob.obj.gsub(/#{Mx[:mk_o]}:name#\S+?#{Mx[:mk_c]}/,''). + gsub(/#{Mx[:mk_o]}#([a-zA-Z]+)#{Mx[:mk_c]}/,'&\1;'). + gsub(/#{Mx[:mk_o]}(#[0-9]+)#{Mx[:mk_c]}/,'&\1;'). + gsub(/(^|#{Mx[:gl_c]}|\s+)<\s+/,'\1< ').gsub(/\s+>(\s+|$)/,' >\1'). + #gsub(/#{Mx[:fa_emphasis_o]}(.+?)#{Mx[:fa_emphasis_c]}/,'\1'). #reinstate + gsub(/#{Mx[:fa_bold_o]}(.+?)#{Mx[:fa_bold_c]}/m,'\1'). + gsub(/#{Mx[:fa_italics_o]}(.+?)#{Mx[:fa_italics_c]}/m,'\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_insert_o]}(.+?)#{Mx[:fa_insert_c]}/,'\1'). + gsub(/#{Mx[:fa_cite_o]}(.+?)#{Mx[:fa_cite_c]}/,'\1'). + gsub(/#{Mx[:fa_strike_o]}(.+?)#{Mx[:fa_strike_c]}/,'\1'). + gsub(/#{Mx[:fa_monospace_o]}(.+?)#{Mx[:fa_monospace_c]}/,'\1'). + gsub(/<:pb>\s*/,''). #Fix + gsub(/<+[-~]#>+/,'') + if dob.is !=:code + #embeds a red-bullet image --> + dob.obj=dob.obj.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_strike_o]}(.+?)#{Mx[:fa_strike_c]}/,'\1') + dob.obj=dob.obj.gsub(/#{Mx[:br_line]}|#{Mx[:br_nl]}/,'
    ') unless dob.is==:table + dob.obj=dob.obj.gsub(/#{Mx[:br_page]}\s*/,''). + gsub(/#{Mx[:br_page_new]}\s*/,''). + gsub(/#{Mx[:br_page_line]}\s*/,''). + gsub(/#{Mx[:pa_non_object_no_heading]}|#{Mx[:pa_non_object_dummy_heading]}/,''). + gsub(/<[-~]#>/,''). + gsub(/href="#{Xx[:segment]}/m,'href="'). + gsub(/#{Mx[:lnk_o]}([^#{Mx[:lnk_o]}#{Mx[:lnk_c]}#{Mx[:rel_o]}#{Mx[:rel_c]}]+?)#{Mx[:lnk_c]}#{Mx[:rel_o]}(\.\.\/\S+?)#{Mx[:rel_c]}/, + '\1'). + gsub(/#{Mx[:lnk_o]}([^#{Mx[:lnk_o]}#{Mx[:lnk_c]}#{Mx[:rel_o]}#{Mx[:rel_c]}]+?)#{Mx[:lnk_c]}#{Mx[:rel_o]}:(\S+?)#{Mx[:rel_c]}/, + '\1'). + gsub(/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:rel_o]}(\S+?)#{Mx[:rel_c]}/, + '\1'). + gsub(/(?:^|[^_\\])#{Mx[:lnk_o]}[ ]*(\S+?\.(?:jpg|png|gif))[ ]+(\d+)x(\d+)(\s+[^}]+)?#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/, + %{[\\1] \\4}). + gsub(/(?:^|[^_\\])#{Mx[:lnk_o]}[ ]*(\S+?\.(?:jpg|png|gif))([ ]+[^}]+)?#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/, + %{\\1}). + gsub(/(?:^|[^_\\])#{Mx[:lnk_o]}[ ]*(\S+?\.(?:jpg|png|gif))[ ]+(\d+)x(\d+)(\s+[^}]+)?#{Mx[:lnk_c]}image/, + %{[\\1] \\4}). + gsub(/(?:^|[^_\\])#{Mx[:lnk_o]}[ ]*(\S+?\.(?:jpg|png|gif))([ ]+[^}]+)?#{Mx[:lnk_c]}image/, + %{\\1}). + gsub(/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/, + '\1'). #watch, compare html_tune + gsub(/#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/, + %{#{@brace_url.xml_open}\\1#{@brace_url.xml_close}}). + gsub(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/, + '\1') #escaped urls not linked, deal with later + else + dob.obj=dob.obj.gsub(//m,'>') + end + if dob.of==:block + dob.obj=dob.obj.gsub(/#{Mx[:gl_bullet]}/,'● ') + end + dob.obj=dob.obj.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(/#{Dx[:url_o]}/,"#{Dx[:url_o_xml]}"). + gsub(/#{Dx[:url_c]}/,"#{Dx[:url_c_xml]}"). + gsub(/ |#{Mx[:nbsp]}/m,' ') + dob + end + def markup_light(dob='') + dob.obj=dob.obj.gsub(/\/\{(.+?)\}\//,'\1'). + gsub(/[*!]\{(.+?)\}[*!]/,'\1'). + gsub(/_\{(.+?)\}_/,'\1'). + gsub(/-\{(.+?)\}-/,'\1'). + gsub(//,'
    '). + gsub(/<:pb>\s*/,''). + gsub(/<[-~]#>/,''). + gsub(/(^|#{Mx[:gl_c]}|\s)&\s+/,'\1& '). #sort + gsub(/&([^;]{1,5})/,'&\1'). #sort, rough estimate, revisit #WATCH found in node not sax + gsub(/(?:^|[^_\\])#{Mx[:lnk_o]}(\S+?\.(?:png|jpg|gif))[ ]+.+?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|image)/, + "#{@md.file.output_path.xml.rel_image}\/\\1"). + gsub(/ |#{Mx[:nbsp]}/,' ') + wordlist=dob.obj.scan(/&[#0-9a-z]+;|\S+|\n/) #\n needed for tables, check though added 2005w17 + dob.obj=tidywords(wordlist).join(' ').strip + dob + end + def clean(str) + str=str.gsub(/#{Mx[:gl_o]}(#[0-9]{3})#{Mx[:gl_c]}/u,'&\1;'). + gsub(/#{Mx[:gl_o]}#([a-z]{2,4})#{Mx[:gl_c]}/u,'&\1;') + end + def markup_fictionbook(str='',is='') + str=str.gsub(/#{Mx[:en_a_o]}([\d+*]+).+?#{Mx[:en_a_c]}/m,'
    [\1]'). + gsub(/&/,'&'). #sort + gsub(/#{Mx[:mk_o]}#([a-zA-Z]+)#{Mx[:mk_c]}/,'&\1;'). + gsub(/(^|#{Mx[:gl_c]}|\s)&\s+/,'\1& '). #sort + gsub(/#{Mx[:mk_o]}(#[0-9]+)#{Mx[:mk_c]}/,'&\1;') + str=str.gsub(/#{Mx[:br_line]}|#{Mx[:br_nl]}/,'
    ') unless is==:table + str=str.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_insert_o]}(.+?)#{Mx[:fa_insert_c]}/,'\1'). + gsub(/#{Mx[:fa_cite_o]}(.+?)#{Mx[:fa_cite_c]}/,'\1'). + gsub(/#{Mx[:fa_strike_o]}(.+?)#{Mx[:fa_strike_c]}/,'\1'). + gsub(/#{Mx[:fa_monospace_o]}(.+?)#{Mx[:fa_monospace_c]}/,'\1'). # tt, kbd + gsub(/#{Mx[:lnk_o]}\s*(\S+?\.(?:png|jpg|gif)).+?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}|image)/m,''). + gsub(/#{Mx[:url_o]}(.+?)#{Mx[:url_c]}/,"#{Dx[:url_o]}\\1#{Dx[:url_c]}"). + gsub(/#{Mx[:mk_o]}:name#(\S+?)#{Mx[:mk_c]}/,''). + gsub(/#{Mx[:gl_bullet]}/m,'●  '). + gsub(/#{Mx[:nbsp]}/,' '). + gsub(/<(p|br)>/,'<\1 />') + clean(str) + end + def markup_docbook(dob='') # work on, initially a copy of fictionbook! + dob.obj=dob.obj.gsub(/#{Mx[:en_a_o]}(.+?)#{Mx[:en_a_c]}/m,'\1'). + gsub(/&/,'&'). #sort + gsub(/#{Mx[:mk_o]}#([a-zA-Z]+)#{Mx[:mk_c]}/,'&\1;'). + gsub(/(^|#{Mx[:gl_c]}|\s)&\s+/,'\1& '). #sort + gsub(/#{Mx[:mk_o]}(#[0-9]+)#{Mx[:mk_c]}/,'&\1;') + dob.obj=dob.obj.gsub(/#{Mx[:br_line]}|#{Mx[:br_nl]}/,'
    ') unless dob.is==:table + dob.obj=dob.obj.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_insert_o]}(.+?)#{Mx[:fa_insert_c]}/,'\1'). + gsub(/#{Mx[:fa_cite_o]}(.+?)#{Mx[:fa_cite_c]}/,'\1'). + gsub(/#{Mx[:fa_strike_o]}(.+?)#{Mx[:fa_strike_c]}/,'\1'). + gsub(/#{Mx[:fa_monospace_o]}(.+?)#{Mx[:fa_monospace_c]}/,'\1'). # tt, kbd + gsub(/#{Mx[:url_o]}(.+?)#{Mx[:url_c]}/,"#{Dx[:url_o]}\\1#{Dx[:url_c]}"). + gsub(/#{Mx[:mk_o]}:name#(\S+?)#{Mx[:mk_c]}/,''). + gsub(/#{Mx[:gl_bullet]}/m,'●  '). + gsub(/#{Mx[:nbsp]}/,' '). + gsub(/<(p|br)>/,'<\1 />') + dob.obj=clean(dob.obj) + dob + end + def markup_group(dob='') + dob.obj=dob.obj.gsub(//,'>'). + gsub(/<:?br(?:\s+\/)?>/,'
    '). + gsub(/<(link xmlns:xl=".+?")>/,'<\1>'). + gsub(/<(\/link)>/,'<\1>'). + gsub(/<(\/?en)>/,'<\1>') + dob + end + def markup_block(dob='') + dob.obj=dob.obj.gsub(//,'>'). + gsub(/<:?br(?:\s+\/)?>/,'
    '). + gsub(/<(link xmlns:xl=".+?")>/,'<\1>'). + gsub(/<(\/link)>/,'<\1>'). + gsub(/<(\/?en)>/,'<\1>') + dob + end + def xml_sem_block_paired(matched) # colon depth: many, recurs + matched=matched.gsub(/\b(au):\{(.+?)\}:\1\b/m, %{\\2}). + gsub(/\b(vol):\{(.+?)\}:\1\b/m, %{\\2}). + gsub(/\b(pub):\{(.+?)\}:\1\b/m, %{\\2}). + gsub(/\b(ref):\{(.+?)\}:\1\b/m, %{\\2}). + gsub(/\b(desc):\{(.+?)\}:\1\b/m,%{\\2}). + gsub(/\b(conv):\{(.+?)\}:\1\b/m,%{\\2}). + gsub(/\b(ct):\{(.+?)\}:\1\b/m, %{\\2}). + gsub(/\b(cty):\{(.+?)\}:\1\b/m, %{\\2}). + gsub(/\b(org):\{(.+?)\}:\1\b/m, %{\\2}). + gsub(/\b(dt):\{(.+?)\}:\1\b/m, %{\\2}). + gsub(/\b(n):\{(.+?)\}:\1\b/m, %{\\2}). + gsub(/([a-z]+(?:[_:.][a-z]+)*)(?::\{(.+?)\}:\1)/m,'\2') + end + def xml_semantic_tags(dob) + if @md.sem_tag + dob.obj.gsub!(/([a-z]+(?:[_:.][a-z]+)*)(?::\{(.+?)\}:\1)/m) {|c| xml_sem_block_paired(c) } + dob.obj.gsub!(/([a-z]+(?:[_:.][a-z]+)*)(?::\{(.+?)\}:\1)/m) {|c| xml_sem_block_paired(c) } + dob.obj.gsub!(/([a-z]+(?:[_:.][a-z]+)*)(?::\{(.+?)\}:\1)/m) {|c| xml_sem_block_paired(c) } + dob.obj=dob.obj.gsub(/:\{(.+?)\}:au\b/m, %{\\1}). + gsub(/:\{(.+?)\}:n\b/m, %{\\1}). + gsub(/:\{(.+?)\}:ti\b/m, %{\\1}). + gsub(/:\{(.+?)\}:ref\b/m, %{\\1}). + gsub(/:\{(.+?)\}:desc\b/m, %{\\1}). + gsub(/:\{(.+?)\}:cty\b/m, %{\\1}). + gsub(/:\{(.+?)\}:org\b/m, %{\\1}). + gsub(/:\{(.+?)\}:([a-z]+(?:[_:.][a-z]+)*)/m,'\1'). + gsub(/;\{([^}]+(?![;]))\};ti\b/m, %{\\1}). + gsub(/;\{([^}]+(?![;]))\};qt\b/m, %{\\1}). + gsub(/;\{([^}]+(?![;]))\};ref\b/m, %{\\1}). + gsub(/;\{([^}]+(?![;]))\};ed\b/m, %{\\1}). + gsub(/;\{([^}]+(?![;]))\};v\b/m, %{\\1}). + gsub(/;\{([^}]+(?![;]))\};desc\b/m, %{\\1}). + gsub(/;\{([^}]+(?![;]))\};def\b/m, %{\\1}). + gsub(/;\{([^}]+(?![;]))\};trans\b/m, %{\\1}). + gsub(/;\{([^}]+(?![;]))\};y\b/m, %{\\1}). + gsub(/;\{([^}]+(?![;]))\};ab\b/m, %{\\1}). + gsub(/;\{([^}]+(?![;]))\};pg\b/m, %{\\1}). + gsub(/;\{([^}]+(?![;]))\};fn?\b/m, %{\\1}). + gsub(/;\{([^}]+(?![;]))\};mn?\b/m, %{\\1}). + gsub(/;\{([^}]+(?![;]))\};ln?\b/m, %{\\1}). + gsub(/;\{([^}]+(?![;]))\};in\b/m, %{\\1}). + gsub(/;\{([^}]+(?![;]))\};uni\b/m, %{\\1}). + gsub(/;\{([^}]+(?![;]))\};fac\b/m, %{\\1}). + gsub(/;\{([^}]+(?![;]))\};inst\b/m, %{\\1}). + gsub(/;\{([^}]+(?![;]))\};dept\b/m, %{\\1}). + gsub(/;\{([^}]+(?![;]))\};org\b/m, %{\\1}). + gsub(/;\{([^}]+(?![;]))\};com?\b/m, %{\\1}). + gsub(/;\{([^}]+(?![;]))\};cty\b/m, %{\\1}). + gsub(/;\{([^}]+(?![;]))\};([a-z]+(?:[_:.][a-z]+)*)/m,'\1') + end + dob + end + end +end +module SiSU_XML_Tags #Format + require_relative 'param' # param.rb + include SiSU_Param + include SiSU_Viz + class RDF + def initialize(md='',seg_name=[],tracker=0) + @full_title=@subtitle=@author=@subject=@description=@publisher=@contributor=@date=@date_created=@date_issued=@date_available=@date_valid=@date_modified=@type=@format=@identifier=@source=@language=@relation=@coverage=@rights=@copyright=@owner=@keywords='' + @md=md + @rdfurl=%{ rdf:about="http://www.jus.uio.no/lm/toc"\n} + if defined? @md.title.full \ + and @md.title.full # DublinCore 1 - title + @rdf_title=%{ dc.title="#{seg_name}#{@md.title.full}"\n} + @full_title=%{ \n} + end + if defined? @md.creator.author \ + and @md.creator.author=~/\S+/ # DublinCore 2 - creator/author (author) + @rdf_author=%{ dc.author="#{@md.creator.author}"\n} + content=meta_content_clean(@md.creator.author) + @author=%{ \n} + end + if defined? @md.publisher \ + and @md.publisher # DublinCore 5 - publisher (current copy published by) + @rdf_publisher=%{ dc.publisher="#{@md.publisher}"\n} + content=meta_content_clean(@md.publisher) + @publisher=%{ \n} + end + if defined? @md.creator.contributor \ + and @md.creator.contributor=~/\S+/ # DublinCore 6 - contributor + @rdf_contributor=%{ dc.contributor="#{@md.creator.contributor}"\n} + content=meta_content_clean(@md.creator.contributor) + @contributor=%{ \n} + end + if defined? @md.date.published \ + and @md.date.published=~/\S+/ # DublinCore 7 - date year-mm-dd + @rdf_date=%{ dc.date="#{@md.date.published}"\n} + @date=%{ \n} # fix @md.date_scheme + end + if defined? @md.date.created \ + and @md.date.created=~/\S+/ # DublinCore 7 - date.created year-mm-dd + @rdf_date_created=%{ dc.date.created="#{@md.date.created}"\n} + @date_created=%{ \n} + end + if defined? @md.date.issued \ + and @md.date.issued=~/\S+/ # DublinCore 7 - date.issued year-mm-dd + @rdf_date_issued=%{ dc.date.issued="#{@md.date.issued}"\n} + @date_issued=%{ \n} + end + if defined? @md.date.available \ + and @md.date.available=~/\S+/ # DublinCore 7 - date.available year-mm-dd + @rdf_date_available=%{ dc.date.available="#{@md.date.available}"\n} + @date_available=%{ \n} + end + if defined? @md.date.valid \ + and @md.date.valid=~/\S+/ # DublinCore 7 - date.valid year-mm-dd + @rdf_date_valid=%{ dc.date.valid="#{@md.date.valid}"\n} + @date_valid=%{ \n} + end + if defined? @md.date.modified \ + and @md.date.modified=~/\S+/ # DublinCore 7 - date.modified year-mm-dd + @rdf_date_modified=%{ dc.date.modified="#{@md.date.modified}"\n} + @date_modified=%{ \n} + end + if defined? @md.rights.all \ + and @md.rights.all # DublinCore 15 - rights + @rdf_rights=%{ dc.rights="#{@md.rights.all}"\n} + content=meta_content_clean(@md.rights.all) + @rights=%{ \n} + end + if defined? @md.classify.subject \ + and @md.classify.subject=~/\S+/ # DublinCore 3 - subject (us library of congress, eric or udc, or schema???) + @rdf_subject=%{ dc.subject="#{@md.classify.subject}"\n} + content=meta_content_clean(@md.classify.subject) + @subject=%{ \n} + end + if defined? @md.notes.description \ + and @md.notes.description=~/\S+/ # DublinCore 4 - description + @rdf_description=%{ dc.description="#{@md.notes.description}"\n} + content=meta_content_clean(@md.notes.description) + @description=%{ \n} + end + if defined? @md.notes.coverage \ + and @md.notes.coverage=~/\S+/ # DublinCore 14 - coverage + @rdf_coverage=%{ dc.coverage="#{@md.notes.coverage}"\n} + content=meta_content_clean(@md.notes.coverage) + @coverage=%{ \n} + end + if defined? @md.notes.relation \ + and @md.notes.relation=~/\S+/ # DublinCore 13 - relation + @rdf_relation=%{ dc.relation="#{@md.notes.relation}"\n} + content=meta_content_clean(@md.notes.relation) + @relation=%{ \n} + end + if defined? @md.notes.type \ + and @md.notes.type # DublinCore 8 - type (genre eg. report, convention etc) + @rdf_type=%{ dc.type="#{@md.notes.type}"\n} + content=meta_content_clean(@md.notes.type) + @type=%{ \n} + end + if defined? @md.notes.format \ + and @md.notes.format=~/\S+/ # DublinCore 9 - format (use your mime type) + @rdf_format=%{ dc.format="#{@md.notes.format}"\n} + content=meta_content_clean(@md.notes.format) + @format=%{ \n} + end + #if defined? @md.identifier.sisupod \ + #and @md.identifier.sisupod=~/\S+/ # DublinCore 10 - identifier (your identifier, could use urn which is free) + # @rdf_identifier=%{ dc.identifier="#{@md.identifier.sisupod}"\n} + # content=meta_content_clean(@md.identifier.sisupod) + # @identifier=%{ \n} + #end + if defined? @md.original.source \ + and @md.original.source=~/\S+/ # DublinCore 11 - source (document source) + @rdf_source=%{ dc.source="#{@md.original.source}"\n} + content=meta_content_clean(@md.original.source) + @source=%{ \n} + end + if defined? @md.title.language \ + and @md.title.language=~/\S+/ # DublinCore 12 - language (English) + @rdf_language=%{ dc.language="#{@md.title.language}"\n} + @language=%{ \n} + end + if defined? @md.original.language \ + and @md.original.language=~/\S+/ + @rdf_language_original=%{ dc.language="#{@md.original.language}"\n} + @language_original=%{ \n} + end + content=meta_content_clean(@md.keywords) + @keywords=%{ \n} if @md.keywords + @vz=SiSU_Viz::Defaults.new + end + def meta_content_clean(content='') + content=if not content.nil? + content=content.tr('"',"'") + content=SiSU_XML_Munge::Trans.new(@md).char_enc.utf8(content) + else content + end + end + def rdfseg #segHead + rdftoc + end + def comment_xml(extra='') + 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} version: #{@md.sc_number} of: #{@md.sc_date}" + else '' + end + if extra.empty? +< +WOK + else +< +WOK + end + end + def comment_xml_sax + desc='SiSU XML, SAX type representation' + comment_xml(desc) + end + def comment_xml_node + desc='SiSU XML, Node type representation' + comment_xml(desc) + end + def comment_xml_dom + desc='SiSU XML, DOM type representation' + comment_xml(desc) + end + def metatag_html #values strung together, because some empty, and resulting output (line breaks) is much better +< Date: Tue, 3 Dec 2013 00:12:40 -0500 Subject: v5: plaintext, rename & simplify --- lib/sisu/v5/txt_plain.rb | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'lib') diff --git a/lib/sisu/v5/txt_plain.rb b/lib/sisu/v5/txt_plain.rb index e6a8f46f..0cd50254 100644 --- a/lib/sisu/v5/txt_plain.rb +++ b/lib/sisu/v5/txt_plain.rb @@ -60,12 +60,10 @@ linefeed) =end -module SiSU_Plaintext +module SiSU_Txt_Plain require_relative 'ao' # ao.rb require_relative 'sysenv' # sysenv.rb include SiSU_Env - require_relative 'txt_plaint_format' # plaintext_format.rb - include SiSU_Plaintext_Format require_relative 'shared_metadata' # shared_metadata.rb require_relative 'txt_shared' # txt_shared.rb include SiSU_Param @@ -396,6 +394,16 @@ WOK end @@endnotes[:para]=[] end + def ocn_display(dob) + if @env.plaintext_ocn? + if defined? dob.ocn \ + and dob.ocn.is_a?(Fixnum) + (defined? dob.ocn) ? "\n#{Dx[:ocn_o]}#{dob.ocn}#{Dx[:ocn_c]}" : '' + else '' + end + else '' + end + end def markup(data) # Used for major markup instructions SiSU_Env::InfoEnv.new(@md.fns) @data_mod,@endnotes,@level,@cont,@copen,@plaintext_contents_close=Array.new(6){[]} @@ -466,13 +474,7 @@ WOK gsub(/(?:^|[^_\\])#{Mx[:lnk_o]}(\S+?\.(?:png|jpg|gif)) .+?#{Mx[:lnk_c]}image/,' [ \1 ]'). gsub(/(?:^|[^_\\])\{\s*\S+?\.(?:png|jpg|gif)\s+.+?"(.*?)"\s*\}\S+/,'[image: "\1"]') if dob.obj !~/(^#{Rx[:meta]}|#{Mx[:br_eof]}|#{Mx[:br_endnotes]})/ - p_num='' - if @env.plaintext_ocn? - if defined? dob.ocn \ - and dob.ocn.is_a?(Fixnum) - p_num=SiSU_Plaintext_Format::ParagraphNumber.new(dob.ocn).display - end - end + p_num=ocn_display(dob) if dob.is==:heading \ or dob.is==:para plaintext_structure(dob,p_num) -- cgit v1.2.3 From cdda22f51e4de785502b42fce3cc645e95ffd1d4 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Tue, 3 Dec 2013 00:15:43 -0500 Subject: v5: plaintext, smarttext: textile --- lib/sisu/v5/constants.rb | 1 + lib/sisu/v5/hub.rb | 5 + lib/sisu/v5/manifest.rb | 8 + lib/sisu/v5/options.rb | 5 + lib/sisu/v5/sysenv.rb | 66 ++++++ lib/sisu/v5/txt_textile.rb | 543 +++++++++++++++++++++++++++++++++++++++++++++ lib/sisu/v5/urls.rb | 8 + 7 files changed, 636 insertions(+) create mode 100644 lib/sisu/v5/txt_textile.rb (limited to 'lib') diff --git a/lib/sisu/v5/constants.rb b/lib/sisu/v5/constants.rb index a21f01b7..e160fada 100644 --- a/lib/sisu/v5/constants.rb +++ b/lib/sisu/v5/constants.rb @@ -64,6 +64,7 @@ YEAR='2013' Sfx={ txt: '.txt', + txt_textile: '.textile', html: '.html', xhtml: '.xhtml', xml: '.xml', diff --git a/lib/sisu/v5/hub.rb b/lib/sisu/v5/hub.rb index a4fd408f..82036c87 100644 --- a/lib/sisu/v5/hub.rb +++ b/lib/sisu/v5/hub.rb @@ -302,6 +302,10 @@ module SiSU require_relative 'txt_plain' # txt_plain.rb SiSU_Txt_Plain::Source.new(@opt).read end + if @opt.act[:txt_textile][:set]==:on #% --textile + require_relative 'txt_textile' # txt_textile.rb + SiSU_Txt_Textile::Source.new(@opt).read + end if @opt.act[:html][:set]==:on #% --html, -h -H require_relative 'html' # html.rb SiSU_HTML::Source.new(@opt).read @@ -637,6 +641,7 @@ module SiSU || @opt.act[:manpage][:set]==:on \ || @opt.act[:texinfo][:set]==:on \ || @opt.act[:txt][:set]==:on \ + || @opt.act[:txt_textile][:set]==:on \ || @opt.act[:html][:set]==:on \ || @opt.act[:html_scroll][:set]==:on \ || @opt.act[:html_seg][:set]==:on \ diff --git a/lib/sisu/v5/manifest.rb b/lib/sisu/v5/manifest.rb index fc4bd5b9..9eb2aecb 100644 --- a/lib/sisu/v5/manifest.rb +++ b/lib/sisu/v5/manifest.rb @@ -439,6 +439,14 @@ module SiSU_Manifest file=@f.base_filename.txt summarize(id,file,pth,rel,url) end + if FileTest.file?(@f.place_file.textile.dir)==true + id='Textile text (UTF-8)' + pth=@f.output_path.textile.dir + rel=@f.output_path.textile.rel_sm + url=@f.output_path.textile.url + file=@f.base_filename.textile + summarize(id,file,pth,rel,url) + end if FileTest.file?("#{@base_path}/#{@md.fns}.tex")==true id,file='LaTeX (portrait)',"#{@md.fns}.tex" pth,rel,url='','','' diff --git a/lib/sisu/v5/options.rb b/lib/sisu/v5/options.rb index 650105fa..ccea95aa 100644 --- a/lib/sisu/v5/options.rb +++ b/lib/sisu/v5/options.rb @@ -875,6 +875,9 @@ module SiSU_Commandline || mod.inspect =~/"--txt"/) \ ? { bool: true, set: :on } : { bool: false, set: :na } + act[:txt_textile]=(mod.inspect =~/"--textile"/) \ + ? { bool: true, set: :on } + : { bool: false, set: :na } act[:manpage]=(cmd =~/i/ \ || mod.inspect =~/"--manpage"|"--man"/) \ ? { bool: true, set: :on } @@ -964,6 +967,7 @@ module SiSU_Commandline || mod.inspect =~/"--ao"|"--dal"/) { bool: true, set: :on } elsif (act[:txt][:set]==:on \ + || act[:txt_textile][:set]==:on \ || act[:xhtml][:set]==:on \ || act[:epub][:set]==:on \ || act[:html][:set]==:on \ @@ -1008,6 +1012,7 @@ module SiSU_Commandline || mod.inspect =~/"--manifest"/) { bool: true, set: :on } elsif (act[:txt][:set]==:on \ + || act[:txt_textile][:set]==:on \ || act[:xhtml][:set]==:on \ || act[:epub][:set]==:on \ || act[:html][:set]==:on \ diff --git a/lib/sisu/v5/sysenv.rb b/lib/sisu/v5/sysenv.rb index 344a88d3..d89b118f 100644 --- a/lib/sisu/v5/sysenv.rb +++ b/lib/sisu/v5/sysenv.rb @@ -1490,6 +1490,12 @@ module SiSU_Env ? @rc['plaintext']['ocn'] : true end + def textile_ocn? + ((defined? @rc['textile']['ocn']) \ + && @rc['textile']['ocn']==true) \ + ? @rc['textile']['ocn'] + : false + end def widget #needs (md) #move @rc=SiSU_Env::GetInit.new.sisu_yaml.rc @ad=SiSU_Env::GetInit.new.ads @@ -2995,6 +3001,9 @@ WOK if @md.opt.act[:txt][:set]==:on #% --txt, -t -a ft << @md.fn[:plain] end + if @md.opt.act[:txt_textile][:set]==:on #% --textile + ft << @md.fn[:txt_textile] + end if @md.opt.act[:xhtml][:set]==:on #% --xhtml, -b xhtml ft << @md.fn[:xhtml] end @@ -3045,6 +3054,9 @@ WOK if @opt.act[:txt][:set]==:on #% --txt, -t -a ft << 'plain.txt' << '??.plain.txt' << 'plain.??.txt' end + if @opt.act[:txt_textile][:set]==:on #% --textile + ft << 'plain.txt' << '??.plain.txt' << 'plain.??.txt' + end if @opt.act[:xhtml][:set]==:on #% --xhtml, -b xhtml ft << 'scroll.xhtml' << '??.scroll.xhtml' << 'scroll.??.xhtml' end @@ -4372,6 +4384,12 @@ WOK fn=base_filename.txt make_file(path,fn) end + def textile + path=output_path.textile.dir + make_path(path) + fn=base_filename.textile + make_file(path,fn) + end def html_scroll pth=output_path.html.dir make_path(pth) @@ -4493,6 +4511,15 @@ WOK end self end + def textile + def dir + output_path.textile.dir + '/' + base_filename.textile + end + def rel + output_path.textile.rel + '/' + base_filename.textile + end + self + end def html_scroll def dir output_path.html_scroll.dir + '/' + base_filename.html_scroll @@ -4784,6 +4811,24 @@ WOK end i18n(fnh) end + def textile(fh=nil) + fh=default_hash_build(fh,Sfx[:txt_textile]) + fh[:lng]=lang_code?(fh[:lng]) + fnh=if output_dir_structure.by_filename? + { + fn: 'plain', + ft: fh[:ft], + lng: fh[:lng], + } + else + { + fn: fh[:fn], + ft: fh[:ft], + lng: fh[:lng], + } + end + i18n(fnh) + end def html_scroll(fh=nil) fh=default_hash_build(fh,Sfx[:html]) fh[:lng]=lang_code?(fh[:lng]) @@ -5560,6 +5605,27 @@ WOK end self end + def textile + def ft + 'textile_CONSTRUCTION_ZONE' + end + def dir + set_path(ft).dir.abc + end + def url + set_path(ft).url.abc + end + def rel + set_path(ft).rel.abc + end + def rcp + set_path(ft).rcp.abc + end + def rel_sm + set_path(ft).rel_sm.ab + end + self + end def html_scroll def ft 'html' diff --git a/lib/sisu/v5/txt_textile.rb b/lib/sisu/v5/txt_textile.rb new file mode 100644 index 00000000..429593cc --- /dev/null +++ b/lib/sisu/v5/txt_textile.rb @@ -0,0 +1,543 @@ +# 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: plaintext (smarttext) generation, textile + +=end +module SiSU_Txt_Textile + require_relative 'ao' # ao.rb + require_relative 'sysenv' # sysenv.rb + include SiSU_Env + require_relative 'shared_metadata' # shared_metadata.rb + require_relative 'txt_shared' # txt_shared.rb + include SiSU_Param + include SiSU_Viz + @@alt_id_count,@@alt_id_count,@@tablehead,@@number_of_cols=0,0,0,0 + @@tablefoot='' + class Source + def initialize(opt) + @opt=opt + unless @opt.fns =~/(.+?)\.(?:-|ssm\.)?sst$/ + puts "#{sf} not a processed file type" + end + end + def read + begin + md=SiSU_Param::Parameters.new(@opt).get + env=SiSU_Env::InfoEnv.new(@opt.fns) + 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.text_editor} #{md.file.output_path.textile.dir}/#{md.file.base_filename.textile}" + : "[#{@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],'Textile (plaintext utf-8)',tool).green_hi_blue + : SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'Textile (plaintext utf-8)',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,"#{md.file.output_path.textile.dir}/#{md.file.base_filename.textile}").flow + end + end + ao_array=SiSU_AO::Source.new(@opt).get # ao file drawn here + wrap_width=if defined? md.make.plaintext_wrap \ + and md.make.plaintext_wrap + md.make.plaintext_wrap + elsif defined? env.plaintext_wrap \ + and env.plaintext_wrap + env.plaintext_wrap + else 78 + end + #wrap_width=(defined? md.make.plaintext_wrap) ? md.make.plaintext_wrap : 78 + SiSU_Txt_Textile::Source::Scroll.new(md,ao_array,wrap_width).songsheet + rescue + SiSU_Errors::Rescued.new($!,$@,@opt.cmd,@opt.fns).location do + __LINE__.to_s + ':' + __FILE__ + end + ensure + end + end + private + class Scroll appropriately within plaintext, consider + n=n.dup.to_s + if n =~/#{Mx[:br_line]}|#{Mx[:br_nl]}/ + fix = n.split(/#{Mx[:br_line]}|#{Mx[:br_nl]}/) #watch #added + fix.each do |x| + unless x.empty?; @n << x + end + end + else @n << n + end + end + notes=@n.flatten + notes.each do |e| + util=(e.to_s =~/^\[[\d*+]+\]:/) \ + ? (SiSU_TextUtils::Wrap.new(e.to_s,@wrap_width,4,1)) + : (SiSU_TextUtils::Wrap.new(e.to_s,@wrap_width,1,1)) + wrap=util.line_wrap + wrap=if wrap =~ /^\s*[\d*+]+\s+.+?\s*\Z/m + wrap.gsub(/^(\s*)([\d*+]+)\s+(.+?)\s*\Z/m, <<-GSUB +\\1[\\2]: \\3 + GSUB + ) + else + wrap.gsub(/^(.+)\Z/m, <<-GSUB +\\1 + GSUB + ) + end + @@endnotes[:para] << "-#{wrap}" + @@endnotes[:end] << '' << wrap + end + @@endnotes + end + def plaintext_metadata + array=SiSU_Metadata::Summary.new(@md).plaintext.metadata + array.each do |meta| + tag,inf=meta.scan(/^.+?:\s|.+/) + if tag and inf + util=SiSU_TextUtils::Wrap.new(inf,@wrap_width,15,1) + txt=util.line_wrap + @plaintext[:metadata] <<<]'). + gsub(/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}image/,'\1 [link: local image]'). + gsub(/#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,"#{@brace_url.txt_open}\\1#{@brace_url.txt_close}") + extract_endnotes(dob) + dob.obj=dob.obj.gsub(/#{Mx[:en_a_o]}([\d*+]+)\s+(?:.+?)#{Mx[:en_a_c]}/,'[^\1]'). # endnote marker marked up + gsub(/#{Mx[:en_b_o]}([\d*+]+)\s+(?:.+?)#{Mx[:en_b_c]}/,'[^\1]'). # endnote marker marked up + gsub(/#{Mx[:gl_o]}(?:#lt|#060)#{Mx[:gl_c]}/,'<'). + gsub(/#{Mx[:gl_o]}(?:#gt|#062)#{Mx[:gl_c]}/,'>'). + gsub(/#{Mx[:gl_o]}#(?:038|amp)#{Mx[:gl_c]}/,'&'). + gsub(/#{Mx[:gl_o]}#033#{Mx[:gl_c]}/,'!'). + gsub(/#{Mx[:gl_o]}#035#{Mx[:gl_c]}/,'#'). + gsub(/#{Mx[:gl_o]}#042#{Mx[:gl_c]}/,'*'). + gsub(/#{Mx[:gl_o]}#045#{Mx[:gl_c]}/,'-'). + gsub(/#{Mx[:gl_o]}#047#{Mx[:gl_c]}/,'/'). + gsub(/#{Mx[:gl_o]}#095#{Mx[:gl_c]}/,'_'). + gsub(/#{Mx[:gl_o]}#123#{Mx[:gl_c]}/,'{'). + gsub(/#{Mx[:gl_o]}#125#{Mx[:gl_c]}/,'}'). + gsub(/#{Mx[:gl_o]}#126#{Mx[:gl_c]}/,'~'). + gsub(/#{Mx[:gl_o]}#169#{Mx[:gl_c]}/,'©'). + gsub(/#{Mx[:gl_o]}#092#{Mx[:gl_c]}/,'\\') + end + dob.obj=if dob.of==:block # watch + dob.obj.gsub(/#{Mx[:gl_o]}●#{Mx[:gl_c]}/m,"* "). + gsub(/\n?#{Mx[:br_line]}\n?|\n?#{Mx[:br_nl]}\n?/m,break_line) + else dob.obj.gsub(/\n?#{Mx[:br_line]}\n?|\n?#{Mx[:br_nl]}\n?/m,break_line*2) + end + if dob.is==:code + dob.obj=dob.obj.gsub(/(^|[^}])_([<>])/m,'\1\2'). # _> _< + gsub(/(^|[^}])_([<>])/m,'\1\2') # _<_< + end + dob.obj=dob.obj.gsub(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/,'\1'). + gsub(/(.+?)<\/a>/m,'\1'). + gsub(/#{Mx[:mk_o]}:name#(\S+?)#{Mx[:mk_c]}/,''). # remove name links + gsub(/ |#{Mx[:nbsp]}/,' '). # decide on + gsub(/(?:^|[^_\\])#{Mx[:lnk_o]}(\S+?\.(?:png|jpg|gif)) .+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/,' [ \1 ]'). #"[ #{dir.url.images_local}\/\\1 ]") + gsub(/(?:^|[^_\\])#{Mx[:lnk_o]}(\S+?\.(?:png|jpg|gif)) .+?#{Mx[:lnk_c]}image/,' [ \1 ]'). + gsub(/(?:^|[^_\\])\{\s*\S+?\.(?:png|jpg|gif)\s+.+?"(.*?)"\s*\}\S+/,'[image: "\1"]') + if dob.obj !~/(^#{Rx[:meta]}|#{Mx[:br_eof]}|#{Mx[:br_endnotes]})/ + p_num='' + #ocn + if dob.is==:heading \ + or dob.is==:para + plaintext_structure(dob,p_num) + elsif dob.is==:group \ + or dob.is==:block \ + or dob.is==:verse \ + or dob.is==:code \ + or dob.is==:table + @plaintext[:body] << dob.obj + p_num << break_line + elsif dob.is==:break + sp=' ' + ln='-' + @plaintext[:body] <<=if dob.obj==Mx[:br_page] \ + or dob.obj==Mx[:br_page_new] \ + or dob.obj==Mx[:br_page_line] + "#{break_line}#{ln*40}#{break_line*2}" + elsif dob.obj ==Mx[:br_obj] + "#{break_line}#{sp*20}* * *#{break_line*2}" + end # following empty line (break_line) missing, fix + end + dob='' if (dob.obj =~// \ + and dob.obj =~/^(-\{{2}~\d+|)/) # -endnote + if dob ## Clean Prepared Text + dob.obj=dob.obj.gsub(//,' '). + gsub(/<:\S+>/,' ') + end + end + end + @plaintext + end + def publish(plaintext) + divider='=' + content=[] + content << plaintext[:open] + content << plaintext[:head] + content << plaintext[:body] + content << @@endnotes[:end] if @@endnotes_ + content << "#{break_line}#{divider*@wrap_width}#{break_line}" + content << plaintext[:metadata] + content << "#{break_line}#{divider*@wrap_width}#{break_line}" if @md.stmp =~/\w+/ #not used? + content << plaintext[:tail] + Output.new(content,@md).textile + @@endnotes={ para: [], end: [] } + end + end + class Output 0 + para.each do |line| + if line + line=line.gsub(/[ \t]+$/m,''). + gsub(/^\A[ ]*\Z/m,'') + (line=~/^\A\Z/) \ + ? (emptyline+=1) + : emptyline=0 + if emptyline < 2 #remove additional empty lines + file_plaintext.puts line + end + end + end + else file_plaintext.puts para #unix plaintext # /^([*=-]|\.){5}/ + end + end + file_plaintext.close + end + end + end +end +__END__ diff --git a/lib/sisu/v5/urls.rb b/lib/sisu/v5/urls.rb index 9b2f1937..16c753ee 100644 --- a/lib/sisu/v5/urls.rb +++ b/lib/sisu/v5/urls.rb @@ -114,6 +114,7 @@ module SiSU_Urls 's --source (sisu markup)'=>@opt.fno, 'S --sisupod (sisupod)'=>@fn[:sisupod], 't --txt (Plain-text (endnotes))'=>@fn[:plain], + ' --textile (textile txt)'=>@fn[:txt_textile], 'x --xml-sax (XML sax type)'=>@fn[:sax], 'X --xml-dom (XML dom type)'=>@fn[:dom], ' --xml-scaffold-sisu (XML scaffold)'=>@fn[:xml_scaffold_structure_sisu], @@ -153,6 +154,9 @@ module SiSU_Urls def text(x) SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"[#{@opt.f_pth[:lng_is]}] -#{x}","#{@prog.web_browser} file://#{@md.file.output_path.txt.dir}/#{@md.file.base_filename.txt}").result end + def textile(x) + SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"[#{@opt.f_pth[:lng_is]}] -#{x}","#{@prog.web_browser} file://#{@md.file.output_path.textile.dir}/#{@md.file.base_filename.textile}").result + end def epub(x) SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"[#{@opt.f_pth[:lng_is]}] -#{x}","#{@prog.epub_viewer} #{@md.file.output_path.epub.dir}/#{@md.file.base_filename.epub}").result end @@ -310,6 +314,10 @@ module SiSU_Urls and @opt.act[:txt][:set]==:on show.text(x) end + if x=~/--textile\b/ \ + and @opt.act[:txt_textile][:set]==:on + show.textile(x) + end if x=~/--xhtml\b/ \ and @opt.act[:xhtml][:set]==:on show.xhtml(x) -- cgit v1.2.3 From ce74f66cf2cd1dae56f7f7f14586bd770a0b32f4 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Tue, 3 Dec 2013 00:19:46 -0500 Subject: v5: plaintext, smarttext: asciidoc --- lib/sisu/v5/constants.rb | 1 + lib/sisu/v5/hub.rb | 5 + lib/sisu/v5/manifest.rb | 8 + lib/sisu/v5/options.rb | 5 + lib/sisu/v5/sysenv.rb | 66 +++++ lib/sisu/v5/txt_asciidoc.rb | 588 ++++++++++++++++++++++++++++++++++++++++++++ lib/sisu/v5/urls.rb | 8 + 7 files changed, 681 insertions(+) create mode 100644 lib/sisu/v5/txt_asciidoc.rb (limited to 'lib') diff --git a/lib/sisu/v5/constants.rb b/lib/sisu/v5/constants.rb index e160fada..f8aedf19 100644 --- a/lib/sisu/v5/constants.rb +++ b/lib/sisu/v5/constants.rb @@ -65,6 +65,7 @@ YEAR='2013' Sfx={ txt: '.txt', txt_textile: '.textile', + txt_asciidoc: '.asciidoc.txt', html: '.html', xhtml: '.xhtml', xml: '.xml', diff --git a/lib/sisu/v5/hub.rb b/lib/sisu/v5/hub.rb index 82036c87..6546de4c 100644 --- a/lib/sisu/v5/hub.rb +++ b/lib/sisu/v5/hub.rb @@ -306,6 +306,10 @@ module SiSU require_relative 'txt_textile' # txt_textile.rb SiSU_Txt_Textile::Source.new(@opt).read end + if @opt.act[:txt_asciidoc][:set]==:on #% --asciidoc + require_relative 'txt_asciidoc' # txt_asciidoc.rb + SiSU_Txt_asciiDoc::Source.new(@opt).read + end if @opt.act[:html][:set]==:on #% --html, -h -H require_relative 'html' # html.rb SiSU_HTML::Source.new(@opt).read @@ -642,6 +646,7 @@ module SiSU || @opt.act[:texinfo][:set]==:on \ || @opt.act[:txt][:set]==:on \ || @opt.act[:txt_textile][:set]==:on \ + || @opt.act[:txt_asciidoc][:set]==:on \ || @opt.act[:html][:set]==:on \ || @opt.act[:html_scroll][:set]==:on \ || @opt.act[:html_seg][:set]==:on \ diff --git a/lib/sisu/v5/manifest.rb b/lib/sisu/v5/manifest.rb index 9eb2aecb..821b8fab 100644 --- a/lib/sisu/v5/manifest.rb +++ b/lib/sisu/v5/manifest.rb @@ -447,6 +447,14 @@ module SiSU_Manifest file=@f.base_filename.textile summarize(id,file,pth,rel,url) end + if FileTest.file?(@f.place_file.asciidoc.dir)==true + id='asciiDoc text (UTF-8)' + pth=@f.output_path.asciidoc.dir + rel=@f.output_path.asciidoc.rel_sm + url=@f.output_path.asciidoc.url + file=@f.base_filename.asciidoc + summarize(id,file,pth,rel,url) + end if FileTest.file?("#{@base_path}/#{@md.fns}.tex")==true id,file='LaTeX (portrait)',"#{@md.fns}.tex" pth,rel,url='','','' diff --git a/lib/sisu/v5/options.rb b/lib/sisu/v5/options.rb index ccea95aa..3995a1b4 100644 --- a/lib/sisu/v5/options.rb +++ b/lib/sisu/v5/options.rb @@ -878,6 +878,9 @@ module SiSU_Commandline act[:txt_textile]=(mod.inspect =~/"--textile"/) \ ? { bool: true, set: :on } : { bool: false, set: :na } + act[:txt_asciidoc]=(mod.inspect =~/"--asciidoc"/) \ + ? { bool: true, set: :on } + : { bool: false, set: :na } act[:manpage]=(cmd =~/i/ \ || mod.inspect =~/"--manpage"|"--man"/) \ ? { bool: true, set: :on } @@ -968,6 +971,7 @@ module SiSU_Commandline { bool: true, set: :on } elsif (act[:txt][:set]==:on \ || act[:txt_textile][:set]==:on \ + || act[:txt_asciidoc][:set]==:on \ || act[:xhtml][:set]==:on \ || act[:epub][:set]==:on \ || act[:html][:set]==:on \ @@ -1013,6 +1017,7 @@ module SiSU_Commandline { bool: true, set: :on } elsif (act[:txt][:set]==:on \ || act[:txt_textile][:set]==:on \ + || act[:txt_asciidoc][:set]==:on \ || act[:xhtml][:set]==:on \ || act[:epub][:set]==:on \ || act[:html][:set]==:on \ diff --git a/lib/sisu/v5/sysenv.rb b/lib/sisu/v5/sysenv.rb index d89b118f..da992173 100644 --- a/lib/sisu/v5/sysenv.rb +++ b/lib/sisu/v5/sysenv.rb @@ -1496,6 +1496,12 @@ module SiSU_Env ? @rc['textile']['ocn'] : false end + def asciidoc_ocn? + ((defined? @rc['asciidoc']['ocn']) \ + && @rc['asciidoc']['ocn']==true) \ + ? @rc['asciidoc']['ocn'] + : false + end def widget #needs (md) #move @rc=SiSU_Env::GetInit.new.sisu_yaml.rc @ad=SiSU_Env::GetInit.new.ads @@ -3004,6 +3010,9 @@ WOK if @md.opt.act[:txt_textile][:set]==:on #% --textile ft << @md.fn[:txt_textile] end + if @md.opt.act[:txt_asciidoc][:set]==:on #% --asciidoc + ft << @md.fn[:txt_asciidoc] + end if @md.opt.act[:xhtml][:set]==:on #% --xhtml, -b xhtml ft << @md.fn[:xhtml] end @@ -3057,6 +3066,9 @@ WOK if @opt.act[:txt_textile][:set]==:on #% --textile ft << 'plain.txt' << '??.plain.txt' << 'plain.??.txt' end + if @opt.act[:txt_asciidoc][:set]==:on #% --asciidoc + ft << 'plain.txt' << '??.plain.txt' << 'plain.??.txt' + end if @opt.act[:xhtml][:set]==:on #% --xhtml, -b xhtml ft << 'scroll.xhtml' << '??.scroll.xhtml' << 'scroll.??.xhtml' end @@ -4390,6 +4402,12 @@ WOK fn=base_filename.textile make_file(path,fn) end + def asciidoc + path=output_path.asciidoc.dir + make_path(path) + fn=base_filename.asciidoc + make_file(path,fn) + end def html_scroll pth=output_path.html.dir make_path(pth) @@ -4520,6 +4538,15 @@ WOK end self end + def asciidoc + def dir + output_path.asciidoc.dir + '/' + base_filename.asciidoc + end + def rel + output_path.asciidoc.rel + '/' + base_filename.asciidoc + end + self + end def html_scroll def dir output_path.html_scroll.dir + '/' + base_filename.html_scroll @@ -4829,6 +4856,24 @@ WOK end i18n(fnh) end + def asciidoc(fh=nil) + fh=default_hash_build(fh,Sfx[:txt_asciidoc]) + fh[:lng]=lang_code?(fh[:lng]) + fnh=if output_dir_structure.by_filename? + { + fn: 'plain', + ft: fh[:ft], + lng: fh[:lng], + } + else + { + fn: fh[:fn], + ft: fh[:ft], + lng: fh[:lng], + } + end + i18n(fnh) + end def html_scroll(fh=nil) fh=default_hash_build(fh,Sfx[:html]) fh[:lng]=lang_code?(fh[:lng]) @@ -5626,6 +5671,27 @@ WOK end self end + def asciidoc + def ft + 'asciidoc_CONSTRUCTION_ZONE' + end + def dir + set_path(ft).dir.abc + end + def url + set_path(ft).url.abc + end + def rel + set_path(ft).rel.abc + end + def rcp + set_path(ft).rcp.abc + end + def rel_sm + set_path(ft).rel_sm.ab + end + self + end def html_scroll def ft 'html' diff --git a/lib/sisu/v5/txt_asciidoc.rb b/lib/sisu/v5/txt_asciidoc.rb new file mode 100644 index 00000000..114252b1 --- /dev/null +++ b/lib/sisu/v5/txt_asciidoc.rb @@ -0,0 +1,588 @@ +# 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: plaintext (smarttext) generation, asciidoc + +=end +module SiSU_Txt_asciiDoc + require_relative 'ao' # ao.rb + require_relative 'sysenv' # sysenv.rb + include SiSU_Env + require_relative 'shared_metadata' # shared_metadata.rb + require_relative 'txt_shared' # txt_shared.rb + include SiSU_Param + include SiSU_Viz + @@alt_id_count,@@alt_id_count,@@tablehead,@@number_of_cols=0,0,0,0 + @@tablefoot='' + class Source + def initialize(opt) + @opt=opt + unless @opt.fns =~/(.+?)\.(?:-|ssm\.)?sst$/ + puts "#{sf} not a processed file type" + end + end + def read + begin + md=SiSU_Param::Parameters.new(@opt).get + env=SiSU_Env::InfoEnv.new(@opt.fns) + 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.text_editor} #{md.file.output_path.asciidoc.dir}/#{md.file.base_filename.asciidoc}" + : "[#{@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],'asciiDoc (plaintext utf-8)',tool).green_hi_blue + : SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'asciiDoc (plaintext utf-8)',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,"#{md.file.output_path.asciidoc.dir}/#{md.file.base_filename.asciidoc}").flow + end + end + ao_array=SiSU_AO::Source.new(@opt).get # ao file drawn here + wrap_width=if defined? md.make.plaintext_wrap \ + and md.make.plaintext_wrap + md.make.plaintext_wrap + elsif defined? env.plaintext_wrap \ + and env.plaintext_wrap + env.plaintext_wrap + else 78 + end + #wrap_width=(defined? md.make.plaintext_wrap) ? md.make.plaintext_wrap : 78 + SiSU_Txt_asciiDoc::Source::Scroll.new(md,ao_array,wrap_width).songsheet + rescue + SiSU_Errors::Rescued.new($!,$@,@opt.cmd,@opt.fns).location do + __LINE__.to_s + ':' + __FILE__ + end + ensure + end + end + private + class Scroll appropriately within plaintext, consider + n=n.dup.to_s + if n =~/#{Mx[:br_line]}|#{Mx[:br_nl]}/ + fix = n.split(/#{Mx[:br_line]}|#{Mx[:br_nl]}/) #watch #added + fix.each do |x| + unless x.empty?; @n << x + end + end + else @n << n + end + end + notes=@n.flatten + notes.each do |e| + util=(e.to_s =~/^\[[\d*+]+\]:/) \ + ? (SiSU_TextUtils::Wrap.new(e.to_s,@wrap_width,4,1)) + : (SiSU_TextUtils::Wrap.new(e.to_s,@wrap_width,1,1)) + wrap=util.line_wrap + wrap=if wrap =~ /^\s*[\d*+]+\s+.+?\s*\Z/m + wrap.gsub(/^(\s*)([\d*+]+)\s+(.+?)\s*\Z/m, <<-GSUB +\\1[\\2]: \\3 + GSUB + ) + else + wrap.gsub(/^(.+)\Z/m, <<-GSUB +\\1 + GSUB + ) + end + @@endnotes[:para] << "-#{wrap}" + @@endnotes[:end] << '' << wrap + end + @@endnotes + end + def plaintext_metadata + array=SiSU_Metadata::Summary.new(@md).plaintext.metadata + array.each do |meta| + tag,inf=meta.scan(/^.+?:\s|.+/) + if tag and inf + util=SiSU_TextUtils::Wrap.new(inf,@wrap_width,15,1) + txt=util.line_wrap + @plaintext[:metadata] <<< @wrap_width + case dob.lc + when 1 then decorate.heading.underscore.l1*times + p_num << break_line*2 + when 2 then decorate.heading.underscore.l2*times + p_num << break_line*2 + when 3 then decorate.heading.underscore.l3*times + p_num << break_line*2 + when 4 then decorate.heading.underscore.l4*times + p_num << break_line*2 + when 5 then decorate.heading.underscore.l5*times + p_num << break_line*2 + when 6 then decorate.heading.underscore.l6*times + p_num << break_line*2 + end + end + end + def plaintext_structure(dob='',p_num='') #% Used to extract the structure of a document + heading_decoration=:inline #(:inline|:underscore) #switch heading decoration between inline & underscore options + util=nil + wrapped=if dob.is==:para \ + || dob.is==:heading + if dob.is==:heading + util=(heading_decoration== :inline) \ + ? (SiSU_TextUtils::Wrap.new(heading_decorated_inline(dob),@wrap_width,0)) + : (SiSU_TextUtils::Wrap.new(dob.obj,@wrap_width,0)) + elsif dob.is==:para + if dob.hang \ + and dob.hang =~/[0-9]/ \ + and dob.indent != dob.hang + util=SiSU_TextUtils::Wrap.new(dob.obj,@wrap_width,dob.indent.to_i*2,dob.hang.to_i*2) + #util=SiSU_TextUtils::Wrap.new(dob.obj,@wrap_width,dob.hang.to_i*2,0) + elsif dob.indent =~/[1-9]/ + util=if dob.bullet_ + SiSU_TextUtils::Wrap.new("* #{dob.obj}",@wrap_width,dob.indent.to_i*2) + else SiSU_TextUtils::Wrap.new(dob.obj,@wrap_width,dob.indent.to_i*2) + end + else + util=if dob.bullet_ + SiSU_TextUtils::Wrap.new("* #{dob.obj}",@wrap_width,0) + else SiSU_TextUtils::Wrap.new(dob.obj,@wrap_width,0) + end + end + else util=SiSU_TextUtils::Wrap.new(dob.obj,@wrap_width,0) + end + dob.is==:heading ? util.no_wrap_no_breaks : util.line_wrap + end + if heading_decoration== :underscore \ + and dob.is==:heading + @plaintext[:body] << wrapped + p_num # main text, contents, body KEEP + @plaintext[:body] << heading_decorated_underscore(dob,wrapped.length,p_num) + else + @plaintext[:body] << wrapped + p_num << break_line # main text, contents, body KEEP + end + if @@endnotes[:para] \ + and not @@endnotes_ + @@endnotes[:para].each {|e| @plaintext[:body] << e << break_line} + elsif @@endnotes[:para] \ + and @@endnotes_ + end + @@endnotes[:para]=[] + end + def markup(data) # Used for major markup instructions + SiSU_Env::InfoEnv.new(@md.fns) + @data_mod,@endnotes,@level,@cont,@copen,@plaintext_contents_close=Array.new(6){[]} + (0..6).each { |x| @cont[x]=@level[x]=false } + (4..6).each { |x| @plaintext_contents_close[x]='' } + plaintext_tail #($1,$2) + plaintext_metadata + table_message='[table conversion awaited, see other document formats]' + data.each do |dob| + dob.obj=dob.obj.gsub(/#{Mx[:gr_o]}Th?#{Mx[:tc_p]}.+/um,"#{break_line}#{table_message}"). #fix + gsub(/.+?#{Mx[:gl_o]}-##{Mx[:gl_c]}/,''). # remove dummy headings (used by html) #check also [~-]# + gsub(/#{Mx[:fa_bold_o]}(.+?)#{Mx[:fa_bold_c]}/, + "#{decorate.bold.open}\\1#{decorate.bold.close}"). + gsub(/#{Mx[:fa_italics_o]}(.+?)#{Mx[:fa_italics_c]}/, + "#{decorate.italics.open}\\1#{decorate.italics.close}"). + gsub(/#{Mx[:fa_underscore_o]}(.+?)#{Mx[:fa_underscore_c]}/, + "#{decorate.underscore.open}\\1#{decorate.underscore.close}"). + gsub(/#{Mx[:fa_subscript_o]}(.+?)#{Mx[:fa_subscript_c]}/, + "#{decorate.subscript.open}\\1#{decorate.subscript.close}"). + gsub(/#{Mx[:fa_superscript_o]}(.+?)#{Mx[:fa_superscript_c]}/, + "#{decorate.superscript.open}\\1#{decorate.superscript.close}"). + gsub(/#{Mx[:fa_insert_o]}(.+?)#{Mx[:fa_insert_c]}/, + "#{decorate.insert.open}\\1#{decorate.insert.close}"). + gsub(/#{Mx[:fa_cite_o]}(.+?)#{Mx[:fa_cite_c]}/, + "#{decorate.cite.open}\\1#{decorate.cite.close}"). + gsub(/#{Mx[:fa_strike_o]}(.+?)#{Mx[:fa_strike_c]}/, + "#{decorate.strike.open}\\1#{decorate.strike.close}"). + gsub(/#{Mx[:fa_monospace_o]}(.+?)#{Mx[:fa_monospace_c]}/, + "#{decorate.monospace.open}\\1#{decorate.monospace.close}") + unless dob.is==:code + dob.obj=dob.obj.gsub(/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}/,'\1'). + gsub(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/,'\1'). + gsub(/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,'\1 [link: <\2>]'). + gsub(/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}image/,'\1 [link: local image]'). + gsub(/#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,"#{@brace_url.txt_open}\\1#{@brace_url.txt_close}") + extract_endnotes(dob) + dob.obj=dob.obj.gsub(/#{Mx[:en_a_o]}([\d*+]+)\s+(?:.+?)#{Mx[:en_a_c]}/,'[^\1]'). # endnote marker marked up + gsub(/#{Mx[:en_b_o]}([\d*+]+)\s+(?:.+?)#{Mx[:en_b_c]}/,'[^\1]'). # endnote marker marked up + gsub(/#{Mx[:gl_o]}(?:#lt|#060)#{Mx[:gl_c]}/,'<'). + gsub(/#{Mx[:gl_o]}(?:#gt|#062)#{Mx[:gl_c]}/,'>'). + gsub(/#{Mx[:gl_o]}#(?:038|amp)#{Mx[:gl_c]}/,'&'). + gsub(/#{Mx[:gl_o]}#033#{Mx[:gl_c]}/,'!'). + gsub(/#{Mx[:gl_o]}#035#{Mx[:gl_c]}/,'#'). + gsub(/#{Mx[:gl_o]}#042#{Mx[:gl_c]}/,'*'). + gsub(/#{Mx[:gl_o]}#045#{Mx[:gl_c]}/,'-'). + gsub(/#{Mx[:gl_o]}#047#{Mx[:gl_c]}/,'/'). + gsub(/#{Mx[:gl_o]}#095#{Mx[:gl_c]}/,'_'). + gsub(/#{Mx[:gl_o]}#123#{Mx[:gl_c]}/,'{'). + gsub(/#{Mx[:gl_o]}#125#{Mx[:gl_c]}/,'}'). + gsub(/#{Mx[:gl_o]}#126#{Mx[:gl_c]}/,'~'). + gsub(/#{Mx[:gl_o]}#169#{Mx[:gl_c]}/,'©'). + gsub(/#{Mx[:gl_o]}#092#{Mx[:gl_c]}/,'\\') + end + dob.obj=if dob.of==:block # watch + dob.obj.gsub(/#{Mx[:gl_o]}●#{Mx[:gl_c]}/m,"* "). + gsub(/\n?#{Mx[:br_line]}\n?|\n?#{Mx[:br_nl]}\n?/m,break_line) + else dob.obj.gsub(/\n?#{Mx[:br_line]}\n?|\n?#{Mx[:br_nl]}\n?/m,break_line*2) + end + if dob.is==:code + dob.obj=dob.obj.gsub(/(^|[^}])_([<>])/m,'\1\2'). # _> _< + gsub(/(^|[^}])_([<>])/m,'\1\2') # _<_< + end + dob.obj=dob.obj.gsub(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/,'\1'). + gsub(/(.+?)<\/a>/m,'\1'). + gsub(/#{Mx[:mk_o]}:name#(\S+?)#{Mx[:mk_c]}/,''). # remove name links + gsub(/ |#{Mx[:nbsp]}/,' '). # decide on + gsub(/(?:^|[^_\\])#{Mx[:lnk_o]}(\S+?\.(?:png|jpg|gif)) .+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/,' [ \1 ]'). #"[ #{dir.url.images_local}\/\\1 ]") + gsub(/(?:^|[^_\\])#{Mx[:lnk_o]}(\S+?\.(?:png|jpg|gif)) .+?#{Mx[:lnk_c]}image/,' [ \1 ]'). + gsub(/(?:^|[^_\\])\{\s*\S+?\.(?:png|jpg|gif)\s+.+?"(.*?)"\s*\}\S+/,'[image: "\1"]') + if dob.obj !~/(^#{Rx[:meta]}|#{Mx[:br_eof]}|#{Mx[:br_endnotes]})/ + p_num='' + #ocn + if dob.is==:heading \ + or dob.is==:para + plaintext_structure(dob,p_num) + elsif dob.is==:group \ + or dob.is==:block \ + or dob.is==:verse \ + or dob.is==:code \ + or dob.is==:table + @plaintext[:body] << dob.obj + p_num << break_line + elsif dob.is==:break + sp=' ' + ln='-' + @plaintext[:body] <<=if dob.obj==Mx[:br_page] \ + or dob.obj==Mx[:br_page_new] \ + or dob.obj==Mx[:br_page_line] + "#{break_line}#{ln*40}#{break_line*2}" + elsif dob.obj ==Mx[:br_obj] + "#{break_line}#{sp*20}* * *#{break_line*2}" + end # following empty line (break_line) missing, fix + end + dob='' if (dob.obj =~// \ + and dob.obj =~/^(-\{{2}~\d+|)/) # -endnote + if dob ## Clean Prepared Text + dob.obj=dob.obj.gsub(//,' '). + gsub(/<:\S+>/,' ') + end + end + end + @plaintext + end + def publish(plaintext) + divider='=' + content=[] + content << plaintext[:open] + content << plaintext[:head] + content << plaintext[:body] + content << @@endnotes[:end] if @@endnotes_ + content << "#{break_line}#{divider*@wrap_width}#{break_line}" + content << plaintext[:metadata] + content << "#{break_line}#{divider*@wrap_width}#{break_line}" if @md.stmp =~/\w+/ #not used? + content << plaintext[:tail] + Output.new(content,@md).asciidoc + @@endnotes={ para: [], end: [] } + end + end + class Output 0 + para.each do |line| + if line + line=line.gsub(/[ \t]+$/m,''). + gsub(/^\A[ ]*\Z/m,'') + (line=~/^\A\Z/) \ + ? (emptyline+=1) + : emptyline=0 + if emptyline < 2 #remove additional empty lines + file_plaintext.puts line + end + end + end + else file_plaintext.puts para #unix plaintext # /^([*=-]|\.){5}/ + end + end + file_plaintext.close + end + end + end +end +__END__ diff --git a/lib/sisu/v5/urls.rb b/lib/sisu/v5/urls.rb index 16c753ee..4e1b3d8e 100644 --- a/lib/sisu/v5/urls.rb +++ b/lib/sisu/v5/urls.rb @@ -115,6 +115,7 @@ module SiSU_Urls 'S --sisupod (sisupod)'=>@fn[:sisupod], 't --txt (Plain-text (endnotes))'=>@fn[:plain], ' --textile (textile txt)'=>@fn[:txt_textile], + ' --asciidoc (asciidoc txt)'=>@fn[:txt_asciidoc], 'x --xml-sax (XML sax type)'=>@fn[:sax], 'X --xml-dom (XML dom type)'=>@fn[:dom], ' --xml-scaffold-sisu (XML scaffold)'=>@fn[:xml_scaffold_structure_sisu], @@ -157,6 +158,9 @@ module SiSU_Urls def textile(x) SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"[#{@opt.f_pth[:lng_is]}] -#{x}","#{@prog.web_browser} file://#{@md.file.output_path.textile.dir}/#{@md.file.base_filename.textile}").result end + def asciidoc(x) + SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"[#{@opt.f_pth[:lng_is]}] -#{x}","#{@prog.web_browser} file://#{@md.file.output_path.asciidoc.dir}/#{@md.file.base_filename.asciidoc}").result + end def epub(x) SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"[#{@opt.f_pth[:lng_is]}] -#{x}","#{@prog.epub_viewer} #{@md.file.output_path.epub.dir}/#{@md.file.base_filename.epub}").result end @@ -318,6 +322,10 @@ module SiSU_Urls and @opt.act[:txt_textile][:set]==:on show.textile(x) end + if x=~/--asciidoc\b/ \ + and @opt.act[:txt_asciidoc][:set]==:on + show.asciidoc(x) + end if x=~/--xhtml\b/ \ and @opt.act[:xhtml][:set]==:on show.xhtml(x) -- cgit v1.2.3 From 66fde27a84a4fca7b93d08cc7ceda19400e8f9ad Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Tue, 3 Dec 2013 00:22:22 -0500 Subject: v5: plaintext, smarttext: markdown --- lib/sisu/v5/constants.rb | 1 + lib/sisu/v5/hub.rb | 5 + lib/sisu/v5/manifest.rb | 8 + lib/sisu/v5/options.rb | 5 + lib/sisu/v5/sysenv.rb | 66 +++++ lib/sisu/v5/txt_markdown.rb | 588 ++++++++++++++++++++++++++++++++++++++++++++ lib/sisu/v5/urls.rb | 8 + 7 files changed, 681 insertions(+) create mode 100644 lib/sisu/v5/txt_markdown.rb (limited to 'lib') diff --git a/lib/sisu/v5/constants.rb b/lib/sisu/v5/constants.rb index f8aedf19..4f7f02a2 100644 --- a/lib/sisu/v5/constants.rb +++ b/lib/sisu/v5/constants.rb @@ -66,6 +66,7 @@ Sfx={ txt: '.txt', txt_textile: '.textile', txt_asciidoc: '.asciidoc.txt', + txt_markdown: '.md', html: '.html', xhtml: '.xhtml', xml: '.xml', diff --git a/lib/sisu/v5/hub.rb b/lib/sisu/v5/hub.rb index 6546de4c..9ef005bd 100644 --- a/lib/sisu/v5/hub.rb +++ b/lib/sisu/v5/hub.rb @@ -310,6 +310,10 @@ module SiSU require_relative 'txt_asciidoc' # txt_asciidoc.rb SiSU_Txt_asciiDoc::Source.new(@opt).read end + if @opt.act[:txt_markdown][:set]==:on #% --markdown + require_relative 'txt_markdown' # txt_markdown.rb + SiSU_Txt_Markdown::Source.new(@opt).read + end if @opt.act[:html][:set]==:on #% --html, -h -H require_relative 'html' # html.rb SiSU_HTML::Source.new(@opt).read @@ -647,6 +651,7 @@ module SiSU || @opt.act[:txt][:set]==:on \ || @opt.act[:txt_textile][:set]==:on \ || @opt.act[:txt_asciidoc][:set]==:on \ + || @opt.act[:txt_markdown][:set]==:on \ || @opt.act[:html][:set]==:on \ || @opt.act[:html_scroll][:set]==:on \ || @opt.act[:html_seg][:set]==:on \ diff --git a/lib/sisu/v5/manifest.rb b/lib/sisu/v5/manifest.rb index 821b8fab..d2e4d7f2 100644 --- a/lib/sisu/v5/manifest.rb +++ b/lib/sisu/v5/manifest.rb @@ -455,6 +455,14 @@ module SiSU_Manifest file=@f.base_filename.asciidoc summarize(id,file,pth,rel,url) end + if FileTest.file?(@f.place_file.markdown.dir)==true + id='Markdown text (UTF-8)' + pth=@f.output_path.markdown.dir + rel=@f.output_path.markdown.rel_sm + url=@f.output_path.markdown.url + file=@f.base_filename.markdown + summarize(id,file,pth,rel,url) + end if FileTest.file?("#{@base_path}/#{@md.fns}.tex")==true id,file='LaTeX (portrait)',"#{@md.fns}.tex" pth,rel,url='','','' diff --git a/lib/sisu/v5/options.rb b/lib/sisu/v5/options.rb index 3995a1b4..24b75b29 100644 --- a/lib/sisu/v5/options.rb +++ b/lib/sisu/v5/options.rb @@ -881,6 +881,9 @@ module SiSU_Commandline act[:txt_asciidoc]=(mod.inspect =~/"--asciidoc"/) \ ? { bool: true, set: :on } : { bool: false, set: :na } + act[:txt_markdown]=(mod.inspect =~/"--markdown"/) \ + ? { bool: true, set: :on } + : { bool: false, set: :na } act[:manpage]=(cmd =~/i/ \ || mod.inspect =~/"--manpage"|"--man"/) \ ? { bool: true, set: :on } @@ -972,6 +975,7 @@ module SiSU_Commandline elsif (act[:txt][:set]==:on \ || act[:txt_textile][:set]==:on \ || act[:txt_asciidoc][:set]==:on \ + || act[:txt_markdown][:set]==:on \ || act[:xhtml][:set]==:on \ || act[:epub][:set]==:on \ || act[:html][:set]==:on \ @@ -1018,6 +1022,7 @@ module SiSU_Commandline elsif (act[:txt][:set]==:on \ || act[:txt_textile][:set]==:on \ || act[:txt_asciidoc][:set]==:on \ + || act[:txt_markdown][:set]==:on \ || act[:xhtml][:set]==:on \ || act[:epub][:set]==:on \ || act[:html][:set]==:on \ diff --git a/lib/sisu/v5/sysenv.rb b/lib/sisu/v5/sysenv.rb index da992173..410d1a2c 100644 --- a/lib/sisu/v5/sysenv.rb +++ b/lib/sisu/v5/sysenv.rb @@ -1502,6 +1502,12 @@ module SiSU_Env ? @rc['asciidoc']['ocn'] : false end + def markdown_ocn? + ((defined? @rc['markdown']['ocn']) \ + && @rc['markdown']['ocn']==true) \ + ? @rc['markdown']['ocn'] + : false + end def widget #needs (md) #move @rc=SiSU_Env::GetInit.new.sisu_yaml.rc @ad=SiSU_Env::GetInit.new.ads @@ -3013,6 +3019,9 @@ WOK if @md.opt.act[:txt_asciidoc][:set]==:on #% --asciidoc ft << @md.fn[:txt_asciidoc] end + if @md.opt.act[:txt_markdown][:set]==:on #% --markdown + ft << @md.fn[:txt_markdown] + end if @md.opt.act[:xhtml][:set]==:on #% --xhtml, -b xhtml ft << @md.fn[:xhtml] end @@ -3069,6 +3078,9 @@ WOK if @opt.act[:txt_asciidoc][:set]==:on #% --asciidoc ft << 'plain.txt' << '??.plain.txt' << 'plain.??.txt' end + if @opt.act[:txt_markdown][:set]==:on #% --markdown + ft << 'plain.txt' << '??.plain.txt' << 'plain.??.txt' + end if @opt.act[:xhtml][:set]==:on #% --xhtml, -b xhtml ft << 'scroll.xhtml' << '??.scroll.xhtml' << 'scroll.??.xhtml' end @@ -4408,6 +4420,12 @@ WOK fn=base_filename.asciidoc make_file(path,fn) end + def markdown + path=output_path.markdown.dir + make_path(path) + fn=base_filename.markdown + make_file(path,fn) + end def html_scroll pth=output_path.html.dir make_path(pth) @@ -4547,6 +4565,15 @@ WOK end self end + def markdown + def dir + output_path.markdown.dir + '/' + base_filename.markdown + end + def rel + output_path.markdown.rel + '/' + base_filename.markdown + end + self + end def html_scroll def dir output_path.html_scroll.dir + '/' + base_filename.html_scroll @@ -4874,6 +4901,24 @@ WOK end i18n(fnh) end + def markdown(fh=nil) + fh=default_hash_build(fh,Sfx[:txt_markdown]) + fh[:lng]=lang_code?(fh[:lng]) + fnh=if output_dir_structure.by_filename? + { + fn: 'plain', + ft: fh[:ft], + lng: fh[:lng], + } + else + { + fn: fh[:fn], + ft: fh[:ft], + lng: fh[:lng], + } + end + i18n(fnh) + end def html_scroll(fh=nil) fh=default_hash_build(fh,Sfx[:html]) fh[:lng]=lang_code?(fh[:lng]) @@ -5692,6 +5737,27 @@ WOK end self end + def markdown + def ft + 'markdown_CONSTRUCTION_ZONE' + end + def dir + set_path(ft).dir.abc + end + def url + set_path(ft).url.abc + end + def rel + set_path(ft).rel.abc + end + def rcp + set_path(ft).rcp.abc + end + def rel_sm + set_path(ft).rel_sm.ab + end + self + end def html_scroll def ft 'html' diff --git a/lib/sisu/v5/txt_markdown.rb b/lib/sisu/v5/txt_markdown.rb new file mode 100644 index 00000000..89ee022d --- /dev/null +++ b/lib/sisu/v5/txt_markdown.rb @@ -0,0 +1,588 @@ +# 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: plaintext (smarttext) generation, markdown + +=end +module SiSU_Txt_Markdown + require_relative 'ao' # ao.rb + require_relative 'sysenv' # sysenv.rb + include SiSU_Env + require_relative 'shared_metadata' # shared_metadata.rb + require_relative 'txt_shared' # txt_shared.rb + include SiSU_Param + include SiSU_Viz + @@alt_id_count,@@alt_id_count,@@tablehead,@@number_of_cols=0,0,0,0 + @@tablefoot='' + class Source + def initialize(opt) + @opt=opt + unless @opt.fns =~/(.+?)\.(?:-|ssm\.)?sst$/ + puts "#{sf} not a processed file type" + end + end + def read + begin + md=SiSU_Param::Parameters.new(@opt).get + env=SiSU_Env::InfoEnv.new(@opt.fns) + 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.text_editor} #{md.file.output_path.markdown.dir}/#{md.file.base_filename.markdown}" + : "[#{@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],'Markdown (plaintext utf-8)',tool).green_hi_blue + : SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'Markdown (plaintext utf-8)',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,"#{md.file.output_path.markdown.dir}/#{md.file.base_filename.markdown}").flow + end + end + ao_array=SiSU_AO::Source.new(@opt).get # ao file drawn here + wrap_width=if defined? md.make.plaintext_wrap \ + and md.make.plaintext_wrap + md.make.plaintext_wrap + elsif defined? env.plaintext_wrap \ + and env.plaintext_wrap + env.plaintext_wrap + else 78 + end + #wrap_width=(defined? md.make.plaintext_wrap) ? md.make.plaintext_wrap : 78 + SiSU_Txt_Markdown::Source::Scroll.new(md,ao_array,wrap_width).songsheet + rescue + SiSU_Errors::Rescued.new($!,$@,@opt.cmd,@opt.fns).location do + __LINE__.to_s + ':' + __FILE__ + end + ensure + end + end + private + class Scroll appropriately within plaintext, consider + n=n.dup.to_s + if n =~/#{Mx[:br_line]}|#{Mx[:br_nl]}/ + fix = n.split(/#{Mx[:br_line]}|#{Mx[:br_nl]}/) #watch #added + fix.each do |x| + unless x.empty?; @n << x + end + end + else @n << n + end + end + notes=@n.flatten + notes.each do |e| + util=(e.to_s =~/^\[[\d*+]+\]:/) \ + ? (SiSU_TextUtils::Wrap.new(e.to_s,@wrap_width,4,1)) + : (SiSU_TextUtils::Wrap.new(e.to_s,@wrap_width,1,1)) + wrap=util.line_wrap + wrap=if wrap =~ /^\s*[\d*+]+\s+.+?\s*\Z/m + wrap.gsub(/^(\s*)([\d*+]+)\s+(.+?)\s*\Z/m, <<-GSUB +\\1[\\2]: \\3 + GSUB + ) + else + wrap.gsub(/^(.+)\Z/m, <<-GSUB +\\1 + GSUB + ) + end + @@endnotes[:para] << "-#{wrap}" + @@endnotes[:end] << '' << wrap + end + @@endnotes + end + def plaintext_metadata + array=SiSU_Metadata::Summary.new(@md).plaintext.metadata + array.each do |meta| + tag,inf=meta.scan(/^.+?:\s|.+/) + if tag and inf + util=SiSU_TextUtils::Wrap.new(inf,@wrap_width,15,1) + txt=util.line_wrap + @plaintext[:metadata] <<< @wrap_width + case dob.lc + when 1 then decorate.heading.underscore.l1*times + p_num << break_line*2 + when 2 then decorate.heading.underscore.l2*times + p_num << break_line*2 + when 3 then decorate.heading.underscore.l3*times + p_num << break_line*2 + when 4 then decorate.heading.underscore.l4*times + p_num << break_line*2 + when 5 then decorate.heading.underscore.l5*times + p_num << break_line*2 + when 6 then decorate.heading.underscore.l6*times + p_num << break_line*2 + end + end + end + def plaintext_structure(dob='',p_num='') #% Used to extract the structure of a document + heading_decoration=:inline #(:inline|:underscore) #switch heading decoration between inline & underscore options + util=nil + wrapped=if dob.is==:para \ + || dob.is==:heading + if dob.is==:heading + util=(heading_decoration== :inline) \ + ? (SiSU_TextUtils::Wrap.new(heading_decorated_inline(dob),@wrap_width,0)) + : (SiSU_TextUtils::Wrap.new(dob.obj,@wrap_width,0)) + elsif dob.is==:para + if dob.hang \ + and dob.hang =~/[0-9]/ \ + and dob.indent != dob.hang + util=SiSU_TextUtils::Wrap.new(dob.obj,@wrap_width,dob.indent.to_i*2,dob.hang.to_i*2) + #util=SiSU_TextUtils::Wrap.new(dob.obj,@wrap_width,dob.hang.to_i*2,0) + elsif dob.indent =~/[1-9]/ + util=if dob.bullet_ + SiSU_TextUtils::Wrap.new("* #{dob.obj}",@wrap_width,dob.indent.to_i*2) + else SiSU_TextUtils::Wrap.new(dob.obj,@wrap_width,dob.indent.to_i*2) + end + else + util=if dob.bullet_ + SiSU_TextUtils::Wrap.new("* #{dob.obj}",@wrap_width,0) + else SiSU_TextUtils::Wrap.new(dob.obj,@wrap_width,0) + end + end + else util=SiSU_TextUtils::Wrap.new(dob.obj,@wrap_width,0) + end + dob.is==:heading ? util.no_wrap_no_breaks : util.line_wrap + end + if heading_decoration== :underscore \ + and dob.is==:heading + @plaintext[:body] << wrapped + p_num # main text, contents, body KEEP + @plaintext[:body] << heading_decorated_underscore(dob,wrapped.length,p_num) + else + @plaintext[:body] << wrapped + p_num << break_line # main text, contents, body KEEP + end + if @@endnotes[:para] \ + and not @@endnotes_ + @@endnotes[:para].each {|e| @plaintext[:body] << e << break_line} + elsif @@endnotes[:para] \ + and @@endnotes_ + end + @@endnotes[:para]=[] + end + def markup(data) # Used for major markup instructions + SiSU_Env::InfoEnv.new(@md.fns) + @data_mod,@endnotes,@level,@cont,@copen,@plaintext_contents_close=Array.new(6){[]} + (0..6).each { |x| @cont[x]=@level[x]=false } + (4..6).each { |x| @plaintext_contents_close[x]='' } + plaintext_tail #($1,$2) + plaintext_metadata + table_message='[table conversion awaited, see other document formats]' + data.each do |dob| + dob.obj=dob.obj.gsub(/#{Mx[:gr_o]}Th?#{Mx[:tc_p]}.+/um,"#{break_line}#{table_message}"). #fix + gsub(/.+?#{Mx[:gl_o]}-##{Mx[:gl_c]}/,''). # remove dummy headings (used by html) #check also [~-]# + gsub(/#{Mx[:fa_bold_o]}(.+?)#{Mx[:fa_bold_c]}/, + "#{decorate.bold.open}\\1#{decorate.bold.close}"). + gsub(/#{Mx[:fa_italics_o]}(.+?)#{Mx[:fa_italics_c]}/, + "#{decorate.italics.open}\\1#{decorate.italics.close}"). + gsub(/#{Mx[:fa_underscore_o]}(.+?)#{Mx[:fa_underscore_c]}/, + "#{decorate.underscore.open}\\1#{decorate.underscore.close}"). + gsub(/#{Mx[:fa_subscript_o]}(.+?)#{Mx[:fa_subscript_c]}/, + "#{decorate.subscript.open}\\1#{decorate.subscript.close}"). + gsub(/#{Mx[:fa_superscript_o]}(.+?)#{Mx[:fa_superscript_c]}/, + "#{decorate.superscript.open}\\1#{decorate.superscript.close}"). + gsub(/#{Mx[:fa_insert_o]}(.+?)#{Mx[:fa_insert_c]}/, + "#{decorate.insert.open}\\1#{decorate.insert.close}"). + gsub(/#{Mx[:fa_cite_o]}(.+?)#{Mx[:fa_cite_c]}/, + "#{decorate.cite.open}\\1#{decorate.cite.close}"). + gsub(/#{Mx[:fa_strike_o]}(.+?)#{Mx[:fa_strike_c]}/, + "#{decorate.strike.open}\\1#{decorate.strike.close}"). + gsub(/#{Mx[:fa_monospace_o]}(.+?)#{Mx[:fa_monospace_c]}/, + "#{decorate.monospace.open}\\1#{decorate.monospace.close}") + unless dob.is==:code + dob.obj=dob.obj.gsub(/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}/,'\1'). + gsub(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/,'\1'). + gsub(/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,'\1 [link: <\2>]'). + gsub(/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}image/,'\1 [link: local image]'). + gsub(/#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,"#{@brace_url.txt_open}\\1#{@brace_url.txt_close}") + extract_endnotes(dob) + dob.obj=dob.obj.gsub(/#{Mx[:en_a_o]}([\d*+]+)\s+(?:.+?)#{Mx[:en_a_c]}/,'[^\1]'). # endnote marker marked up + gsub(/#{Mx[:en_b_o]}([\d*+]+)\s+(?:.+?)#{Mx[:en_b_c]}/,'[^\1]'). # endnote marker marked up + gsub(/#{Mx[:gl_o]}(?:#lt|#060)#{Mx[:gl_c]}/,'<'). + gsub(/#{Mx[:gl_o]}(?:#gt|#062)#{Mx[:gl_c]}/,'>'). + gsub(/#{Mx[:gl_o]}#(?:038|amp)#{Mx[:gl_c]}/,'&'). + gsub(/#{Mx[:gl_o]}#033#{Mx[:gl_c]}/,'!'). + gsub(/#{Mx[:gl_o]}#035#{Mx[:gl_c]}/,'#'). + gsub(/#{Mx[:gl_o]}#042#{Mx[:gl_c]}/,'*'). + gsub(/#{Mx[:gl_o]}#045#{Mx[:gl_c]}/,'-'). + gsub(/#{Mx[:gl_o]}#047#{Mx[:gl_c]}/,'/'). + gsub(/#{Mx[:gl_o]}#095#{Mx[:gl_c]}/,'_'). + gsub(/#{Mx[:gl_o]}#123#{Mx[:gl_c]}/,'{'). + gsub(/#{Mx[:gl_o]}#125#{Mx[:gl_c]}/,'}'). + gsub(/#{Mx[:gl_o]}#126#{Mx[:gl_c]}/,'~'). + gsub(/#{Mx[:gl_o]}#169#{Mx[:gl_c]}/,'©'). + gsub(/#{Mx[:gl_o]}#092#{Mx[:gl_c]}/,'\\') + end + dob.obj=if dob.of==:block # watch + dob.obj.gsub(/#{Mx[:gl_o]}●#{Mx[:gl_c]}/m,"* "). + gsub(/\n?#{Mx[:br_line]}\n?|\n?#{Mx[:br_nl]}\n?/m,break_line) + else dob.obj.gsub(/\n?#{Mx[:br_line]}\n?|\n?#{Mx[:br_nl]}\n?/m,break_line*2) + end + if dob.is==:code + dob.obj=dob.obj.gsub(/(^|[^}])_([<>])/m,'\1\2'). # _> _< + gsub(/(^|[^}])_([<>])/m,'\1\2') # _<_< + end + dob.obj=dob.obj.gsub(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/,'\1'). + gsub(/(.+?)<\/a>/m,'\1'). + gsub(/#{Mx[:mk_o]}:name#(\S+?)#{Mx[:mk_c]}/,''). # remove name links + gsub(/ |#{Mx[:nbsp]}/,' '). # decide on + gsub(/(?:^|[^_\\])#{Mx[:lnk_o]}(\S+?\.(?:png|jpg|gif)) .+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/,' [ \1 ]'). #"[ #{dir.url.images_local}\/\\1 ]") + gsub(/(?:^|[^_\\])#{Mx[:lnk_o]}(\S+?\.(?:png|jpg|gif)) .+?#{Mx[:lnk_c]}image/,' [ \1 ]'). + gsub(/(?:^|[^_\\])\{\s*\S+?\.(?:png|jpg|gif)\s+.+?"(.*?)"\s*\}\S+/,'[image: "\1"]') + if dob.obj !~/(^#{Rx[:meta]}|#{Mx[:br_eof]}|#{Mx[:br_endnotes]})/ + p_num='' + #ocn + if dob.is==:heading \ + or dob.is==:para + plaintext_structure(dob,p_num) + elsif dob.is==:group \ + or dob.is==:block \ + or dob.is==:verse \ + or dob.is==:code \ + or dob.is==:table + @plaintext[:body] << dob.obj + p_num << break_line + elsif dob.is==:break + sp=' ' + ln='-' + @plaintext[:body] <<=if dob.obj==Mx[:br_page] \ + or dob.obj==Mx[:br_page_new] \ + or dob.obj==Mx[:br_page_line] + "#{break_line}#{ln*40}#{break_line*2}" + elsif dob.obj ==Mx[:br_obj] + "#{break_line}#{sp*20}* * *#{break_line*2}" + end # following empty line (break_line) missing, fix + end + dob='' if (dob.obj =~// \ + and dob.obj =~/^(-\{{2}~\d+|)/) # -endnote + if dob ## Clean Prepared Text + dob.obj=dob.obj.gsub(//,' '). + gsub(/<:\S+>/,' ') + end + end + end + @plaintext + end + def publish(plaintext) + divider='=' + content=[] + content << plaintext[:open] + content << plaintext[:head] + content << plaintext[:body] + content << @@endnotes[:end] if @@endnotes_ + content << "#{break_line}#{divider*@wrap_width}#{break_line}" + content << plaintext[:metadata] + content << "#{break_line}#{divider*@wrap_width}#{break_line}" if @md.stmp =~/\w+/ #not used? + content << plaintext[:tail] + Output.new(content,@md).markdown + @@endnotes={ para: [], end: [] } + end + end + class Output 0 + para.each do |line| + if line + line=line.gsub(/[ \t]+$/m,''). + gsub(/^\A[ ]*\Z/m,'') + (line=~/^\A\Z/) \ + ? (emptyline+=1) + : emptyline=0 + if emptyline < 2 #remove additional empty lines + file_plaintext.puts line + end + end + end + else file_plaintext.puts para #unix plaintext # /^([*=-]|\.){5}/ + end + end + file_plaintext.close + end + end + end +end +__END__ diff --git a/lib/sisu/v5/urls.rb b/lib/sisu/v5/urls.rb index 4e1b3d8e..7da71137 100644 --- a/lib/sisu/v5/urls.rb +++ b/lib/sisu/v5/urls.rb @@ -116,6 +116,7 @@ module SiSU_Urls 't --txt (Plain-text (endnotes))'=>@fn[:plain], ' --textile (textile txt)'=>@fn[:txt_textile], ' --asciidoc (asciidoc txt)'=>@fn[:txt_asciidoc], + ' --markdown (markdown txt)'=>@fn[:txt_markdown], 'x --xml-sax (XML sax type)'=>@fn[:sax], 'X --xml-dom (XML dom type)'=>@fn[:dom], ' --xml-scaffold-sisu (XML scaffold)'=>@fn[:xml_scaffold_structure_sisu], @@ -161,6 +162,9 @@ module SiSU_Urls def asciidoc(x) SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"[#{@opt.f_pth[:lng_is]}] -#{x}","#{@prog.web_browser} file://#{@md.file.output_path.asciidoc.dir}/#{@md.file.base_filename.asciidoc}").result end + def markdown(x) + SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"[#{@opt.f_pth[:lng_is]}] -#{x}","#{@prog.web_browser} file://#{@md.file.output_path.markdown.dir}/#{@md.file.base_filename.markdown}").result + end def epub(x) SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"[#{@opt.f_pth[:lng_is]}] -#{x}","#{@prog.epub_viewer} #{@md.file.output_path.epub.dir}/#{@md.file.base_filename.epub}").result end @@ -326,6 +330,10 @@ module SiSU_Urls and @opt.act[:txt_asciidoc][:set]==:on show.asciidoc(x) end + if x=~/--markdown\b/ \ + and @opt.act[:txt_markdown][:set]==:on + show.markdown(x) + end if x=~/--xhtml\b/ \ and @opt.act[:xhtml][:set]==:on show.xhtml(x) -- cgit v1.2.3 From 6c153f78e75df56bd7c5e04a58124a8d5427d5d7 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Tue, 3 Dec 2013 00:24:33 -0500 Subject: v5: plaintext, smarttext: rst --- lib/sisu/v5/constants.rb | 1 + lib/sisu/v5/hub.rb | 5 + lib/sisu/v5/manifest.rb | 8 + lib/sisu/v5/options.rb | 5 + lib/sisu/v5/sysenv.rb | 66 ++++++ lib/sisu/v5/txt_rst.rb | 550 +++++++++++++++++++++++++++++++++++++++++++++++ lib/sisu/v5/urls.rb | 8 + 7 files changed, 643 insertions(+) create mode 100644 lib/sisu/v5/txt_rst.rb (limited to 'lib') diff --git a/lib/sisu/v5/constants.rb b/lib/sisu/v5/constants.rb index 4f7f02a2..1b97b67f 100644 --- a/lib/sisu/v5/constants.rb +++ b/lib/sisu/v5/constants.rb @@ -67,6 +67,7 @@ Sfx={ txt_textile: '.textile', txt_asciidoc: '.asciidoc.txt', txt_markdown: '.md', + txt_rst: '.rst', html: '.html', xhtml: '.xhtml', xml: '.xml', diff --git a/lib/sisu/v5/hub.rb b/lib/sisu/v5/hub.rb index 9ef005bd..755a13dd 100644 --- a/lib/sisu/v5/hub.rb +++ b/lib/sisu/v5/hub.rb @@ -314,6 +314,10 @@ module SiSU require_relative 'txt_markdown' # txt_markdown.rb SiSU_Txt_Markdown::Source.new(@opt).read end + if @opt.act[:txt_rst][:set]==:on #% --rst, --rest + require_relative 'txt_rst' # txt_rst.rb + SiSU_Txt_rST::Source.new(@opt).read + end if @opt.act[:html][:set]==:on #% --html, -h -H require_relative 'html' # html.rb SiSU_HTML::Source.new(@opt).read @@ -652,6 +656,7 @@ module SiSU || @opt.act[:txt_textile][:set]==:on \ || @opt.act[:txt_asciidoc][:set]==:on \ || @opt.act[:txt_markdown][:set]==:on \ + || @opt.act[:txt_rst][:set]==:on \ || @opt.act[:html][:set]==:on \ || @opt.act[:html_scroll][:set]==:on \ || @opt.act[:html_seg][:set]==:on \ diff --git a/lib/sisu/v5/manifest.rb b/lib/sisu/v5/manifest.rb index d2e4d7f2..61da6080 100644 --- a/lib/sisu/v5/manifest.rb +++ b/lib/sisu/v5/manifest.rb @@ -463,6 +463,14 @@ module SiSU_Manifest file=@f.base_filename.markdown summarize(id,file,pth,rel,url) end + if FileTest.file?(@f.place_file.rst.dir)==true + id='rST text (UTF-8)' + pth=@f.output_path.rst.dir + rel=@f.output_path.rst.rel_sm + url=@f.output_path.rst.url + file=@f.base_filename.rst + summarize(id,file,pth,rel,url) + end if FileTest.file?("#{@base_path}/#{@md.fns}.tex")==true id,file='LaTeX (portrait)',"#{@md.fns}.tex" pth,rel,url='','','' diff --git a/lib/sisu/v5/options.rb b/lib/sisu/v5/options.rb index 24b75b29..2f6b9a0b 100644 --- a/lib/sisu/v5/options.rb +++ b/lib/sisu/v5/options.rb @@ -884,6 +884,9 @@ module SiSU_Commandline act[:txt_markdown]=(mod.inspect =~/"--markdown"/) \ ? { bool: true, set: :on } : { bool: false, set: :na } + act[:txt_rst]=(mod.inspect =~/"--rst"|"--rest"|"--restructuredtext"/) \ + ? { bool: true, set: :on } + : { bool: false, set: :na } act[:manpage]=(cmd =~/i/ \ || mod.inspect =~/"--manpage"|"--man"/) \ ? { bool: true, set: :on } @@ -976,6 +979,7 @@ module SiSU_Commandline || act[:txt_textile][:set]==:on \ || act[:txt_asciidoc][:set]==:on \ || act[:txt_markdown][:set]==:on \ + || act[:txt_rst][:set]==:on \ || act[:xhtml][:set]==:on \ || act[:epub][:set]==:on \ || act[:html][:set]==:on \ @@ -1023,6 +1027,7 @@ module SiSU_Commandline || act[:txt_textile][:set]==:on \ || act[:txt_asciidoc][:set]==:on \ || act[:txt_markdown][:set]==:on \ + || act[:txt_rst][:set]==:on \ || act[:xhtml][:set]==:on \ || act[:epub][:set]==:on \ || act[:html][:set]==:on \ diff --git a/lib/sisu/v5/sysenv.rb b/lib/sisu/v5/sysenv.rb index 410d1a2c..094df7fd 100644 --- a/lib/sisu/v5/sysenv.rb +++ b/lib/sisu/v5/sysenv.rb @@ -1508,6 +1508,12 @@ module SiSU_Env ? @rc['markdown']['ocn'] : false end + def rst_ocn? + ((defined? @rc['rst']['ocn']) \ + && @rc['rst']['ocn']==true) \ + ? @rc['rst']['ocn'] + : false + end def widget #needs (md) #move @rc=SiSU_Env::GetInit.new.sisu_yaml.rc @ad=SiSU_Env::GetInit.new.ads @@ -3022,6 +3028,9 @@ WOK if @md.opt.act[:txt_markdown][:set]==:on #% --markdown ft << @md.fn[:txt_markdown] end + if @md.opt.act[:txt_rst][:set]==:on #% --rst, --rest + ft << @md.fn[:txt_rst] + end if @md.opt.act[:xhtml][:set]==:on #% --xhtml, -b xhtml ft << @md.fn[:xhtml] end @@ -3081,6 +3090,9 @@ WOK if @opt.act[:txt_markdown][:set]==:on #% --markdown ft << 'plain.txt' << '??.plain.txt' << 'plain.??.txt' end + if @opt.act[:txt_rst][:set]==:on #% --rst, --rest + ft << 'plain.txt' << '??.plain.txt' << 'plain.??.txt' + end if @opt.act[:xhtml][:set]==:on #% --xhtml, -b xhtml ft << 'scroll.xhtml' << '??.scroll.xhtml' << 'scroll.??.xhtml' end @@ -4426,6 +4438,12 @@ WOK fn=base_filename.markdown make_file(path,fn) end + def rst + path=output_path.rst.dir + make_path(path) + fn=base_filename.rst + make_file(path,fn) + end def html_scroll pth=output_path.html.dir make_path(pth) @@ -4574,6 +4592,15 @@ WOK end self end + def rst + def dir + output_path.rst.dir + '/' + base_filename.rst + end + def rel + output_path.rst.rel + '/' + base_filename.rst + end + self + end def html_scroll def dir output_path.html_scroll.dir + '/' + base_filename.html_scroll @@ -4919,6 +4946,24 @@ WOK end i18n(fnh) end + def rst(fh=nil) + fh=default_hash_build(fh,Sfx[:txt_rst]) + fh[:lng]=lang_code?(fh[:lng]) + fnh=if output_dir_structure.by_filename? + { + fn: 'plain', + ft: fh[:ft], + lng: fh[:lng], + } + else + { + fn: fh[:fn], + ft: fh[:ft], + lng: fh[:lng], + } + end + i18n(fnh) + end def html_scroll(fh=nil) fh=default_hash_build(fh,Sfx[:html]) fh[:lng]=lang_code?(fh[:lng]) @@ -5758,6 +5803,27 @@ WOK end self end + def rst + def ft + 'rst_CONSTRUCTION_ZONE' + end + def dir + set_path(ft).dir.abc + end + def url + set_path(ft).url.abc + end + def rel + set_path(ft).rel.abc + end + def rcp + set_path(ft).rcp.abc + end + def rel_sm + set_path(ft).rel_sm.ab + end + self + end def html_scroll def ft 'html' diff --git a/lib/sisu/v5/txt_rst.rb b/lib/sisu/v5/txt_rst.rb new file mode 100644 index 00000000..c98bb275 --- /dev/null +++ b/lib/sisu/v5/txt_rst.rb @@ -0,0 +1,550 @@ +# 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: plaintext (smarttext) generation, rST + +=end +module SiSU_Txt_rST + require_relative 'ao' # ao.rb + require_relative 'sysenv' # sysenv.rb + include SiSU_Env + require_relative 'shared_metadata' # shared_metadata.rb + require_relative 'txt_shared' # txt_shared.rb + include SiSU_Param + include SiSU_Viz + @@alt_id_count,@@alt_id_count,@@tablehead,@@number_of_cols=0,0,0,0 + @@tablefoot='' + class Source + def initialize(opt) + @opt=opt + unless @opt.fns =~/(.+?)\.(?:-|ssm\.)?sst$/ + puts "#{sf} not a processed file type" + end + end + def read + begin + md=SiSU_Param::Parameters.new(@opt).get + env=SiSU_Env::InfoEnv.new(@opt.fns) + 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.text_editor} #{md.file.output_path.rst.dir}/#{md.file.base_filename.rst}" + : "[#{@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],'rST (plaintext utf-8)',tool).green_hi_blue + : SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'rST (plaintext utf-8)',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,"#{md.file.output_path.rst.dir}/#{md.file.base_filename.rst}").flow + end + end + ao_array=SiSU_AO::Source.new(@opt).get # ao file drawn here + wrap_width=if defined? md.make.plaintext_wrap \ + and md.make.plaintext_wrap + md.make.plaintext_wrap + elsif defined? env.plaintext_wrap \ + and env.plaintext_wrap + env.plaintext_wrap + else 78 + end + #wrap_width=(defined? md.make.plaintext_wrap) ? md.make.plaintext_wrap : 78 + SiSU_Txt_rST::Source::Scroll.new(md,ao_array,wrap_width).songsheet + rescue + SiSU_Errors::Rescued.new($!,$@,@opt.cmd,@opt.fns).location do + __LINE__.to_s + ':' + __FILE__ + end + ensure + end + end + private + class Scroll appropriately within plaintext, consider + n=n.dup.to_s + if n =~/#{Mx[:br_line]}|#{Mx[:br_nl]}/ + fix = n.split(/#{Mx[:br_line]}|#{Mx[:br_nl]}/) #watch #added + fix.each do |x| + unless x.empty?; @n << x + end + end + else @n << n + end + end + notes=@n.flatten + notes.each do |e| + util=(e.to_s =~/^\[[\d*+]+\]:/) \ + ? (SiSU_TextUtils::Wrap.new(e.to_s,@wrap_width,4,1)) + : (SiSU_TextUtils::Wrap.new(e.to_s,@wrap_width,1,1)) + wrap=util.line_wrap + wrap=if wrap =~ /^\s*[\d*+]+\s+.+?\s*\Z/m + wrap.gsub(/^(\s*)([\d*+]+)\s+(.+?)\s*\Z/m, <<-GSUB +\\1[\\2]: \\3 + GSUB + ) + else + wrap.gsub(/^(.+)\Z/m, <<-GSUB +\\1 + GSUB + ) + end + @@endnotes[:para] << "-#{wrap}" + @@endnotes[:end] << '' << wrap + end + @@endnotes + end + def plaintext_metadata + array=SiSU_Metadata::Summary.new(@md).plaintext.metadata + array.each do |meta| + tag,inf=meta.scan(/^.+?:\s|.+/) + if tag and inf + util=SiSU_TextUtils::Wrap.new(inf,@wrap_width,15,1) + txt=util.line_wrap + @plaintext[:metadata] <<< @wrap_width + case dob.lc + when 1 then decorate.heading.underscore.l1*times + p_num << break_line*2 + when 2 then decorate.heading.underscore.l2*times + p_num << break_line*2 + when 3 then decorate.heading.underscore.l3*times + p_num << break_line*2 + when 4 then decorate.heading.underscore.l4*times + p_num << break_line*2 + when 5 then decorate.heading.underscore.l5*times + p_num << break_line*2 + when 6 then decorate.heading.underscore.l6*times + p_num << break_line*2 + end + end + end + def plaintext_structure(dob='',p_num='') #% Used to extract the structure of a document + util=nil + wrapped=if dob.is==:para \ + || dob.is==:heading + if dob.is==:heading + util=SiSU_TextUtils::Wrap.new(dob.obj,@wrap_width,0) + elsif dob.is==:para + if dob.hang \ + and dob.hang =~/[0-9]/ \ + and dob.indent != dob.hang + util=SiSU_TextUtils::Wrap.new(dob.obj,@wrap_width,dob.indent.to_i*2,dob.hang.to_i*2) + #util=SiSU_TextUtils::Wrap.new(dob.obj,@wrap_width,dob.hang.to_i*2,0) + elsif dob.indent =~/[1-9]/ + util=if dob.bullet_ + SiSU_TextUtils::Wrap.new("* #{dob.obj}",@wrap_width,dob.indent.to_i*2) + else SiSU_TextUtils::Wrap.new(dob.obj,@wrap_width,dob.indent.to_i*2) + end + else + util=if dob.bullet_ + SiSU_TextUtils::Wrap.new("* #{dob.obj}",@wrap_width,0) + else SiSU_TextUtils::Wrap.new(dob.obj,@wrap_width,0) + end + end + else util=SiSU_TextUtils::Wrap.new(dob.obj,@wrap_width,0) + end + dob.is==:heading ? util.no_wrap_no_breaks : util.line_wrap + end + if dob.is==:heading + @plaintext[:body] << wrapped + p_num # main text, contents, body KEEP + @plaintext[:body] << heading_decorated_underscore(dob,wrapped.length,p_num) + else + @plaintext[:body] << wrapped + p_num << break_line # main text, contents, body KEEP + end + if @@endnotes[:para] \ + and not @@endnotes_ + @@endnotes[:para].each {|e| @plaintext[:body] << e << break_line} + elsif @@endnotes[:para] \ + and @@endnotes_ + end + @@endnotes[:para]=[] + end + def markup(data) # Used for major markup instructions + SiSU_Env::InfoEnv.new(@md.fns) + @data_mod,@endnotes,@level,@cont,@copen,@plaintext_contents_close=Array.new(6){[]} + (0..6).each { |x| @cont[x]=@level[x]=false } + (4..6).each { |x| @plaintext_contents_close[x]='' } + plaintext_tail #($1,$2) + plaintext_metadata + table_message='[table conversion awaited, see other document formats]' + data.each do |dob| + dob.obj=dob.obj.gsub(/#{Mx[:gr_o]}Th?#{Mx[:tc_p]}.+/um,"#{break_line}#{table_message}"). #fix + gsub(/.+?#{Mx[:gl_o]}-##{Mx[:gl_c]}/,''). # remove dummy headings (used by html) #check also [~-]# + gsub(/#{Mx[:fa_bold_o]}(.+?)#{Mx[:fa_bold_c]}/, + "#{decorate.bold.open}\\1#{decorate.bold.close}"). + gsub(/#{Mx[:fa_italics_o]}(.+?)#{Mx[:fa_italics_c]}/, + "#{decorate.italics.open}\\1#{decorate.italics.close}"). + gsub(/#{Mx[:fa_underscore_o]}(.+?)#{Mx[:fa_underscore_c]}/, + "#{decorate.underscore.open}\\1#{decorate.underscore.close}"). + gsub(/#{Mx[:fa_subscript_o]}(.+?)#{Mx[:fa_subscript_c]}/, + "#{decorate.subscript.open}\\1#{decorate.subscript.close}"). + gsub(/#{Mx[:fa_superscript_o]}(.+?)#{Mx[:fa_superscript_c]}/, + "#{decorate.superscript.open}\\1#{decorate.superscript.close}"). + gsub(/#{Mx[:fa_insert_o]}(.+?)#{Mx[:fa_insert_c]}/, + "#{decorate.insert.open}\\1#{decorate.insert.close}"). + gsub(/#{Mx[:fa_cite_o]}(.+?)#{Mx[:fa_cite_c]}/, + "#{decorate.cite.open}\\1#{decorate.cite.close}"). + gsub(/#{Mx[:fa_strike_o]}(.+?)#{Mx[:fa_strike_c]}/, + "#{decorate.strike.open}\\1#{decorate.strike.close}"). + gsub(/#{Mx[:fa_monospace_o]}(.+?)#{Mx[:fa_monospace_c]}/, + "#{decorate.monospace.open}\\1#{decorate.monospace.close}") + unless dob.is==:code + dob.obj=dob.obj.gsub(/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}/,'\1'). + gsub(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/,'\1'). + gsub(/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,'\1 [link: <\2>]'). + gsub(/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}image/,'\1 [link: local image]'). + gsub(/#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,"#{@brace_url.txt_open}\\1#{@brace_url.txt_close}") + extract_endnotes(dob) + dob.obj=dob.obj.gsub(/#{Mx[:en_a_o]}([\d*+]+)\s+(?:.+?)#{Mx[:en_a_c]}/,'[^\1]'). # endnote marker marked up + gsub(/#{Mx[:en_b_o]}([\d*+]+)\s+(?:.+?)#{Mx[:en_b_c]}/,'[^\1]'). # endnote marker marked up + gsub(/#{Mx[:gl_o]}(?:#lt|#060)#{Mx[:gl_c]}/,'<'). + gsub(/#{Mx[:gl_o]}(?:#gt|#062)#{Mx[:gl_c]}/,'>'). + gsub(/#{Mx[:gl_o]}#(?:038|amp)#{Mx[:gl_c]}/,'&'). + gsub(/#{Mx[:gl_o]}#033#{Mx[:gl_c]}/,'!'). + gsub(/#{Mx[:gl_o]}#035#{Mx[:gl_c]}/,'#'). + gsub(/#{Mx[:gl_o]}#042#{Mx[:gl_c]}/,'*'). + gsub(/#{Mx[:gl_o]}#045#{Mx[:gl_c]}/,'-'). + gsub(/#{Mx[:gl_o]}#047#{Mx[:gl_c]}/,'/'). + gsub(/#{Mx[:gl_o]}#095#{Mx[:gl_c]}/,'_'). + gsub(/#{Mx[:gl_o]}#123#{Mx[:gl_c]}/,'{'). + gsub(/#{Mx[:gl_o]}#125#{Mx[:gl_c]}/,'}'). + gsub(/#{Mx[:gl_o]}#126#{Mx[:gl_c]}/,'~'). + gsub(/#{Mx[:gl_o]}#169#{Mx[:gl_c]}/,'©'). + gsub(/#{Mx[:gl_o]}#092#{Mx[:gl_c]}/,'\\') + end + dob.obj=if dob.of==:block # watch + dob.obj.gsub(/#{Mx[:gl_o]}●#{Mx[:gl_c]}/m,"* "). + gsub(/\n?#{Mx[:br_line]}\n?|\n?#{Mx[:br_nl]}\n?/m,break_line) + else dob.obj.gsub(/\n?#{Mx[:br_line]}\n?|\n?#{Mx[:br_nl]}\n?/m,break_line*2) + end + if dob.is==:code + dob.obj=dob.obj.gsub(/(^|[^}])_([<>])/m,'\1\2'). # _> _< + gsub(/(^|[^}])_([<>])/m,'\1\2') # _<_< + end + dob.obj=dob.obj.gsub(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/,'\1'). + gsub(/(.+?)<\/a>/m,'\1'). + gsub(/#{Mx[:mk_o]}:name#(\S+?)#{Mx[:mk_c]}/,''). # remove name links + gsub(/ |#{Mx[:nbsp]}/,' '). # decide on + gsub(/(?:^|[^_\\])#{Mx[:lnk_o]}(\S+?\.(?:png|jpg|gif)) .+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/,' [ \1 ]'). #"[ #{dir.url.images_local}\/\\1 ]") + gsub(/(?:^|[^_\\])#{Mx[:lnk_o]}(\S+?\.(?:png|jpg|gif)) .+?#{Mx[:lnk_c]}image/,' [ \1 ]'). + gsub(/(?:^|[^_\\])\{\s*\S+?\.(?:png|jpg|gif)\s+.+?"(.*?)"\s*\}\S+/,'[image: "\1"]') + if dob.obj !~/(^#{Rx[:meta]}|#{Mx[:br_eof]}|#{Mx[:br_endnotes]})/ + p_num='' + #ocn + if dob.is==:heading \ + or dob.is==:para + plaintext_structure(dob,p_num) + elsif dob.is==:group \ + or dob.is==:block \ + or dob.is==:verse \ + or dob.is==:code \ + or dob.is==:table + @plaintext[:body] << dob.obj + p_num << break_line + elsif dob.is==:break + sp=' ' + ln='-' + @plaintext[:body] <<=if dob.obj==Mx[:br_page] \ + or dob.obj==Mx[:br_page_new] \ + or dob.obj==Mx[:br_page_line] + "#{break_line}#{ln*40}#{break_line*2}" + elsif dob.obj ==Mx[:br_obj] + "#{break_line}#{sp*20}* * *#{break_line*2}" + end # following empty line (break_line) missing, fix + end + dob='' if (dob.obj =~// \ + and dob.obj =~/^(-\{{2}~\d+|)/) # -endnote + if dob ## Clean Prepared Text + dob.obj=dob.obj.gsub(//,' '). + gsub(/<:\S+>/,' ') + end + end + end + @plaintext + end + def publish(plaintext) + divider='=' + content=[] + content << plaintext[:open] + content << plaintext[:head] + content << plaintext[:body] + content << @@endnotes[:end] if @@endnotes_ + content << "#{break_line}#{divider*@wrap_width}#{break_line}" + content << plaintext[:metadata] + content << "#{break_line}#{divider*@wrap_width}#{break_line}" if @md.stmp =~/\w+/ #not used? + content << plaintext[:tail] + Output.new(content,@md).rst + @@endnotes={ para: [], end: [] } + end + end + class Output 0 + para.each do |line| + if line + line=line.gsub(/[ \t]+$/m,''). + gsub(/^\A[ ]*\Z/m,'') + (line=~/^\A\Z/) \ + ? (emptyline+=1) + : emptyline=0 + if emptyline < 2 #remove additional empty lines + file_plaintext.puts line + end + end + end + else file_plaintext.puts para #unix plaintext # /^([*=-]|\.){5}/ + end + end + file_plaintext.close + end + end + end +end +__END__ diff --git a/lib/sisu/v5/urls.rb b/lib/sisu/v5/urls.rb index 7da71137..43ecd6cb 100644 --- a/lib/sisu/v5/urls.rb +++ b/lib/sisu/v5/urls.rb @@ -117,6 +117,7 @@ module SiSU_Urls ' --textile (textile txt)'=>@fn[:txt_textile], ' --asciidoc (asciidoc txt)'=>@fn[:txt_asciidoc], ' --markdown (markdown txt)'=>@fn[:txt_markdown], + ' --rst (rST restructured-text)'=>@fn[:txt_rst], 'x --xml-sax (XML sax type)'=>@fn[:sax], 'X --xml-dom (XML dom type)'=>@fn[:dom], ' --xml-scaffold-sisu (XML scaffold)'=>@fn[:xml_scaffold_structure_sisu], @@ -165,6 +166,9 @@ module SiSU_Urls def markdown(x) SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"[#{@opt.f_pth[:lng_is]}] -#{x}","#{@prog.web_browser} file://#{@md.file.output_path.markdown.dir}/#{@md.file.base_filename.markdown}").result end + def rst(x) + SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"[#{@opt.f_pth[:lng_is]}] -#{x}","#{@prog.web_browser} file://#{@md.file.output_path.rst.dir}/#{@md.file.base_filename.rst}").result + end def epub(x) SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"[#{@opt.f_pth[:lng_is]}] -#{x}","#{@prog.epub_viewer} #{@md.file.output_path.epub.dir}/#{@md.file.base_filename.epub}").result end @@ -334,6 +338,10 @@ module SiSU_Urls and @opt.act[:txt_markdown][:set]==:on show.markdown(x) end + if x=~/--rst\b/ \ + and @opt.act[:txt_rst][:set]==:on + show.rst(x) + end if x=~/--xhtml\b/ \ and @opt.act[:xhtml][:set]==:on show.xhtml(x) -- cgit v1.2.3 From c7f7a26587c9ae9e569eb46b4d90f93ff63984d6 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Tue, 3 Dec 2013 00:28:11 -0500 Subject: v5: xml, docbook --- lib/sisu/v5/constants.rb | 3 + lib/sisu/v5/hub.rb | 5 + lib/sisu/v5/manifest.rb | 14 +++ lib/sisu/v5/options.rb | 5 + lib/sisu/v5/sysenv.rb | 99 ++++++++++++++++ lib/sisu/v5/urls.rb | 8 ++ lib/sisu/v5/xml_docbook5.rb | 271 ++++++++++++++++++++++++++++++++++++++++++++ lib/sisu/v5/xml_shared.rb | 5 +- 8 files changed, 408 insertions(+), 2 deletions(-) create mode 100644 lib/sisu/v5/xml_docbook5.rb (limited to 'lib') diff --git a/lib/sisu/v5/constants.rb b/lib/sisu/v5/constants.rb index 1b97b67f..1f96f0aa 100644 --- a/lib/sisu/v5/constants.rb +++ b/lib/sisu/v5/constants.rb @@ -76,6 +76,9 @@ Sfx={ xml_scaffold: '.scaffold.xml', xml_scaffold_structure_sisu: '.scaffold.sisu.xml', xml_scaffold_structure_collapse: '.scaffold.collapse.xml', + xml_docbook: '.docbook.xml', + xml_docbook_article: '.article.docbook.xml', + xml_docbook_book: '.book.docbook.xml', epub: '.epub', epub_xhtml: '.xhtml', odt: '.odt', diff --git a/lib/sisu/v5/hub.rb b/lib/sisu/v5/hub.rb index 755a13dd..08147d96 100644 --- a/lib/sisu/v5/hub.rb +++ b/lib/sisu/v5/hub.rb @@ -355,6 +355,10 @@ module SiSU require_relative 'xml_scaffold_structure_collapsed' # xml_scaffold_structure_collapsed.rb SiSU_XML_Scaffold_Structure_Collapse::Source.new(@opt).read end + if @opt.act[:xml_docbook_book][:set]==:on #% --xml-docbook + require_relative 'xml_docbook5' # xml_docbook5.rb + SiSU_XML_Docbook_Book::Source.new(@opt).read + end if @opt.act[:xml_sax][:set]==:on #% --xml-sax, -x xml sax type require_relative 'xml_sax' # xml_sax.rb SiSU_XML_SAX::Source.new(@opt).read @@ -668,6 +672,7 @@ module SiSU || @opt.act[:xml_dom][:set]==:on \ || @opt.act[:xml_scaffold_structure_sisu][:set]==:on \ || @opt.act[:xml_scaffold_structure_collapse][:set]==:on \ + || @opt.act[:xml_docbook_book][:set]==:on \ || @opt.act[:pdf][:set]==:on \ || @opt.act[:pdf_p][:set]==:on \ || @opt.act[:pdf_l][:set]==:on \ diff --git a/lib/sisu/v5/manifest.rb b/lib/sisu/v5/manifest.rb index 61da6080..42755151 100644 --- a/lib/sisu/v5/manifest.rb +++ b/lib/sisu/v5/manifest.rb @@ -396,6 +396,20 @@ module SiSU_Manifest id,file='XML DOM',@f.base_filename.xml_dom summarize(id,file,pth,rel,url) end + if FileTest.file?(@f.place_file.xml_docbook_article.dir)==true + pth=@f.output_path.xml_docbook_article.dir + rel=@f.output_path.xml_docbook_article.rel_sm + url=@f.output_path.xml_docbook_article.url + id,file='XML Docbook Book',@f.base_filename.xml_docbook_article + summarize(id,file,pth,rel,url) + end + if FileTest.file?(@f.place_file.xml_docbook_book.dir)==true + pth=@f.output_path.xml_docbook_book.dir + rel=@f.output_path.xml_docbook_book.rel_sm + url=@f.output_path.xml_docbook_book.url + id,file='XML Docbook Book',@f.base_filename.xml_docbook_book + summarize(id,file,pth,rel,url) + end if FileTest.file?(@f.place_file.xml_scaffold_structure_sisu.dir)==true pth=@f.output_path.xml_scaffold_structure_sisu.dir rel=@f.output_path.xml_scaffold_structure_sisu.rel_sm diff --git a/lib/sisu/v5/options.rb b/lib/sisu/v5/options.rb index 2f6b9a0b..1e11b711 100644 --- a/lib/sisu/v5/options.rb +++ b/lib/sisu/v5/options.rb @@ -861,6 +861,9 @@ module SiSU_Commandline || mod.inspect =~/"--xml-dom"/) \ ? { bool: true, set: :on } : { bool: false, set: :na } + act[:xml_docbook_book]=mod.inspect =~/"--docbook"|"--docbook-book"|"--xml-docbook"|"--xml-docbook_book"/ \ + ? { bool: true, set: :on } + : { bool: false, set: :na } act[:xml_scaffold_structure_sisu]=mod.inspect =~/"--xml-scaffold"|"--xml-scaffold-sisu"/ \ ? { bool: true, set: :on } : { bool: false, set: :na } @@ -998,6 +1001,7 @@ module SiSU_Commandline || act[:concordance][:set]==:on \ || act[:xml_dom][:set]==:on \ || act[:xml_sax][:set]==:on \ + || act[:xml_docbook_book][:set]==:on \ || act[:xml_scaffold_structure_sisu][:set]==:on \ || act[:xml_scaffold_structure_collapse][:set]==:on ) { bool: true, set: :on } @@ -1046,6 +1050,7 @@ module SiSU_Commandline || act[:concordance][:set]==:on \ || act[:xml_dom][:set]==:on \ || act[:xml_sax][:set]==:on \ + || act[:xml_docbook_book][:set]==:on \ || act[:xml_scaffold_structure_sisu][:set]==:on \ || act[:xml_scaffold_structure_collapse][:set]==:on ) { bool: true, set: :on } diff --git a/lib/sisu/v5/sysenv.rb b/lib/sisu/v5/sysenv.rb index 094df7fd..f25cd027 100644 --- a/lib/sisu/v5/sysenv.rb +++ b/lib/sisu/v5/sysenv.rb @@ -1478,6 +1478,12 @@ module SiSU_Env ? @rc['odt']['ocn'] : true end + def xml_docbook_ocn? + ((defined? @rc['xml_docbook']['ocn']) \ + && @rc['xml_docbook']['ocn']==false) \ + ? @rc['xml_docbook']['ocn'] + : true + end def xml_scaffold_ocn? ((defined? @rc['xml_scaffold']['ocn']) \ && @rc['xml_scaffold']['ocn']==false) \ @@ -2760,6 +2766,12 @@ WOK ? @rc['program_select']['xml_viewer'] : text_editor end + def docbook_viewer + ((defined? @rc['program_select']['xml_viewer']) \ + && @rc['program_select']['xml_viewer'] =~/\S\S+/) \ + ? @rc['program_select']['xml_viewer'] + : text_editor + end def xml_editor xml_viewer end @@ -3061,6 +3073,9 @@ WOK if @md.opt.act[:xml_dom][:set]==:on #% --xml-dom, -X xml dom type ft << @md.fn[:dom] end + if @md.opt.act[:xml_docbook_book][:set]==:on #% --xml-docbook-book + ft << @md.fn[:xml_docbook_book] + end if @md.opt.act[:xml_scaffold_structure_sisu][:set]==:on #% --xml-scaffold --xml-scaffold-sisu ft << @md.fn[:xml_scaffold_structure_sisu] end @@ -3123,6 +3138,9 @@ WOK if @opt.act[:xml_dom][:set]==:on #% --xml-dom, -X xml dom type ft << 'dom.xml' << '??.dom.xml' << 'dom.??.xml' end + if @opt.act[:xml_docbook_book][:set]==:on #% --xml-docbook-book + ft << 'docbook.xml' << '??.docbook.xml' << 'docbook.??.xml' + end if @opt.act[:xml_scaffold_structure_sisu][:set]==:on #% --xml-scaffold --xml-scaffold-sisu ft << 'scaffold.xml' << '??.scaffold.xml' << 'scaffold.??.xml' end @@ -4487,6 +4505,12 @@ WOK fn=base_filename.xml_dom make_file(path,fn) end + def xml_docbook_book + path=output_path.xml_docbook_book.dir + make_path(path) + fn=base_filename.xml_docbook_book + make_file(path,fn) + end def xml_scaffold_structure_sisu path=output_path.xml_scaffold_structure_sisu.dir make_path(path) @@ -4697,6 +4721,15 @@ WOK end self end + def xml_docbook_book + def dir + output_path.xml_docbook.dir + '/' + base_filename.xml_docbook_book + end + def rel + output_path.xml_docbook.rel + '/' + base_filename.xml_docbook_book + end + self + end def xml_scaffold_structure_sisu def dir output_path.xml.dir + '/' + base_filename.xml_scaffold_structure_sisu @@ -5132,6 +5165,24 @@ WOK end i18n(fnh) end + def xml_docbook_book(fh=nil) + fh=default_hash_build(fh,Sfx[:xml_docbook_book]) + fh[:lng]=lang_code?(fh[:lng]) + fnh=if output_dir_structure.by_filename? + { + fn: 'scroll', + ft: fh[:ft], + lng: fh[:lng], + } + else + { + fn: fh[:fn], + ft: fh[:ft], + lng: fh[:lng], + } + end + i18n(fnh) + end def xml_scaffold_structure_sisu(fh=nil) fh=default_hash_build(fh,Sfx[:xml_scaffold_structure_sisu]) fh[:lng]=lang_code?(fh[:lng]) @@ -6023,6 +6074,54 @@ WOK xml self end + def xml_docbook + def ft + 'docbook_CONSTRUCTION_ZONE' + end + def dir + set_path(ft).dir.abc + end + def url + set_path(ft).url.abc + end + def rel + set_path(ft).rel.abc + end + def rcp + set_path(ft).rcp.abc + end + def rel_sm + set_path(ft).rel_sm.ab + end + def rel_image + '../../_sisu/image' + end + self + end + def xml_docbook_book + def ft + 'docbook_CONSTRUCTION_ZONE' + end + def dir + set_path(ft).dir.abc + end + def url + set_path(ft).url.abc + end + def rel + set_path(ft).rel.abc + end + def rcp + set_path(ft).rcp.abc + end + def rel_sm + set_path(ft).rel_sm.ab + end + def rel_image + '../../_sisu/image' + end + self + end def xml_scaffold_structure_sisu def ft 'sisu.scaffold.xml' diff --git a/lib/sisu/v5/urls.rb b/lib/sisu/v5/urls.rb index 43ecd6cb..bdd66a59 100644 --- a/lib/sisu/v5/urls.rb +++ b/lib/sisu/v5/urls.rb @@ -118,6 +118,7 @@ module SiSU_Urls ' --asciidoc (asciidoc txt)'=>@fn[:txt_asciidoc], ' --markdown (markdown txt)'=>@fn[:txt_markdown], ' --rst (rST restructured-text)'=>@fn[:txt_rst], + ' --docbook-book (DocBook Book)'=>@fn[:xml_docbook_book], 'x --xml-sax (XML sax type)'=>@fn[:sax], 'X --xml-dom (XML dom type)'=>@fn[:dom], ' --xml-scaffold-sisu (XML scaffold)'=>@fn[:xml_scaffold_structure_sisu], @@ -227,6 +228,9 @@ module SiSU_Urls def dom(x) SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"[#{@opt.f_pth[:lng_is]}] -#{x}","#{@prog.web_browser} file://#{@md.file.output_path.xml_dom.dir}/#{@md.file.base_filename.xml_dom}").result end + def docbook_book(x) + SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"[#{@opt.f_pth[:lng_is]}] -#{x}","#{@prog.web_browser} file://#{@md.file.output_path.xml_docbook_book.dir}/#{@md.file.base_filename.xml_docbook_book}").result + end def scaffold_structure_sisu(x) SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"[#{@opt.f_pth[:lng_is]}] -#{x}","#{@prog.web_browser} file://#{@md.file.output_path.xml_scaffold_structure_sisu.dir}/#{@md.file.base_filename.xml_scaffold_structure_sisu}").result end @@ -438,6 +442,10 @@ module SiSU_Urls and @opt.act[:xml_sax][:set]==:on show.xml.sax(x) end + if x=~/--docbook-book\b/ \ + and @opt.act[:xml_docbook_book][:set]==:on + show.xml.docbook_book(x) + end if x=~/--xml-scaffold-sisu\b/ \ and @opt.act[:xml_scaffold_structure_sisu][:set]==:on show.xml.scaffold_structure_sisu(x) diff --git a/lib/sisu/v5/xml_docbook5.rb b/lib/sisu/v5/xml_docbook5.rb new file mode 100644 index 00000000..d3840d18 --- /dev/null +++ b/lib/sisu/v5/xml_docbook5.rb @@ -0,0 +1,271 @@ +# 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: Docbook book XML rendition + +=end +module SiSU_XML_Docbook_Book + require_relative 'particulars' # particulars.rb + include SiSU_Particulars + require_relative 'ao' # ao.rb + require_relative 'sysenv' # sysenv.rb + include SiSU_Env + require_relative 'txt_shared' # txt_shared.rb + include SiSU_TextUtils + require_relative 'xml_shared' # xml_shared.rb + include SiSU_XML_Munge + class Source + def initialize(opt) + @opt=opt + @particulars=SiSU_Particulars::CombinedSingleton.instance.get_all(opt) + end + def read + begin + @md,@ao_array=@particulars.md,@particulars.ao_array + @env=@particulars.env + report + SiSU_XML_Docbook_Book::Source::Scroll.new(@ao_array,@md).songsheet + rescue + SiSU_Errors::Rescued.new($!,$@,@opt.cmd,@opt.fns).location do + __LINE__.to_s + ':' + __FILE__ + end + ensure + end + end + private + def report + 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.docbook_viewer} #{@md.file.output_path.xml_docbook_book.dir}/#{@md.file.base_filename.xml_docbook_book}" + : "[#{@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],'DocBook',tool).green_hi_blue + : SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'DocBook',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,"#{@md.file.output_path.xml_docbook_book.dir}/#{@md.file.base_filename.xml_docbook_book}").flow + end + end + end + class Scroll + def collapsed + %w[ 0 1 2 3 4 5 6 ] + end + def docbook(lc,chlv='') + case lc + when 1 + 'book' + when 2 + lc==chlv ? 'chapter' : 'section' + when 3 + lc==chlv ? 'chapter' : 'section' + when 4 + lc==chlv ? 'chapter' : 'section' + when 5 + 'section' + when 6 + 'section' + end + end + self + end + def put(line) + #@file_docbook.puts line #look into and use perhaps + puts line if @md.opt.act[:verbose_plus][:set]==:on + end + def head + <<-WOK + + + WOK + end + def markup_text(data) + data.each_with_index do |o,i| + if o.is ==:heading || o.is ==:para + o=@trans.markup_docbook(o) #unless o.obj==nil + end + end + data + end + def tail + tail=<<-WOK + + WOK + put(tail) + end + def output(o,lev=nil,comment='') + puts lev == 0..6 \ + ? "#{space*lev}<#{lev}>[#{o.ocn}] #{o.ln} #{o.obj}#{comment}" + : "<#{lev}>[#{o.ocn}] #{o.ln} #{o.obj}#{comment}" + end + def structure_collapsed(data) + puts "\ncollapsed structure, heading outline --->\n\n" + data.each_with_index do |o,i| + if (o.is ==:heading || o.is ==:heading_insert) + output(o,o.lc) + end + end + end + #def chapterlevel + #end + def structure_build_collapsed(data) + #output_file=@md.file.output_path.xml_docbook_book.dir + '/' + @md.file.base_filename.xml_docbook_book + file=SiSU_Env::FileOp.new(@md) + filename_docbook=file.write_file.xml_docbook_book + h=0 + @chlv=chlv=0 + doc_position=:head + filename_docbook.puts head + data.each_with_index do |o,i| + if (defined? o.ocn and not o.ocn.nil?) + ocn="\n#{Dx[:ocn_o]}#{o.ocn}#{Dx[:ocn_c]}" + id=%{ id="o#{o.ocn}" } + else + ocn,id='','' + end + if (o.is ==:heading || o.is ==:heading_insert) + lev=o.lc + chlv=(o.lv.to_i == 1) \ + ? @chlv=o.lc.to_i + : 0 + @splv=lev + unless doc_position==:head + filename_docbook.puts structure_build_tag_close(lev,h) + end + doc_position=:body_and_tail + filename_docbook.puts %{#{space*(lev-1)}<#{tags.docbook(lev,chlv)}> +#{space*lev} +} + filename_docbook.puts SiSU_TextUtils::Wrap.new(o.obj + ocn,80,(@splv*2+2)).line_wrap + filename_docbook.puts %{#{space*lev}} + h=lev + elsif (o.of ==:para or o.of ==:block) + filename_docbook.puts "#{space*(@splv)}" + filename_docbook.puts SiSU_TextUtils::Wrap.new(o.obj + ocn,80,(@splv*2+2)).line_wrap + filename_docbook.puts "#{space*(@splv)}" + end + end + filename_docbook.puts structure_build_tag_close(0,h) + filename_docbook.close + end + def structure_build_tag_close(lev,h) + x=[] + case h + when 1 + x << "#{space*0}" if (lev <= 1) + when 2 + x << "#{space*1}" if (lev <= 2) + x << "#{space*0}" if (lev <= 1) + when 3 + x << "#{space*2}" if (lev <= 3) + x << "#{space*1}" if (lev <= 2) + x << "#{space*0}" if (lev <= 1) + when 4 + x << "#{space*3}" if (lev <= 4) + x << "#{space*2}" if (lev <= 3) + x << "#{space*1}" if (lev <= 2) + x << "#{space*0}" if (lev <= 1) + when 5 + x << "#{space*4}" if (lev <= 5) + x << "#{space*3}" if (lev <= 4) + x << "#{space*2}" if (lev <= 3) + x << "#{space*1}" if (lev <= 2) + x << "#{space*0}" if (lev <= 1) + when 6 + x << "#{space*5}" if (lev <= 6) + x << "#{space*4}" if (lev <= 5) + x << "#{space*3}" if (lev <= 4) + x << "#{space*2}" if (lev <= 3) + x << "#{space*1}" if (lev <= 2) + x << "#{space*0}" if (lev <= 1) + end + x.join("\n") + end + end + end +end +__END__ diff --git a/lib/sisu/v5/xml_shared.rb b/lib/sisu/v5/xml_shared.rb index caad8be0..688e34c3 100644 --- a/lib/sisu/v5/xml_shared.rb +++ b/lib/sisu/v5/xml_shared.rb @@ -474,10 +474,11 @@ module SiSU_XML_Munge gsub(/#{Mx[:fa_cite_o]}(.+?)#{Mx[:fa_cite_c]}/,'\1'). gsub(/#{Mx[:fa_strike_o]}(.+?)#{Mx[:fa_strike_c]}/,'\1'). gsub(/#{Mx[:fa_monospace_o]}(.+?)#{Mx[:fa_monospace_c]}/,'\1'). # tt, kbd + gsub(/#{Mx[:lnk_o]}\s*(\S+?\.(?:png|jpg|gif)).+?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}|image)/m,''). #taken unmodified except path from fictionbook gsub(/#{Mx[:url_o]}(.+?)#{Mx[:url_c]}/,"#{Dx[:url_o]}\\1#{Dx[:url_c]}"). gsub(/#{Mx[:mk_o]}:name#(\S+?)#{Mx[:mk_c]}/,''). - gsub(/#{Mx[:gl_bullet]}/m,'●  '). - gsub(/#{Mx[:nbsp]}/,' '). + gsub(/#{Mx[:gl_bullet]}/m,'● '). #  not available + gsub(/#{Mx[:nbsp]}/,' '). #  not available gsub(/<(p|br)>/,'<\1 />') dob.obj=clean(dob.obj) dob -- cgit v1.2.3 From 9700518408f388c9f070894f7986d94d80e4c070 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Tue, 3 Dec 2013 00:30:50 -0500 Subject: v5: xml, fictionbook --- lib/sisu/v5/constants.rb | 1 + lib/sisu/v5/hub.rb | 5 + lib/sisu/v5/manifest.rb | 7 + lib/sisu/v5/options.rb | 6 + lib/sisu/v5/sysenv.rb | 99 +++++++++++ lib/sisu/v5/urls.rb | 8 + lib/sisu/v5/xml_fictionbook2.rb | 366 ++++++++++++++++++++++++++++++++++++++++ lib/sisu/v5/xml_shared.rb | 8 +- 8 files changed, 496 insertions(+), 4 deletions(-) create mode 100644 lib/sisu/v5/xml_fictionbook2.rb (limited to 'lib') diff --git a/lib/sisu/v5/constants.rb b/lib/sisu/v5/constants.rb index 1f96f0aa..da9858f2 100644 --- a/lib/sisu/v5/constants.rb +++ b/lib/sisu/v5/constants.rb @@ -79,6 +79,7 @@ Sfx={ xml_docbook: '.docbook.xml', xml_docbook_article: '.article.docbook.xml', xml_docbook_book: '.book.docbook.xml', + xml_fictionbook: '.fb2', epub: '.epub', epub_xhtml: '.xhtml', odt: '.odt', diff --git a/lib/sisu/v5/hub.rb b/lib/sisu/v5/hub.rb index 08147d96..f09bd832 100644 --- a/lib/sisu/v5/hub.rb +++ b/lib/sisu/v5/hub.rb @@ -359,6 +359,10 @@ module SiSU require_relative 'xml_docbook5' # xml_docbook5.rb SiSU_XML_Docbook_Book::Source.new(@opt).read end + if @opt.act[:xml_fictionbook][:set]==:on #% --xml-fictionbook + require_relative 'xml_fictionbook2' # xml_fictionbook2.rb + SiSU_XML_Fictionbook::Source.new(@opt).read + end if @opt.act[:xml_sax][:set]==:on #% --xml-sax, -x xml sax type require_relative 'xml_sax' # xml_sax.rb SiSU_XML_SAX::Source.new(@opt).read @@ -673,6 +677,7 @@ module SiSU || @opt.act[:xml_scaffold_structure_sisu][:set]==:on \ || @opt.act[:xml_scaffold_structure_collapse][:set]==:on \ || @opt.act[:xml_docbook_book][:set]==:on \ + || @opt.act[:xml_fictionbook][:set]==:on \ || @opt.act[:pdf][:set]==:on \ || @opt.act[:pdf_p][:set]==:on \ || @opt.act[:pdf_l][:set]==:on \ diff --git a/lib/sisu/v5/manifest.rb b/lib/sisu/v5/manifest.rb index 42755151..fb3064e7 100644 --- a/lib/sisu/v5/manifest.rb +++ b/lib/sisu/v5/manifest.rb @@ -410,6 +410,13 @@ module SiSU_Manifest id,file='XML Docbook Book',@f.base_filename.xml_docbook_book summarize(id,file,pth,rel,url) end + if FileTest.file?(@f.place_file.xml_fictionbook.dir)==true + pth=@f.output_path.xml_fictionbook.dir + rel=@f.output_path.xml_fictionbook.rel_sm + url=@f.output_path.xml_fictionbook.url + id,file='XML Fictionbook',@f.base_filename.xml_fictionbook + summarize(id,file,pth,rel,url) + end if FileTest.file?(@f.place_file.xml_scaffold_structure_sisu.dir)==true pth=@f.output_path.xml_scaffold_structure_sisu.dir rel=@f.output_path.xml_scaffold_structure_sisu.rel_sm diff --git a/lib/sisu/v5/options.rb b/lib/sisu/v5/options.rb index 1e11b711..f410e61f 100644 --- a/lib/sisu/v5/options.rb +++ b/lib/sisu/v5/options.rb @@ -864,6 +864,10 @@ module SiSU_Commandline act[:xml_docbook_book]=mod.inspect =~/"--docbook"|"--docbook-book"|"--xml-docbook"|"--xml-docbook_book"/ \ ? { bool: true, set: :on } : { bool: false, set: :na } + act[:xml_fictionbook]=(cmd =~/f/ \ + || mod.inspect =~/"--fictionbook"|"--xml-fictionbook"/) \ + ? { bool: true, set: :on } + : { bool: false, set: :na } act[:xml_scaffold_structure_sisu]=mod.inspect =~/"--xml-scaffold"|"--xml-scaffold-sisu"/ \ ? { bool: true, set: :on } : { bool: false, set: :na } @@ -1002,6 +1006,7 @@ module SiSU_Commandline || act[:xml_dom][:set]==:on \ || act[:xml_sax][:set]==:on \ || act[:xml_docbook_book][:set]==:on \ + || act[:xml_fictionbook][:set]==:on \ || act[:xml_scaffold_structure_sisu][:set]==:on \ || act[:xml_scaffold_structure_collapse][:set]==:on ) { bool: true, set: :on } @@ -1051,6 +1056,7 @@ module SiSU_Commandline || act[:xml_dom][:set]==:on \ || act[:xml_sax][:set]==:on \ || act[:xml_docbook_book][:set]==:on \ + || act[:xml_fictionbook][:set]==:on \ || act[:xml_scaffold_structure_sisu][:set]==:on \ || act[:xml_scaffold_structure_collapse][:set]==:on ) { bool: true, set: :on } diff --git a/lib/sisu/v5/sysenv.rb b/lib/sisu/v5/sysenv.rb index f25cd027..1f5d7d3a 100644 --- a/lib/sisu/v5/sysenv.rb +++ b/lib/sisu/v5/sysenv.rb @@ -1484,6 +1484,12 @@ module SiSU_Env ? @rc['xml_docbook']['ocn'] : true end + def xml_fictionbook_ocn? + ((defined? @rc['xml_fictionbook']['ocn']) \ + && @rc['xml_fictionbook']['ocn']==false) \ + ? @rc['xml_fictionbook']['ocn'] + : true + end def xml_scaffold_ocn? ((defined? @rc['xml_scaffold']['ocn']) \ && @rc['xml_scaffold']['ocn']==false) \ @@ -2772,6 +2778,12 @@ WOK ? @rc['program_select']['xml_viewer'] : text_editor end + def fictionbook_viewer + ((defined? @rc['program_select']['xml_viewer']) \ + && @rc['program_select']['xml_viewer'] =~/\S\S+/) \ + ? @rc['program_select']['xml_viewer'] + : text_editor + end def xml_editor xml_viewer end @@ -3076,6 +3088,9 @@ WOK if @md.opt.act[:xml_docbook_book][:set]==:on #% --xml-docbook-book ft << @md.fn[:xml_docbook_book] end + if @md.opt.act[:xml_fictionbook][:set]==:on #% --xml-fictionbook + ft << @md.fn[:xml_fictionbook] + end if @md.opt.act[:xml_scaffold_structure_sisu][:set]==:on #% --xml-scaffold --xml-scaffold-sisu ft << @md.fn[:xml_scaffold_structure_sisu] end @@ -3141,6 +3156,9 @@ WOK if @opt.act[:xml_docbook_book][:set]==:on #% --xml-docbook-book ft << 'docbook.xml' << '??.docbook.xml' << 'docbook.??.xml' end + if @opt.act[:xml_fictionbook][:set]==:on #% --xml-fictionbook + ft << 'fictionbook.xml' << '??.fictionbook.xml' << 'fictionbook.??.xml' + end if @opt.act[:xml_scaffold_structure_sisu][:set]==:on #% --xml-scaffold --xml-scaffold-sisu ft << 'scaffold.xml' << '??.scaffold.xml' << 'scaffold.??.xml' end @@ -4511,6 +4529,12 @@ WOK fn=base_filename.xml_docbook_book make_file(path,fn) end + def xml_fictionbook + path=output_path.xml_fictionbook.dir + make_path(path) + fn=base_filename.xml_fictionbook + make_file(path,fn) + end def xml_scaffold_structure_sisu path=output_path.xml_scaffold_structure_sisu.dir make_path(path) @@ -4730,6 +4754,15 @@ WOK end self end + def xml_fictionbook + def dir + output_path.xml_fictionbook.dir + '/' + base_filename.xml_fictionbook + end + def rel + output_path.xml_fictionbook.rel + '/' + base_filename.xml_fictionbook + end + self + end def xml_scaffold_structure_sisu def dir output_path.xml.dir + '/' + base_filename.xml_scaffold_structure_sisu @@ -5183,6 +5216,24 @@ WOK end i18n(fnh) end + def xml_fictionbook(fh=nil) + fh=default_hash_build(fh,Sfx[:xml_fictionbook]) + fh[:lng]=lang_code?(fh[:lng]) + fnh=if output_dir_structure.by_filename? + { + fn: 'scroll', + ft: fh[:ft], + lng: fh[:lng], + } + else + { + fn: fh[:fn], + ft: fh[:ft], + lng: fh[:lng], + } + end + i18n(fnh) + end def xml_scaffold_structure_sisu(fh=nil) fh=default_hash_build(fh,Sfx[:xml_scaffold_structure_sisu]) fh[:lng]=lang_code?(fh[:lng]) @@ -6098,6 +6149,30 @@ WOK end self end + def xml_docbook_article + def ft + 'docbook' + end + def dir + set_path(ft).dir.abc + end + def url + set_path(ft).url.abc + end + def rel + set_path(ft).rel.abc + end + def rcp + set_path(ft).rcp.abc + end + def rel_sm + set_path(ft).rel_sm.ab + end + def rel_image + '../../_sisu/image' + end + self + end def xml_docbook_book def ft 'docbook_CONSTRUCTION_ZONE' @@ -6122,6 +6197,30 @@ WOK end self end + def xml_fictionbook + def ft + 'fictionbook_CONSTRUCTION_ZONE' + end + def dir + set_path(ft).dir.abc + end + def url + set_path(ft).url.abc + end + def rel + set_path(ft).rel.abc + end + def rcp + set_path(ft).rcp.abc + end + def rel_sm + set_path(ft).rel_sm.ab + end + def rel_image + '../../_sisu/image' + end + self + end def xml_scaffold_structure_sisu def ft 'sisu.scaffold.xml' diff --git a/lib/sisu/v5/urls.rb b/lib/sisu/v5/urls.rb index bdd66a59..ce3be66b 100644 --- a/lib/sisu/v5/urls.rb +++ b/lib/sisu/v5/urls.rb @@ -119,6 +119,7 @@ module SiSU_Urls ' --markdown (markdown txt)'=>@fn[:txt_markdown], ' --rst (rST restructured-text)'=>@fn[:txt_rst], ' --docbook-book (DocBook Book)'=>@fn[:xml_docbook_book], + ' --fictionbook (Fictionbook)'=>@fn[:xml_fictionbook], 'x --xml-sax (XML sax type)'=>@fn[:sax], 'X --xml-dom (XML dom type)'=>@fn[:dom], ' --xml-scaffold-sisu (XML scaffold)'=>@fn[:xml_scaffold_structure_sisu], @@ -231,6 +232,9 @@ module SiSU_Urls def docbook_book(x) SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"[#{@opt.f_pth[:lng_is]}] -#{x}","#{@prog.web_browser} file://#{@md.file.output_path.xml_docbook_book.dir}/#{@md.file.base_filename.xml_docbook_book}").result end + def fictionbook(x) + SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"[#{@opt.f_pth[:lng_is]}] -#{x}","#{@prog.web_browser} file://#{@md.file.output_path.xml_fictionbook.dir}/#{@md.file.base_filename.xml_fictionbook}").result + end def scaffold_structure_sisu(x) SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],"[#{@opt.f_pth[:lng_is]}] -#{x}","#{@prog.web_browser} file://#{@md.file.output_path.xml_scaffold_structure_sisu.dir}/#{@md.file.base_filename.xml_scaffold_structure_sisu}").result end @@ -446,6 +450,10 @@ module SiSU_Urls and @opt.act[:xml_docbook_book][:set]==:on show.xml.docbook_book(x) end + if x=~/--fictionbook\b/ \ + and @opt.act[:xml_fictionbook][:set]==:on + show.xml.fictionbook(x) + end if x=~/--xml-scaffold-sisu\b/ \ and @opt.act[:xml_scaffold_structure_sisu][:set]==:on show.xml.scaffold_structure_sisu(x) diff --git a/lib/sisu/v5/xml_fictionbook2.rb b/lib/sisu/v5/xml_fictionbook2.rb new file mode 100644 index 00000000..8ee2fb89 --- /dev/null +++ b/lib/sisu/v5/xml_fictionbook2.rb @@ -0,0 +1,366 @@ +# 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: Fictionbook XML rendition + +=end +module SiSU_XML_Fictionbook + require_relative 'particulars' # particulars.rb + include SiSU_Particulars + require_relative 'ao' # ao.rb + require_relative 'sysenv' # sysenv.rb + include SiSU_Env + require_relative 'txt_shared' # txt_shared.rb + include SiSU_TextUtils + require_relative 'xml_shared' # xml_shared.rb + include SiSU_XML_Munge + class Source + def initialize(opt) + @opt=opt + @particulars=SiSU_Particulars::CombinedSingleton.instance.get_all(opt) + end + def read + begin + @md,@ao_array=@particulars.md,@particulars.ao_array + @env=@particulars.env + report + SiSU_XML_Fictionbook::Source::Scroll.new(@ao_array,@md).songsheet + rescue + SiSU_Errors::Rescued.new($!,$@,@opt.cmd,@opt.fns).location do + __LINE__.to_s + ':' + __FILE__ + end + ensure + end + end + private + def report + 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.fictionbook_viewer} #{@md.file.output_path.xml_fictionbook.dir}/#{@md.file.base_filename.xml_fictionbook}" + : "[#{@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],'Fictionbook',tool).green_hi_blue + : SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],'Fictionbook',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,"#{@md.file.output_path.xml_fictionbook.dir}/#{@md.file.base_filename.xml_fictionbook}").flow + end + end + end + class Scroll + def collapsed + %w[ 0 1 2 3 4 5 6 ] + end + def fictionbook + [ 'section', + 'section', + 'section', + 'section', + 'section', + 'section', + 'section' + ] + end + self + end + def put(line) + puts line if @md.opt.act[:verbose_plus][:set]==:on + end + def head + version=SiSU_Env::InfoVersion.instance.get_version + rb_ver=SiSU_Env::InfoVersion.instance.rbversion + date_available=if defined? @md.date.available; "\n

    #{@md.date.available} Initial version

    " + else '' + end + date_modified=if defined? @md.date.modified; "\n

    #{@md.date.modified} Last Modified

    " + else '' + end + coverpageimage=if defined? @md.make.cover_image[:cover] + %{\n } + else '' + end + if defined? @md.authors \ + and @md.authors.length > 0 + authors=[] + @md.authors.each do |author| + authors << ' ' + if not author[:others].empty? + authors << %{ #{author[:others]}} + end + if not author[:the].empty? + authors << %{ #{author[:the]}} + end + authors << ' ' + end + authors=authors.join("\n") + end + <<-WOK + + + + + *** +#{authors} + #{@md.title.full}#{coverpageimage} + + + #{@md.date.published} + + + + + + + + #{version[:project]} #{version[:version]} and #{rb_ver} + #{version[:date]} + #{@md.file.output_path.manifest.url}/#{@md.file.base_filename.manifest} + + 1.0 + #{date_available}#{date_modified} + + + + + WOK + end + def extract_endnotes #work on + endnotes,endnotes_raw,endnotes_b=[],[],[] + @data.each do |para| + endnotes_raw << para.obj.scan(/#{Mx[:en_a_o]}(.+?)#{Mx[:en_a_c]}/m) + endnotes_b << para.obj.scan(/#{Mx[:en_b_o]}(.+?)#{Mx[:en_b_c]}/m) + end + endnotes_raw.flatten.each do |en| + en=@trans.markup_fictionbook(en) + endnotes << en.gsub(/([\d+*]+)\s+(.+)/m, + %{
    \n +<p>\\1.</p>\n +

    \\2

    \n +
    }) + end + endnotes_raw=[] + endnotes + end + def extract_images #work on + require "base64" + images_raw,images_base64_fb2=[],[] + images_base64={} + if defined? @md.make.cover_image[:cover] + images_raw << @md.make.cover_image[:cover] + end + @data.each do |para| + images_raw << para.obj.scan(/#{Mx[:lnk_o]}\s*(\S+?\.(?:png|jpg|gif)).+?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}|image)/m) + end + images_raw.flatten.sort.each do |img| + imgpth=@env.url.images_local + '/' + img + open(imgpth) + if FileTest.file?(imgpth) + images_base64[img]=Base64.encode64(File.read(imgpth)) + end + end + images_raw=[] + images_base64.each_key do |k| + imgtype=case k + when /\.jpg/ then 'jpeg' + when /\.png/ then 'png' + when /\.gif/ then 'gif' + else 'jpeg' + end + images_base64_fb2 << %{#{images_base64[k]} + +} + end + images_base64_fb2.join("\n") + end + def markup_text(data) + data.each_with_index do |o,i| + if o.is ==:heading || o.is ==:para + o.obj=@trans.markup_fictionbook(o.obj,o.is) #unless o.obj==nil + end + end + data + end + def tail(images_base64_fb2) + <<-WOK + +#{images_base64_fb2} +
    + WOK + end + def output(o,lev=nil,comment='') + puts lev == 0..6 \ + ? "#{space*lev}<#{lev}>[#{o.ocn}] #{o.ln} #{o.obj}#{comment}" + : "<#{lev}>[#{o.ocn}] #{o.ln} #{o.obj}#{comment}" + end + def structure_collapsed(data) + puts "\ncollapsed structure, heading outline --->\n\n" + data.each_with_index do |o,i| + if (o.is ==:heading || o.is ==:heading_insert) + output(o,o.lc) + end + end + end + def endnotes_build(endnotes,filename_fictionbook) + if endnotes.length > 0 + filename_fictionbook.puts %{} + endnotes.each do |en| + filename_fictionbook.puts SiSU_TextUtils::Wrap.new(en,80,6).line_wrap + end + end + end + def structure_build_collapsed(data,endnotes,images_base64) + file=SiSU_Env::FileOp.new(@md) + filename_fictionbook=file.write_file.xml_fictionbook + h=0 + doc_position=:head + filename_fictionbook.puts head + data.each_with_index do |o,i| + ocn=(defined? o.ocn and not o.ocn.nil?) ? "\n#{Dx[:ocn_o]}#{o.ocn}#{Dx[:ocn_c]}" : '' + if o.is ==:heading + lev=o.lc + chlv=(o.lv.to_i == 1) \ + ? @chlv=o.lc.to_i + : 0 + unless doc_position==:head + filename_fictionbook.puts structure_build_tag_close(lev,h) + end + doc_position=:body_and_tail + filename_fictionbook.puts %{#{space*lev}<#{tags.fictionbook[lev]}> +#{space*lev} +} + filename_fictionbook.puts SiSU_TextUtils::Wrap.new("<p>#{o.obj}#{ocn}</p>",80,(lev*2+2)).line_wrap + filename_fictionbook.puts %{#{space*lev}} + h=lev + elsif o.is ==:heading_insert \ + and o.obj =~/Endnotes/ \ + and o.ln == 2 + break + elsif (o.of ==:para or o.of ==:block) + filename_fictionbook.puts SiSU_TextUtils::Wrap.new("

    #{o.obj}#{ocn}

    ",80,6).line_wrap + end + end + filename_fictionbook.puts structure_build_tag_close(0,h) + endnotes_build(endnotes,filename_fictionbook) + filename_fictionbook.puts tail(images_base64) + filename_fictionbook.close + end + def structure_build_tag_close(lev,h) + x=[] + case h + when 1 + x << "#{space*1}" if (lev <= 1) + when 2 + x << "#{space*2}" if (lev <= 2) + x << "#{space*1}" if (lev <= 1) + when 3 + x << "#{space*3}" if (lev <= 3) + x << "#{space*2}" if (lev <= 2) + x << "#{space*1}" if (lev <= 1) + when 4 + x << "#{space*4}" if (lev <= 4) + x << "#{space*3}" if (lev <= 3) + x << "#{space*2}" if (lev <= 2) + x << "#{space*1}" if (lev <= 1) + when 5 + x << "#{space*5}" if (lev <= 5) + x << "#{space*4}" if (lev <= 4) + x << "#{space*3}" if (lev <= 3) + x << "#{space*2}" if (lev <= 2) + x << "#{space*1}" if (lev <= 1) + when 6 + x << "#{space*6}" if (lev <= 6) + x << "#{space*5}" if (lev <= 5) + x << "#{space*4}" if (lev <= 4) + x << "#{space*3}" if (lev <= 3) + x << "#{space*2}" if (lev <= 2) + x << "#{space*1}" if (lev <= 1) + end + x.join("\n") + end + end + end +end +__END__ diff --git a/lib/sisu/v5/xml_shared.rb b/lib/sisu/v5/xml_shared.rb index 688e34c3..a6092559 100644 --- a/lib/sisu/v5/xml_shared.rb +++ b/lib/sisu/v5/xml_shared.rb @@ -435,7 +435,7 @@ module SiSU_XML_Munge gsub(/#{Mx[:gl_o]}#([a-z]{2,4})#{Mx[:gl_c]}/u,'&\1;') end def markup_fictionbook(str='',is='') - str=str.gsub(/#{Mx[:en_a_o]}([\d+*]+).+?#{Mx[:en_a_c]}/m,'[\1]'). + str=str.gsub(/#{Mx[:en_a_o]}([\d+*]+).+?#{Mx[:en_a_c]}/m,'[\1]'). gsub(/&/,'&'). #sort gsub(/#{Mx[:mk_o]}#([a-zA-Z]+)#{Mx[:mk_c]}/,'&\1;'). gsub(/(^|#{Mx[:gl_c]}|\s)&\s+/,'\1& '). #sort @@ -450,11 +450,11 @@ module SiSU_XML_Munge gsub(/#{Mx[:fa_cite_o]}(.+?)#{Mx[:fa_cite_c]}/,'\1'). gsub(/#{Mx[:fa_strike_o]}(.+?)#{Mx[:fa_strike_c]}/,'\1'). gsub(/#{Mx[:fa_monospace_o]}(.+?)#{Mx[:fa_monospace_c]}/,'\1'). # tt, kbd - gsub(/#{Mx[:lnk_o]}\s*(\S+?\.(?:png|jpg|gif)).+?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}|image)/m,''). + gsub(/#{Mx[:lnk_o]}\s*(\S+?\.(?:png|jpg|gif)).+?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}|image)/m,''). gsub(/#{Mx[:url_o]}(.+?)#{Mx[:url_c]}/,"#{Dx[:url_o]}\\1#{Dx[:url_c]}"). gsub(/#{Mx[:mk_o]}:name#(\S+?)#{Mx[:mk_c]}/,''). - gsub(/#{Mx[:gl_bullet]}/m,'●  '). - gsub(/#{Mx[:nbsp]}/,' '). + gsub(/#{Mx[:gl_bullet]}/m,'● '). #  not available + gsub(/#{Mx[:nbsp]}/,' '). #  not available gsub(/<(p|br)>/,'<\1 />') clean(str) end -- cgit v1.2.3