From 1832a937713d33517066dc4cf8222871045b2b58 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Mon, 6 Jan 2014 22:56:02 -0500 Subject: v5: single document root A~ (recalibrate headings); level D~ possible * :A~ document title, single document root (ln==0) * introduce additional possible heading level, D~ * markup rule change: single document root * breaks much downstream code, recalibrate (fix, test, fix & test again) * v4 & v5 bifurcate (diverge "un-merge-ably") --- lib/sisu/v5/ao_doc_str.rb | 120 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 85 insertions(+), 35 deletions(-) (limited to 'lib/sisu/v5/ao_doc_str.rb') diff --git a/lib/sisu/v5/ao_doc_str.rb b/lib/sisu/v5/ao_doc_str.rb index f1e73362..31479252 100644 --- a/lib/sisu/v5/ao_doc_str.rb +++ b/lib/sisu/v5/ao_doc_str.rb @@ -97,9 +97,10 @@ module SiSU_AO_DocumentStructureExtract end def ln_get(lv) case lv - when /A/ then 1 - when /B/ then 2 - when /C/ then 3 + when /A/ then 0 + when /B/ then 1 + when /C/ then 2 + when /D/ then 3 when /1/ then 4 when /2/ then 5 when /3/ then 6 @@ -275,10 +276,10 @@ module SiSU_AO_DocumentStructureExtract SiSU_AO_DocumentStructure::ObjectComment.new.comment(h) else nil end - when /^:?([A-C1-6])\~/ #heading / lv + when /^:?([A-D1-6])\~/ #heading / lv lv=$1 ln=ln_get(lv) - t_o=if t_o=~/^:?[A-C1-6]\~\s+(.+)/m + t_o=if t_o=~/^:?[A-D1-6]\~\s+(.+)/m obj=$1 note=endnote_test?(obj) obj,tags=extract_tags(obj) @@ -294,7 +295,7 @@ module SiSU_AO_DocumentStructureExtract 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 + elsif t_o=~/^:?[A-D1-6]\~(\S+?)-\s+(.+)/m name,obj=$1,$2 note=endnote_test?(obj) obj,tags=extract_tags(obj) @@ -310,7 +311,7 @@ module SiSU_AO_DocumentStructureExtract 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 + elsif t_o=~/^:?[A-D1-6]\~(\S+)\s+(.+)/m name,obj=$1,$2 note=endnote_test?(obj) obj,tags=extract_tags(obj,name) @@ -691,24 +692,24 @@ module SiSU_AO_DocumentStructureExtract end if @md.flag_endnotes tuned_file << @pb - h={ ln: 2, lc: 2, obj: 'Endnotes', autonum_: false } + h={ ln: 1, lc: 1, 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 } + h={ ln: 4, lc: 2, 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 } + h={ ln: 1, lc: 1, 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 } + h={ ln: 4, lc: 2, 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 } + h={ ln: 1, lc: 1, 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 } + h={ ln: 4, lc: 2, 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) @@ -768,14 +769,17 @@ module SiSU_AO_DocumentStructureExtract || (@dob.hang != @dob.indent)) \ and not @dob.bullet_ @dob=case @dob.obj + when /^#{@md.lv0}/ + h={ lv: 'A', ln: 0 } + SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h,@dob) when /^#{@md.lv1}/ - h={ lv: 'A', ln: 1 } + h={ lv: 'B', ln: 1 } SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h,@dob) when /^#{@md.lv2}/ - h={ lv: 'B', ln: 2 } + h={ lv: 'C', ln: 2 } SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h,@dob) when /^#{@md.lv3}/ - h={ lv: 'C', ln: 3 } + h={ lv: 'D', ln: 3 } SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h,@dob) when /^#{@md.lv4}/ h={ lv: '1', ln: 4 } @@ -799,14 +803,15 @@ module SiSU_AO_DocumentStructureExtract end def structure_info def lv - %w[0 A~ B~ C~ 1 2 3] + %w[A~ B~ C~ D~ 1 2 3] end def possible_parents(child) case child when /A~/ then 'none' when /B~/ then 'A~' when /C~/ then 'B~' - when /1/ then 'A~, B~, C~' + when /D~/ then 'C~' + when /1/ then 'A~, B~, C~, D~' when /2/ then '1' when /3/ then '2' end @@ -815,7 +820,8 @@ module SiSU_AO_DocumentStructureExtract case parent when /A~/ then 'B~, 1' when /B~/ then 'C~, 1' - when /C~/ then '1' + when /C~/ then 'D~, 1' + when /D~/ then '1' when /1/ then '2' when /2/ then '3' when /3/ then 'none' @@ -846,11 +852,11 @@ has incorrect level and/or parent level} 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 + node=ocn=ocn_dv=ocn_sp=ocnh=ocnh0=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' then 1 - when 'B' then 2 - when 'C' then 3 + when 'A' then 0 + when 'B' then 1 + when 'C' then 2 + when 'D' then 3 when '1' then 4 when '2' then 5 when '3' then 6 @@ -876,7 +883,8 @@ has incorrect level and/or parent level} ocn+=1 end if dob.is==:heading \ - and (ln.to_s =~/^[1-9]/ \ + and (ln.to_s =~/^[0-9]/ \ + or ln.to_s =~@md.lv0 \ or ln.to_s =~@md.lv1 \ or ln.to_s =~@md.lv2 \ or ln.to_s =~@md.lv3 \ @@ -886,7 +894,21 @@ has incorrect level and/or parent level} if not dob.obj =~/~#|-#/ ocnh+=1 end - if ln==1 \ + if ln==0 \ + or ln=~@md.lv0 + if not dob.obj =~/~#|-#/ + ocn_flag=true + ocnh0+=1 #heading + node0="0:#{ocnh0};#{ocn}" + else + ocn_flag=false + node0="0:0;0" + end + document_structure_check_info(node0,node0) + @collapsed_lv0=0 + collapsed_level=@collapsed_lv0 + node,ocn_sp,parent=node0,"h#{ocnh}",'ROOT' + elsif ln==1 \ or ln=~@md.lv1 if not dob.obj =~/~#|-#/ ocn_flag=true @@ -896,8 +918,14 @@ has incorrect level and/or parent level} ocn_flag=false node1="1:0;0" end - document_structure_check_info(node1,node0) - @collapsed_lv1=1 + parent=if node0 + document_structure_check_info(node1,node0) + @collapsed_lv1=@collapsed_lv0+1 + node0 + else + document_structure_check_info(node0,node0,:error) + node0 + end collapsed_level=@collapsed_lv1 node,ocn_sp,parent=node1,"h#{ocnh}",node0 #FIX elsif ln==2 \ @@ -971,6 +999,10 @@ or this level should be level :B~ rather than #{dob.lv}} document_structure_check_info(node4,node1) @collapsed_lv4=@collapsed_lv1+1 node1 + elsif node0 + document_structure_check_info(node4,node0) + @collapsed_lv4=@collapsed_lv0+1 + node0 else warning_incorrect_parent_level_or_level(dob.obj) document_structure_check_info(node4,node0,:error) @@ -1144,10 +1176,11 @@ or this level should be 5~ rather #{dob.lv}" #level 6 @data,@md=data,md end def dom - @s=['0', + @s=[ 'A', 'B', 'C', + 'D', '1', '2', '3' @@ -1170,6 +1203,14 @@ or this level should be 5~ rather #{dob.lv}" #level 6 if o.is==:heading \ || o.is==:heading_insert case o.ln + when 0 + 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,true,false,false,false] when 1 tuned_file << tag_close(o.ln,hs) tuned_file << tag_open(o,@s) @@ -1177,7 +1218,7 @@ or this level should be 5~ rather #{dob.lv}" #level 6 puts_tag_close(o.ln,hs) puts_tag_open(o,@s) end - hs=[1,true,false,false] + hs=[1,true,true,false,false] when 2 tuned_file << tag_close(o.ln,hs) tuned_file << tag_open(o,@s) @@ -1185,7 +1226,7 @@ or this level should be 5~ rather #{dob.lv}" #level 6 puts_tag_close(o.ln,hs) puts_tag_open(o,@s) end - hs=[2,true,true,false] + hs=[2,true,true,true,false] when 3 tuned_file << tag_close(o.ln,hs) tuned_file << tag_open(o,@s) @@ -1193,7 +1234,7 @@ or this level should be 5~ rather #{dob.lv}" #level 6 puts_tag_close(o.ln,hs) puts_tag_open(o,@s) end - hs=[3,true,true,true] + hs=[3,true,true,true,true] when 4 tuned_file << tag_close(o.ln,hs) tuned_file << tag_open(o,@s) @@ -1233,9 +1274,10 @@ or this level should be 5~ rather #{dob.lv}" #level 6 ? %{<#{o[:lv]} id="#{o[:node]}">} : "" ln=case o[:lv] - when 'A' then 1 - when 'B' then 2 - when 'C' then 3 + when 'A' then 0 + when 'B' then 1 + when 'C' then 2 + when 'D' then 3 when '1' then 4 when '2' then 5 when '3' then 6 @@ -1254,6 +1296,11 @@ or this level should be 5~ rather #{dob.lv}" #level 6 def tag_close(lev,hs) ary=[] case hs[0] + when 0 + if (lev <= 0) and hs[0] + t={ lv: @s[0], status: 'close' } + ary << tags(t) + end when 1 if (lev <= 1) and hs[1] t={ lv: @s[1], status: 'close' } @@ -1376,6 +1423,9 @@ or this level should be 5~ rather #{dob.lv}" #level 6 end def puts_tag_close(lev,hs) case hs[0] + when 0 + #puts "#{@sp*0}" if (lev <= 0) and hs[0] + puts "" if (lev==0) when 1 puts "#{@sp*1}" if (lev <= 1) and hs[1] puts "" if (lev==0) -- cgit v1.2.3