diff options
Diffstat (limited to 'lib/sisu/develop/ao_doc_str.rb')
-rw-r--r-- | lib/sisu/develop/ao_doc_str.rb | 690 |
1 files changed, 350 insertions, 340 deletions
diff --git a/lib/sisu/develop/ao_doc_str.rb b/lib/sisu/develop/ao_doc_str.rb index bf7716dc..7f054660 100644 --- a/lib/sisu/develop/ao_doc_str.rb +++ b/lib/sisu/develop/ao_doc_str.rb @@ -1233,8 +1233,8 @@ module SiSU_AO_DocumentStructureExtract end end class OCN - def initialize(md,data) - @md,@data=md,data + def initialize(md,data,fnx,process) + @md,@data,@fnx,@process=md,data,fnx,process end def structure_info def lv @@ -1294,31 +1294,33 @@ has incorrect level and/or parent level --} end def required_headers_present? - unless (defined? @md.title \ - and @md.title.full) - STDERR.puts %{required header missing: + if @process == :complete + unless (defined? @md.title \ + and @md.title.full) + STDERR.puts %{required header missing: @title: SKIPPED processing file: [#{@md.opt.lng}] "#{@md.fns}" } - if @md.opt.act[:no_stop][:set]==:on - $process_document = :skip - else exit + if @md.opt.act[:no_stop][:set]==:on + $process_document = :skip + else exit + end end - end - unless (defined? @md.creator.author \ - and @md.creator.author) - STDERR.puts %{required header missing: + unless (defined? @md.creator.author \ + and @md.creator.author) + STDERR.puts %{required header missing: @creator: :author: anonymous? SKIPPED processing file: [#{@md.opt.lng}] "#{@md.fns}" } - if @md.opt.act[:no_stop][:set]==:on - $process_document = :skip - else exit + if @md.opt.act[:no_stop][:set]==:on + $process_document = :skip + else exit + end end end end @@ -1357,337 +1359,341 @@ SKIPPED processing file: if not dob.obj =~/~#|-#/ ocn+=1 end - if dob.is==:heading \ - 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 \ - or ln.to_s =~@md.lv4 \ - or ln.to_s =~@md.lv5 \ - or ln.to_s =~@md.lv6 \ - or ln.to_s =~@md.lv7) - if not dob.obj =~/~#|-#/ - ocnh+=1 - end - if ln==0 \ - or ln=~@md.lv0 - @lev_occurences[:a] += 1 - if not dob.obj =~/~#|-#/ - ocn_flag=true - ocnh0+=1 #heading - node0="0:#{ocnh0};#{ocn}" - else - #document_structure_check_info(node0,node0,:error) #fix - 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 - @lev_occurences[:b] += 1 + if @process == :complete \ + or (@fnx == @md.opt.fns \ + && @md.opt.fns =~/.sst$/) + if dob.is==:heading \ + 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 \ + or ln.to_s =~@md.lv4 \ + or ln.to_s =~@md.lv5 \ + or ln.to_s =~@md.lv6 \ + or ln.to_s =~@md.lv7) if not dob.obj =~/~#|-#/ - ocn_flag=true - ocnh1+=1 #heading - node1="1:#{ocnh1};#{ocn}" - else - #document_structure_check_info(node0,node0,:error) #fix - ocn_flag=false - node1="1:0;0" + ocnh+=1 end - parent=if node0 - document_structure_check_info(node1,node0) - @collapsed_lv1=@collapsed_lv0+1 - node0 - else - warning_incorrect_parent_level_or_level(dob.obj) - 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 \ - or ln=~@md.lv2 - @lev_occurences[:c] += 1 - if not dob.obj =~/~#|-#/ - ocn_flag=true - ocnh2+=1 - node2="2:#{ocnh2};#{ocn}" - else - #document_structure_check_info(node0,node0,:error) #fix - ocn_flag=false - node2="2:0;0" - end - parent=if node1 - document_structure_check_info(node2,node1) - @collapsed_lv2=@collapsed_lv1+1 - node1 - else - warning_incorrect_parent_level_or_level(dob.obj) - 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 - @lev_occurences[:d] += 1 - if not dob.obj =~/~#|-#/ - ocn_flag=true - ocnh3+=1 - node3="3:#{ocnh3};#{ocn}" - else - #document_structure_check_info(node0,node0,:error) #fix - 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} + if ln==0 \ + or ln=~@md.lv0 + @lev_occurences[:a] += 1 + if not dob.obj =~/~#|-#/ + ocn_flag=true + ocnh0+=1 #heading + node0="0:#{ocnh0};#{ocn}" + else + #document_structure_check_info(node0,node0,:error) #fix + 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 + @lev_occurences[:b] += 1 + if not dob.obj =~/~#|-#/ + ocn_flag=true + ocnh1+=1 #heading + node1="1:#{ocnh1};#{ocn}" + else + #document_structure_check_info(node0,node0,:error) #fix + ocn_flag=false + node1="1:0;0" + end + parent=if node0 + document_structure_check_info(node1,node0) + @collapsed_lv1=@collapsed_lv0+1 + node0 + else + warning_incorrect_parent_level_or_level(dob.obj) + 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 \ + or ln=~@md.lv2 + @lev_occurences[:c] += 1 + if not dob.obj =~/~#|-#/ + ocn_flag=true + ocnh2+=1 + node2="2:#{ocnh2};#{ocn}" + else + #document_structure_check_info(node0,node0,:error) #fix + ocn_flag=false + node2="2:0;0" + end + parent=if node1 + document_structure_check_info(node2,node1) + @collapsed_lv2=@collapsed_lv1+1 + node1 + else + warning_incorrect_parent_level_or_level(dob.obj) + 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 + @lev_occurences[:d] += 1 + if not dob.obj =~/~#|-#/ + ocn_flag=true + ocnh3+=1 + node3="3:#{ocnh3};#{ocn}" + else + #document_structure_check_info(node0,node0,:error) #fix + 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 - @lev_occurences[:l1] += 1 - 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 - 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) - node0 - end - collapsed_level=@collapsed_lv4 - node,ocn_sp=node4,"h#{ocnh}" - elsif ln==5 \ - or ln=~@md.lv5 - @lev_occurences[:l2] += 1 - 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 - warning_incorrect_parent_level_or_level(dob.obj) - 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 - @lev_occurences[:l3] += 1 - 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 (1~) & this level ##{dob.ln} (#{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 + @lev_occurences[:l1] += 1 + 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 + 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) + node0 + end + collapsed_level=@collapsed_lv4 + node,ocn_sp=node4,"h#{ocnh}" + elsif ln==5 \ + or ln=~@md.lv5 + @lev_occurences[:l2] += 1 + 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 + warning_incorrect_parent_level_or_level(dob.obj) + 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 + @lev_occurences[:l3] += 1 + 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 (1~) & this level ##{dob.ln} (#{dob.lv}~) either parent should be level #5 (2~) or this level should be #5 (2~) rather ##{dob.ln} (#{dob.lv}~)" - 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 - warning_incorrect_parent_level_or_level(dob.obj) - document_structure_check_info(node6,node0,:error) - node0 - end - collapsed_level=@collapsed_lv6 - node,ocn_sp=node6,"h#{ocnh}" - elsif ln==7 \ - or ln=~@md.lv7 - @lev_occurences[:l4] += 1 - if not dob.obj =~/~#|-#/ - ocn_flag=true - ocnh7+=1 - node7="7:#{ocnh7};#{ocn}" - else - ocn_flag=false - node7="7:0;0" - end - parent=if node6 - document_structure_check_info(node7,node6) - @collapsed_lv7=@collapsed_lv6+1 - node5 - elsif node5 - warning_incorrect_parent_level_or_level(dob.obj) - puts "parent is level #5 (2~) & this level ##{dob.ln} (#{dob.lv}~) + 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 + warning_incorrect_parent_level_or_level(dob.obj) + document_structure_check_info(node6,node0,:error) + node0 + end + collapsed_level=@collapsed_lv6 + node,ocn_sp=node6,"h#{ocnh}" + elsif ln==7 \ + or ln=~@md.lv7 + @lev_occurences[:l4] += 1 + if not dob.obj =~/~#|-#/ + ocn_flag=true + ocnh7+=1 + node7="7:#{ocnh7};#{ocn}" + else + ocn_flag=false + node7="7:0;0" + end + parent=if node6 + document_structure_check_info(node7,node6) + @collapsed_lv7=@collapsed_lv6+1 + node5 + elsif node5 + warning_incorrect_parent_level_or_level(dob.obj) + puts "parent is level #5 (2~) & this level ##{dob.ln} (#{dob.lv}~) either parent should be level #6 (3~) or this level should be #6 (3~) rather ##{dob.ln} (#{dob.lv}~)" - document_structure_check_info(node7,node5,:error) - @collapsed_lv6=@collapsed_lv5+1 - node5 - elsif node4 - warning_incorrect_parent_level_or_level(dob.obj) - puts "parent is level #4 (1~) & this level ##{dob.ln} (#{dob.lv}~) + document_structure_check_info(node7,node5,:error) + @collapsed_lv6=@collapsed_lv5+1 + node5 + elsif node4 + warning_incorrect_parent_level_or_level(dob.obj) + puts "parent is level #4 (1~) & this level ##{dob.ln} (#{dob.lv}~) either parent should be level 6~ or this level should be #6 (3~) rather ##{dob.ln} (#{dob.lv}~)" - document_structure_check_info(node7,node4,:error) - @collapsed_lv6=@collapsed_lv4+1 - node4 - elsif node3 - warning_incorrect_parent_level_or_level(dob.obj) - document_structure_check_info(node7,node3,:error) - @collapsed_lv6=@collapsed_lv3+1 - node3 - elsif node2 - warning_incorrect_parent_level_or_level(dob.obj) - document_structure_check_info(node7,node2,:error) - @collapsed_lv6=@collapsed_lv2+1 - node2 - elsif node1 - warning_incorrect_parent_level_or_level(dob.obj) - document_structure_check_info(node7,node1,:error) - @collapsed_lv6=@collapsed_lv1+1 - node1 - else - warning_incorrect_parent_level_or_level(dob.obj) - document_structure_check_info(node7,node0,:error) - node0 + document_structure_check_info(node7,node4,:error) + @collapsed_lv6=@collapsed_lv4+1 + node4 + elsif node3 + warning_incorrect_parent_level_or_level(dob.obj) + document_structure_check_info(node7,node3,:error) + @collapsed_lv6=@collapsed_lv3+1 + node3 + elsif node2 + warning_incorrect_parent_level_or_level(dob.obj) + document_structure_check_info(node7,node2,:error) + @collapsed_lv6=@collapsed_lv2+1 + node2 + elsif node1 + warning_incorrect_parent_level_or_level(dob.obj) + document_structure_check_info(node7,node1,:error) + @collapsed_lv6=@collapsed_lv1+1 + node1 + else + warning_incorrect_parent_level_or_level(dob.obj) + document_structure_check_info(node7,node0,:error) + node0 + end + collapsed_level=@collapsed_lv7 + node,ocn_sp=node7,"h#{ocnh}" end - collapsed_level=@collapsed_lv7 - node,ocn_sp=node7,"h#{ocnh}" - end - else - unless @lev_occurences[:l1] > 0 - STDERR.puts %{Substantive text objects must follow a level 1~ heading and there are none at this point in processing: #{@lev_occurences[:l1]} + else + unless @lev_occurences[:l1] > 0 + STDERR.puts %{Substantive text objects must follow a level 1~ heading and there are none at this point in processing: #{@lev_occurences[:l1]} SKIPPED processing file: [#{@md.opt.lng}] "#{@md.fns}"} - puts dob.obj #.gsub(/^(.{1,80})/,'"\1"') - exit - end - unless @ln >= 4 - lev=case @ln - when 0 then 'A' - when 1 then 'B' - when 2 then 'C' - when 3 then 'D' - when 4 then '1' - when 5 then '2' - when 6 then '3' - when 7 then '4' - when 8 then '5' - when 9 then '6' + puts dob.obj #.gsub(/^(.{1,80})/,'"\1"') + exit end - STDERR.puts %{Substantive text objects must follow a level 1~ 2~ or 3~ heading: #{lev}~ + unless @ln >= 4 + lev=case @ln + when 0 then 'A' + when 1 then 'B' + when 2 then 'C' + when 3 then 'D' + when 4 then '1' + when 5 then '2' + when 6 then '3' + when 7 then '4' + when 8 then '5' + when 9 then '6' + end + STDERR.puts %{Substantive text objects must follow a level 1~ 2~ or 3~ heading: #{lev}~ SKIPPED processing file: [#{@md.opt.lng}] "#{@md.fns}"} - puts dob.obj.gsub(/^(.{1,80})/,'"\1"') - if @md.opt.act[:no_stop][:set]==:on - $process_document = :skip - break - else exit + puts dob.obj.gsub(/^(.{1,80})/,'"\1"') + if @md.opt.act[:no_stop][:set]==:on + $process_document = :skip + break + else exit + end + end + 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==:box \ + || 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 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==:box \ - || 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 @@ -1736,24 +1742,28 @@ SKIPPED processing file: end @o_array << dob end - unless @lev_occurences[:a] == 1 - STDERR.puts %{The number of level A~ in this document: #{@lev_occurences[:a]} + if @process == :complete \ + or (@fnx == @md.opt.fns \ + && @md.opt.fns =~/.sst$/) + unless @lev_occurences[:a] == 1 + STDERR.puts %{The number of level A~ in this document: #{@lev_occurences[:a]} There must be one level A~ (no more and no less) SKIPPED processing file: [#{@md.opt.lng}] "#{@md.fns}"} - if @md.opt.act[:no_stop][:set]==:on - $process_document = :skip - else exit + if @md.opt.act[:no_stop][:set]==:on + $process_document = :skip + else exit + end end - end - unless @lev_occurences[:l1] > 0 - STDERR.puts %{The number of level 1~ in this document: #{@lev_occurences[:l1]} + unless @lev_occurences[:l1] > 0 + STDERR.puts %{The number of level 1~ in this document: #{@lev_occurences[:l1]} There must be at least one level 1~ (and as many as required) SKIPPED processing file: [#{@md.opt.lng}] "#{@md.fns}"} - if @md.opt.act[:no_stop][:set]==:on - $process_document = :skip - else exit + if @md.opt.act[:no_stop][:set]==:on + $process_document = :skip + else exit + end end end @o_array |