aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/sisu/v5/ao_doc_str.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sisu/v5/ao_doc_str.rb')
-rw-r--r--lib/sisu/v5/ao_doc_str.rb211
1 files changed, 125 insertions, 86 deletions
diff --git a/lib/sisu/v5/ao_doc_str.rb b/lib/sisu/v5/ao_doc_str.rb
index 465a5666..31479252 100644
--- a/lib/sisu/v5/ao_doc_str.rb
+++ b/lib/sisu/v5/ao_doc_str.rb
@@ -8,7 +8,8 @@
* 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.
+ 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 Ralph Amissah,
+ All Rights Reserved.
* License: GPL 3 or later:
@@ -96,15 +97,16 @@ module SiSU_AO_DocumentStructureExtract
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
+ 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
+ when /4/ then 7
+ when /5/ then 8
+ when /6/ then 9
end
end
def image_test(str)
@@ -274,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)
@@ -293,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)
@@ -309,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)
@@ -400,8 +402,8 @@ module SiSU_AO_DocumentStructureExtract
elsif @@flag[:code]==:off
if t_o =~/^(?:code\{|[`]{3}\s+code)/
@@flag[:code]=case t_o
- when /^code\{/; :curls
- when /^[`]{3}\s+code/; :tics
+ when /^code\{/ then :curls
+ when /^[`]{3}\s+code/ then :tics
else @@flag[:code] #error
end
@@counter=1
@@ -410,8 +412,8 @@ module SiSU_AO_DocumentStructureExtract
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
+ when /^poem\{/ then :curls
+ when /^[`]{3}\s+poem/ then :tics
else @@flag[:poem] #error
end
h={ obj: 'poem start' } #introduce a counter
@@ -419,8 +421,8 @@ module SiSU_AO_DocumentStructureExtract
tuned_file << t_o
elsif t_o =~/^(?:group\{|[`]{3}\s+group)/
@@flag[:group]=case t_o
- when /^group\{/; :curls
- when /^[`]{3}\s+group/; :tics
+ when /^group\{/ then :curls
+ when /^[`]{3}\s+group/ then :tics
else @@flag[:group] #error
end
h={ obj: 'group text start' } #introduce a counter
@@ -428,8 +430,8 @@ module SiSU_AO_DocumentStructureExtract
tuned_file << t_o
elsif t_o =~/^(?:block\{|[`]{3}\s+block)/
@@flag[:block]=case t_o
- when /^block\{/; :curls
- when /^[`]{3}\s+block/; :tics
+ when /^block\{/ then :curls
+ when /^[`]{3}\s+block/ then :tics
else @@flag[:block] #error
end
h={ obj: 'block text start' } #introduce a counter
@@ -437,8 +439,8 @@ module SiSU_AO_DocumentStructureExtract
tuned_file << t_o
elsif t_o =~/^(?:alt\{|[`]{3}\s+alt)/
@@flag[:alt]=case t_o
- when /^alt\{/; :curls
- when /^[`]{3}\s+alt/; :tics
+ when /^alt\{/ then :curls
+ when /^[`]{3}\s+alt/ then :tics
else @@flag[:alt] #error
end
h={ obj: 'alt text start' } #introduce a counter
@@ -690,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)
@@ -767,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 }
@@ -798,38 +803,28 @@ 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~/
- 'none'
- when /B~/
- 'A~'
- when /C~/
- 'B~'
- when /1/
- 'A~, B~, C~'
- when /2/
- '1'
- when /3/
- '3'
+ when /A~/ then 'none'
+ when /B~/ then 'A~'
+ when /C~/ then 'B~'
+ when /D~/ then 'C~'
+ when /1/ then 'A~, B~, C~, D~'
+ when /2/ then '1'
+ when /3/ then '2'
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'
+ when /A~/ then 'B~, 1'
+ when /B~/ then 'C~, 1'
+ when /C~/ then 'D~, 1'
+ when /D~/ then '1'
+ when /1/ then '2'
+ when /2/ then '3'
+ when /3/ then 'none'
end
end
self
@@ -857,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) \
@@ -872,22 +867,24 @@ 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'; 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
+ 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
+ when '4' then 7
+ when '5' then 8
+ when '6' then 9
end
end
if not dob.obj =~/~#|-#/
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 \
@@ -897,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
@@ -907,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 \
@@ -982,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)
@@ -1155,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'
@@ -1181,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)
@@ -1188,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)
@@ -1196,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)
@@ -1204,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)
@@ -1244,15 +1274,16 @@ or this level should be 5~ rather #{dob.lv}" #level 6
? %{<#{o[:lv]} id="#{o[:node]}">}
: "</#{o[:lv]}>"
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
+ 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
+ when '4' then 7
+ when '5' then 8
+ when '6' then 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
@@ -1265,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' }
@@ -1387,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)