From 1832a937713d33517066dc4cf8222871045b2b58 Mon Sep 17 00:00:00 2001
From: Ralph Amissah <ralph@amissah.com>
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")
---
 data/doc/sisu/CHANGELOG_v5     |  27 ++++++++--
 lib/sisu/v5/ao_doc_objects.rb  |  22 ++++----
 lib/sisu/v5/ao_doc_str.rb      | 120 +++++++++++++++++++++++++++++------------
 lib/sisu/v5/ao_idx.rb          |   2 +-
 lib/sisu/v5/ao_misc_arrange.rb |   2 +-
 lib/sisu/v5/ao_numbering.rb    |  12 ++---
 lib/sisu/v5/param.rb           |   8 ++-
 7 files changed, 134 insertions(+), 59 deletions(-)

diff --git a/data/doc/sisu/CHANGELOG_v5 b/data/doc/sisu/CHANGELOG_v5
index e359ad89..9e7547dd 100644
--- a/data/doc/sisu/CHANGELOG_v5
+++ b/data/doc/sisu/CHANGELOG_v5
@@ -33,10 +33,29 @@ http://www.jus.uio.no/sisu/pkg/src/sisu_5.2.0.orig.tar.xz
   sisu_5.2.0.orig.tar.xz
   sisu_5.2.0-1.dsc
 
-* recalibrate heading levels A~ root 0, introduce possible D~
-  * downstream code consequences
-  * markup change of possibilities with possible (occasional) consequences
-  * v5 now diverges "un-merge-ably" from v4
+* 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")
+
+  Notes, rule imposed: heading level A~ becomes, document title & sole document
+  root. Significant as an expressed rule/principle, it simplifies making certain
+  document formats in particular some xml outputs, however, this has been pretty
+  much the case in practice (most documents have this implicit structure) and
+  will affect the markup of very few documents (for example all markup examples
+  so far provided are this way). This being the case, it is a subtle change,
+  because it will not be noticed (by the user) in a majority of cases. The most
+  significant changes are to internal sisu code: it is not yet enforced by the
+  software (software checks); it has implications for the way document output is
+  created; it has implications for document structure regex matches, that now
+  are attached to levels starting below level A~ (from B~ down) rather than
+  level A. One document affected by single root/title level A~ markup rule and
+  that provides a short test (for a document prepared using document structure
+  regex matches), is the U.N. Convention on Contracts for the International Sale
+  of Goods (CISG) that requires levels A-D & 1, and in previous versions of sisu
+  exceptionally required multiple level A's (using levels A-C & 1)
 
 * bin/sisu
   * (ensure SiSU_version_dir) fix
diff --git a/lib/sisu/v5/ao_doc_objects.rb b/lib/sisu/v5/ao_doc_objects.rb
index 229edee4..70696d37 100644
--- a/lib/sisu/v5/ao_doc_objects.rb
+++ b/lib/sisu/v5/ao_doc_objects.rb
@@ -108,9 +108,10 @@ module SiSU_AO_DocumentStructure
     end
     def heading_ln(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
@@ -121,9 +122,10 @@ module SiSU_AO_DocumentStructure
     end
     def heading_lv(ln)
       case ln.to_s
-      when /1/ then 'A'
-      when /2/ then 'B'
-      when /3/ then 'C'
+      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'
@@ -134,10 +136,10 @@ module SiSU_AO_DocumentStructure
     end
     def heading(h,o=nil)
       if not h[:ln] \
-      and (h[:lv] and h[:lv]=~/[1-6A-C]/)
+      and (h[:lv] and h[:lv]=~/[1-6A-D]/)
         h[:ln]=heading_ln(h[:lv])
       elsif not h[:lv] \
-      and (h[:ln] and h[:ln].to_s=~/[1-9]/)
+      and (h[:ln] and h[:ln].to_s=~/[0-9]/)
         h[:lv]=heading_lv(h[:ln])
       end
       of=     @of                                                              #String, classification - group
@@ -151,7 +153,7 @@ module SiSU_AO_DocumentStructure
       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
+      lv=     h[:lv]      || ((defined? o.lv)        ? o.lv      : nil)        #Alpha-numeric, document structure as used in markup, A-D 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)
@@ -401,7 +403,7 @@ module SiSU_AO_DocumentStructure
       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
+      lv=     h[:lv]      || ((defined? o.lv)        ? o.lv      : nil)        #Alpha-numeric, document structure as used in markup, A-D 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]
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|<hr width|#{Mx[:br_endnotes]}|\A\s*\Z/mi #ocn here #&nbsp; added with Tune.code #ยก
       parent=node1=node2=node3=node4=node5=node6=nil
       node0='0:0;0'
-      @collapsed_lv1=1
+      @collapsed_lv0=0
       data.each do |dob|
         h={}
         if (dob.obj !~ regex_exclude_ocn_and_node || dob.is==:code) \
@@ -861,9 +867,10 @@ has incorrect level and/or parent level}
           #dob.ln now is determined, and set earlier, check how best to remove this -->
           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]}">}
       : "</#{o[:lv]}>"
       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}</#{@s[0]}>" if (lev <= 0) and hs[0]
+        puts "</#{@s[0]}>"         if (lev==0)
       when 1
         puts "#{@sp*1}</#{@s[1]}>" if (lev <= 1) and hs[1]
         puts "</#{@s[0]}>"         if (lev==0)
diff --git a/lib/sisu/v5/ao_idx.rb b/lib/sisu/v5/ao_idx.rb
index 32a33b50..aa5f6609 100644
--- a/lib/sisu/v5/ao_idx.rb
+++ b/lib/sisu/v5/ao_idx.rb
@@ -142,7 +142,7 @@ module SiSU_AO_BookIndex
       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"}
+      h={lv: '1', name: 'index', obj: "Index"}
       o=SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h)
       idx[:sst_rel_html_seg] << o
       idx[:sst_rel] << o
diff --git a/lib/sisu/v5/ao_misc_arrange.rb b/lib/sisu/v5/ao_misc_arrange.rb
index f6ebd78d..caf3326c 100644
--- a/lib/sisu/v5/ao_misc_arrange.rb
+++ b/lib/sisu/v5/ao_misc_arrange.rb
@@ -67,7 +67,7 @@ module SiSU_AO_MiscArrangeText
     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
+        gsub(/^((?:[1-9]|:?[A-D])~\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")
diff --git a/lib/sisu/v5/ao_numbering.rb b/lib/sisu/v5/ao_numbering.rb
index 0458d626..8caa5ccc 100644
--- a/lib/sisu/v5/ao_numbering.rb
+++ b/lib/sisu/v5/ao_numbering.rb
@@ -158,7 +158,7 @@ module SiSU_AO_Numbering
             @subnumber=1
             @subnumber=0 if dob.ln==no1
           end
-          if dob.ln.to_s =~/^[1-6]/ \
+          if dob.ln.to_s =~/^[0-6]/ \
           and not dob.toc_ \
           and dob.obj !~/#{Mx[:fa_o]}(?:~#|-#)#{Mx[:fa_c]}/ # <-- fix
             if dob.ln==no1
@@ -206,7 +206,7 @@ module SiSU_AO_Numbering
               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]/ \
+          elsif dob.ln.to_s =~/^[0-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')
@@ -216,7 +216,7 @@ module SiSU_AO_Numbering
         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.ln.to_s =~/^[0-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
@@ -250,7 +250,7 @@ module SiSU_AO_Numbering
         || 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)
+          and dob.ln.to_s=~/^[0-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]/ \
@@ -373,7 +373,7 @@ module SiSU_AO_Numbering
           : @segname
           tags["#{dob.ocn}"]={ segname: @segname }
           ocn_html_seg[dob.ocn]=if (dob.is==:heading || dob.is==:heading_insert)
-            if dob.ln =~/[1-3]/
+            if dob.ln =~/[0-3]/
               { seg: nil, level: dob.ln }
             else #elsif dob.ln =~/[4-6]/
               { seg: @seg, level: dob.ln }
@@ -446,7 +446,7 @@ module SiSU_AO_Numbering
         @tuned_file=[]
         data.each do |dob|
           unless @md.set_heading_seg
-            if defined? dob.ln and dob.ln.to_s !~/^[123]/m \
+            if defined? dob.ln and dob.ln.to_s !~/^[0-3]/m \
             and dob.obj !~/\A\s*\Z/m \
             and dob.is !=:layout
               @md.set_heading_seg=true
diff --git a/lib/sisu/v5/param.rb b/lib/sisu/v5/param.rb
index 9585696e..7288842d 100644
--- a/lib/sisu/v5/param.rb
+++ b/lib/sisu/v5/param.rb
@@ -832,9 +832,9 @@ module SiSU_Param
       @doc={ lv: [] }
       @doc[:fns],@doc[:fnb],@doc[:scr_suffix]='','',''
       @@publisher='SiSU scribe'
-      attr_accessor :make,:env,:path,:file,:fn,:fns,:fno,:fnb,:fnn,:fnt,:fnl,:flv,:fnz,:fnstex,:ocn,:sfx_src,:pdf,:file_type,:dir_out,:dir_tex,:dir_lout,:txt_path,:sisu,:sisu_version,:ruby_version,:title,:subtitle,:full_title,:html_title,:subtitle_tex,:creator,:classify,:author_home,:author,:author_title,:author_nationality,:authors,:authorship,:translator,:illustrator,:prepared_by,:digitized_by,:subject,:description,:publisher,:current_publisher,:contributor,:date,:date_created,:date_issued,:date_available,:date_valid,:date_modified,:date_translated,:date_added_to_site,:date_scheme,:date_created_scheme,:date_issued_scheme,:date_available_scheme,:date_valid_scheme,:date_modified_scheme,:type,:format,:identifier,:source,:language,:language_original,:relation,:coverage,:rights,:keywords,:comments,:abstract,:cls_loc,:cls_dewey,:cls_pg,:cls_isbn,:papersize,:papersize_array,:toc,:lv1,:lv2,:lv3,:lv4,:lv5,:lv6,:lvs,:pagenew,:pagebreak,:pageline,:num_top,:bold_match_list,:italics_match_list,:substitution_match_list,:emphasis_set_to,:toc_lev_limit,:flag_endnotes,:flag_auto_endnotes,:flag_separate_endnotes,:flag_separate_endnotes_make,:markup,:markup_instruction,:flag_tables,:vocabulary,:doc_css,:yaml,:lnk,:links,:prefix_a,:prefix_b,:suffix,:information,:contact,:icon,:image,:ad_url,:ad_png,:ad_alt,:ad_began,:flag_promo,:promo,:ad_home,:stmp,:stmpd,:sc_filename,:sc_number,:sc_date,:sc_time,:sc_info,:yamladdr,:locale,:wc_lines,:wc_words,:wc_bytes,:file_encoding,:filesize,:user,:home,:hostname,:pwd,:firstseg,:programs,:author_copymark,:i18n,:lang,:lang_code_insert,:en,:notes,:dgst,:generated,:tags,:tag_array,:concord_make,:seg_names,:seg_autoname_safe,:set_header_title,:set_heading_top,:set_heading_seg,:heading_seg_first,:heading_seg_first_flag,:base_program,:ec,:opt,:sem_tag,:book_idx,:topic_register,:topic_register_array,:original,:writing_focus,:audio,:daisy,:home_button_image,:home_button_links,:footer_links,:cover_image,:man_section
+      attr_accessor :make,:env,:path,:file,:fn,:fns,:fno,:fnb,:fnn,:fnt,:fnl,:flv,:fnz,:fnstex,:ocn,:sfx_src,:pdf,:file_type,:dir_out,:dir_tex,:dir_lout,:txt_path,:sisu,:sisu_version,:ruby_version,:title,:subtitle,:full_title,:html_title,:subtitle_tex,:creator,:classify,:author_home,:author,:author_title,:author_nationality,:authors,:authorship,:translator,:illustrator,:prepared_by,:digitized_by,:subject,:description,:publisher,:current_publisher,:contributor,:date,:date_created,:date_issued,:date_available,:date_valid,:date_modified,:date_translated,:date_added_to_site,:date_scheme,:date_created_scheme,:date_issued_scheme,:date_available_scheme,:date_valid_scheme,:date_modified_scheme,:type,:format,:identifier,:source,:language,:language_original,:relation,:coverage,:rights,:keywords,:comments,:abstract,:cls_loc,:cls_dewey,:cls_pg,:cls_isbn,:papersize,:papersize_array,:toc,:lv0,:lv1,:lv2,:lv3,:lv4,:lv5,:lv6,:lvs,:pagenew,:pagebreak,:pageline,:num_top,:bold_match_list,:italics_match_list,:substitution_match_list,:emphasis_set_to,:toc_lev_limit,:flag_endnotes,:flag_auto_endnotes,:flag_separate_endnotes,:flag_separate_endnotes_make,:markup,:markup_instruction,:flag_tables,:vocabulary,:doc_css,:yaml,:lnk,:links,:prefix_a,:prefix_b,:suffix,:information,:contact,:icon,:image,:ad_url,:ad_png,:ad_alt,:ad_began,:flag_promo,:promo,:ad_home,:stmp,:stmpd,:sc_filename,:sc_number,:sc_date,:sc_time,:sc_info,:yamladdr,:locale,:wc_lines,:wc_words,:wc_bytes,:file_encoding,:filesize,:user,:home,:hostname,:pwd,:firstseg,:programs,:author_copymark,:i18n,:lang,:lang_code_insert,:en,:notes,:dgst,:generated,:tags,:tag_array,:concord_make,:seg_names,:seg_autoname_safe,:set_header_title,:set_heading_top,:set_heading_seg,:heading_seg_first,:heading_seg_first_flag,:base_program,:ec,:opt,:sem_tag,:book_idx,:topic_register,:topic_register_array,:original,:writing_focus,:audio,:daisy,:home_button_image,:home_button_links,:footer_links,:cover_image,:man_section
       def initialize(fns_array,opt)
-        @env=@path,@file=@fn=@fns=@fno=@fnb=@fnn=@fnt=@fnl=@flv=@fnz=@fnstex=@ocn=@sfx_src=@pdf=@file_type=@dir_out=@dir_tex=@dir_lout=@txt_path=@make=@flag_endnotes=@flag_auto_endnotes=@flag_separate_endnotes=@flag_separate_endnotes_make=@sisu=@sisu_version=@ruby_version=@title=@subtitle=@full_title=@html_title=@subtitle_tex=@creator=@classify=@author_home=@author=@author_title=@author_nationality=@translator=@illustrator=@prepared_by=@digitized_by=@subject=@description=@publisher=@current_publisher=@contributor=@date=@date_created=@date_issued=@date_available=@date_valid=@date_modified=@date_translated=@date_added_to_site=@date_scheme=@date_created_scheme=@date_issued_scheme=@date_available_scheme=@date_valid_scheme=@date_modified_scheme=@type=@format=@identifier=@source=@language=@language_original=@relation=@coverage=@rights=@keywords=@comments=@abstract=@cls_loc=@cls_dewey=@cls_pg=@cls_isbn=@papersize=@toc=@lv1=@lv2=@lv3=@lv4=@lv5=@lv6=@pagenew=@pagebreak=@pageline=@num_top=@bold_match_list=@italics_match_list=@substitution_match_list=@emphasis_set_to=@toc_lev_limit=@flag_tables=@vocabulary=@doc_css=@yaml=@lnk=@links=@prefix_a=@prefix_b=@suffix=@information=@contact=@icon=@ad_url=@ad_png=@ad_alt=@ad_began=@promo=@ad_home=@stmp=@stmpd=@sc_filename=@sc_number=@sc_date=@sc_time=@sc_info=@yamladdr=@locale=@wc_lines=@wc_words=@wc_bytes=@file_encoding=@filesize=@firstseg=@programs=@author_copymark=@i18n=@lang=@lang_code_insert=@en=@notes=@dgst=@generated=@heading_seg_first=@base_program=@topic_register=@original=@writing_focus=@audio=@home_button_image=@home_button_links=@cover_image=@man_section=nil
+        @env=@path,@file=@fn=@fns=@fno=@fnb=@fnn=@fnt=@fnl=@flv=@fnz=@fnstex=@ocn=@sfx_src=@pdf=@file_type=@dir_out=@dir_tex=@dir_lout=@txt_path=@make=@flag_endnotes=@flag_auto_endnotes=@flag_separate_endnotes=@flag_separate_endnotes_make=@sisu=@sisu_version=@ruby_version=@title=@subtitle=@full_title=@html_title=@subtitle_tex=@creator=@classify=@author_home=@author=@author_title=@author_nationality=@translator=@illustrator=@prepared_by=@digitized_by=@subject=@description=@publisher=@current_publisher=@contributor=@date=@date_created=@date_issued=@date_available=@date_valid=@date_modified=@date_translated=@date_added_to_site=@date_scheme=@date_created_scheme=@date_issued_scheme=@date_available_scheme=@date_valid_scheme=@date_modified_scheme=@type=@format=@identifier=@source=@language=@language_original=@relation=@coverage=@rights=@keywords=@comments=@abstract=@cls_loc=@cls_dewey=@cls_pg=@cls_isbn=@papersize=@toc=@lv0=@lv1=@lv2=@lv3=@lv4=@lv5=@lv6=@pagenew=@pagebreak=@pageline=@num_top=@bold_match_list=@italics_match_list=@substitution_match_list=@emphasis_set_to=@toc_lev_limit=@flag_tables=@vocabulary=@doc_css=@yaml=@lnk=@links=@prefix_a=@prefix_b=@suffix=@information=@contact=@icon=@ad_url=@ad_png=@ad_alt=@ad_began=@promo=@ad_home=@stmp=@stmpd=@sc_filename=@sc_number=@sc_date=@sc_time=@sc_info=@yamladdr=@locale=@wc_lines=@wc_words=@wc_bytes=@file_encoding=@filesize=@firstseg=@programs=@author_copymark=@i18n=@lang=@lang_code_insert=@en=@notes=@dgst=@generated=@heading_seg_first=@base_program=@topic_register=@original=@writing_focus=@audio=@home_button_image=@home_button_links=@cover_image=@man_section=nil
         @data,@path,@fns,@fno,@opt=fns_array,opt.pth,opt.fns,opt.fno,opt #@data used as data
         @flag_tables,@set_header_title,@set_heading_top,@set_heading_seg,@heading_seg_first_flag,@flag_promo,@book_idx=false,false,false,false,false,false,false
         @seg_autoname_safe=true
@@ -870,6 +870,7 @@ module SiSU_Param
           @pagebreak=common_makes[:pagebreak]
           @pageline=common_makes[:pageline]
           @toc=common_makes[:toc]
+          @lv0=common_makes[:lv0]
           @lv1=common_makes[:lv1]
           @lv2=common_makes[:lv2]
           @lv3=common_makes[:lv3]
@@ -1012,6 +1013,7 @@ module SiSU_Param
                 ? (makes[:pageline]) \
                 : @pageline
               @toc=(makes[:toc]) ? (makes[:toc]) : @toc
+              @lv0=(makes[:lv0]) ? (makes[:lv0]) : @lv0
               @lv1=(makes[:lv1]) ? (makes[:lv1]) : @lv1
               @lv2=(makes[:lv2]) ? (makes[:lv2]) : @lv2
               @lv3=(makes[:lv3]) ? (makes[:lv3]) : @lv3
@@ -1052,6 +1054,7 @@ module SiSU_Param
                 ? (makes[:cover_image]) \
                 : @cover_image
             end
+            @lv0 ||=/^0~/
             @lv1 ||=/^1~/
             @lv2 ||=/^2~/
             @lv3 ||=/^3~/
@@ -1389,6 +1392,7 @@ module SiSU_Param
           end
         end
         @lnk=@lnk.compact if @lnk
+        @lv0 ||=/^0~/
         @lv1 ||=/^1~/
         @lv2 ||=/^2~/
         @lv3 ||=/^3~/
-- 
cgit v1.2.3