aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/sisu/v6/ao_doc_str.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sisu/v6/ao_doc_str.rb')
-rw-r--r--lib/sisu/v6/ao_doc_str.rb88
1 files changed, 82 insertions, 6 deletions
diff --git a/lib/sisu/v6/ao_doc_str.rb b/lib/sisu/v6/ao_doc_str.rb
index d8c012fd..3eb4a804 100644
--- a/lib/sisu/v6/ao_doc_str.rb
+++ b/lib/sisu/v6/ao_doc_str.rb
@@ -847,18 +847,43 @@ module SiSU_AO_DocumentStructureExtract
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])})
+ STDERR.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])})
--- }
+SKIPPED processing file: [#{@md.opt.lng}] "#{@md.fns}"}
+ $process_document = :skip
end
end
end
def warning_incorrect_parent_level_or_level(txt)
- puts %{warning,
-#{txt}
-has incorrect level and/or parent level}
+ puts %{ERROR. There is an error in markup of heading levels either here or in the parent heading.
+The current header reads:
+"#{txt}"
+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:
+
+@title:
+SKIPPED processing file: [#{@md.opt.lng}] "#{@md.fns}"
+}
+ $process_document = :skip
+ end
+ 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}"
+}
+ $process_document = :skip
+ end
end
def ocn #and auto segment numbering increment
+ required_headers_present?
data=@data
@o_array=[]
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
@@ -866,6 +891,7 @@ has incorrect level and/or parent level}
parent=node1=node2=node3=node4=node5=node6=nil
node0='0:0;0'
@collapsed_lv0=0
+ @lev_occurences={ a: 0, b: 0, c: 0, d: 0, l1: 0, l2: 0, l3: 0 }
data.each do |dob|
h={}
if (dob.obj !~ regex_exclude_ocn_and_node || dob.is==:code) \
@@ -875,7 +901,7 @@ has incorrect level and/or parent level}
&& dob.ocn_
#dob.ln now is determined, and set earlier, check how best to remove this -->
if dob.is==:heading
- ln=case dob.lv
+ @ln=ln=case dob.lv
when 'A' then 0
when 'B' then 1
when 'C' then 2
@@ -905,11 +931,13 @@ has incorrect level and/or parent level}
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
@@ -919,11 +947,13 @@ has incorrect level and/or parent level}
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
@@ -932,6 +962,7 @@ has incorrect level and/or parent level}
@collapsed_lv1=@collapsed_lv0+1
node0
else
+ warning_incorrect_parent_level_or_level(dob.obj)
document_structure_check_info(node0,node0,:error)
node0
end
@@ -939,11 +970,13 @@ has incorrect level and/or parent level}
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
@@ -952,6 +985,7 @@ has incorrect level and/or parent level}
@collapsed_lv2=@collapsed_lv1+1
node1
else
+ warning_incorrect_parent_level_or_level(dob.obj)
document_structure_check_info(node2,node0,:error)
node0
end
@@ -959,11 +993,13 @@ has incorrect level and/or parent level}
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
@@ -988,6 +1024,7 @@ or this level should be level :B~ rather than #{dob.lv}}
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
@@ -1021,6 +1058,7 @@ or this level should be level :B~ rather than #{dob.lv}}
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
@@ -1049,6 +1087,7 @@ or this level should be level :B~ rather than #{dob.lv}}
@collapsed_lv5=@collapsed_lv1+1
node1
else
+ warning_incorrect_parent_level_or_level(dob.obj)
document_structure_check_info(node5,node0,:error)
node0
end
@@ -1056,6 +1095,7 @@ or this level should be level :B~ rather than #{dob.lv}}
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
@@ -1092,6 +1132,7 @@ or this level should be 5~ rather #{dob.lv}" #level 6
@collapsed_lv6=@collapsed_lv1+1
node1
else
+ warning_incorrect_parent_level_or_level(dob.obj)
document_structure_check_info(node6,node0,:error)
node0
end
@@ -1099,6 +1140,29 @@ or this level should be 5~ rather #{dob.lv}" #level 6
node,ocn_sp=node6,"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]}
+}
+ 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'
+ 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"')
+ $process_document = :skip
+ break
+ end
if not dob.obj =~/~#|-#/
ocn_flag=true
else
@@ -1177,6 +1241,18 @@ or this level should be 5~ rather #{dob.lv}" #level 6
end
@o_array << dob
end
+ 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}"}
+ $process_document = :skip
+ end
+ 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}"}
+ $process_document = :skip
+ end
@o_array
end
end