diff options
Diffstat (limited to 'lib/sisu/develop/ao_doc_str.rb')
-rw-r--r-- | lib/sisu/develop/ao_doc_str.rb | 246 |
1 files changed, 111 insertions, 135 deletions
diff --git a/lib/sisu/develop/ao_doc_str.rb b/lib/sisu/develop/ao_doc_str.rb index ae029002..bf7716dc 100644 --- a/lib/sisu/develop/ao_doc_str.rb +++ b/lib/sisu/develop/ao_doc_str.rb @@ -55,45 +55,21 @@ =end module SiSU_AO_DocumentStructureExtract + require_relative 'ao_persist' # ao_persist.rb class Instantiate < SiSU_Param::Parameters::Instructions - @@flag={ - ocn: :on, - code: :off, - lngsyn: :txt, - poem: :off, - block: :off, - box: :off, - group: :off, - alt: :off, - quote: :off, - table: :off, - table_to: :off, - } def initialize @@counter=@@column=@@columns=0 @@line_mode='' end end class Build - @@flag={ - ocn: :on, - code: :off, - lngsyn: :txt, - poem: :off, - block: :off, - box: :off, - group: :off, - alt: :off, - quote: :off, - table: :off, - table_to: :off, - } def initialize(md,data) @md,@data=md,data SiSU_AO_DocumentStructureExtract::Instantiate.new @pb=SiSU_AO_DocumentStructure::ObjectLayout.new.break(Hx[:br_page]) @pbn=SiSU_AO_DocumentStructure::ObjectLayout.new.break(Hx[:br_page_new]) @pbl=SiSU_AO_DocumentStructure::ObjectLayout.new.break(Hx[:br_page_line]) + @per=SiSU_AO_Persist::PersistDocStructExt.new end def ln_get(lv) case lv @@ -120,7 +96,7 @@ module SiSU_AO_DocumentStructureExtract : false end def quotes? - @@flag[:quote]==:open \ + @per.quote==:open \ ? true : false end @@ -273,24 +249,24 @@ module SiSU_AO_DocumentStructureExtract if t_o =~/^--([+~-])[#]$/ h=case $1 when /[+]/ - @@flag[:ocn]=:on + @per.ocn=:on { flag: :ocn_on, } when /[~]/ - @@flag[:ocn]=:ocn_off_headings_keep + @per.ocn=:ocn_off_headings_keep { flag: :ocn_off, mod: :headings_keep, } when /[-]/ #of particular relevance with level 1~ which is required to precede substantive text & used e.g. in html segmented text - @@flag[:ocn]=:ocn_off_headings_dummy_lev1 + @per.ocn=:ocn_off_headings_dummy_lev1 { flag: :ocn_off, mod: :headings_exclude, } else - @@flag[:ocn]=:on + @per.ocn=:on { flag: :ocn_on, } @@ -298,7 +274,7 @@ module SiSU_AO_DocumentStructureExtract t_o=SiSU_AO_DocumentStructure::ObjectFlag.new.flag_ocn(h) next end - t_o=t_o.gsub(/(?:\n\s*\n)+/m,"\n") if @@flag[:code]==:off + t_o=t_o.gsub(/(?:\n\s*\n)+/m,"\n") if @per.code==:off unless t_o =~/^(?:@\S+?:|%+)\s/ # extract book index for paragraph if any idx=if t_o=~/^=\{\s*(.+)\s*\}\s*$\Z/m m=$1 @@ -313,13 +289,13 @@ module SiSU_AO_DocumentStructureExtract end if t_o !~/^(?:code(?:\.[a-z][0-9a-z_]+)?|box(?:\.[a-z_]+)?|poem|alt|group|block)\{|^\}(?:code|poem|alt|group|block)|^(?:table\{|\{table)[ ~]/ \ and t_o !~/^```[ ]+(?:code(?:\.[a-z][0-9a-z_]+)?|box(?:\.[a-z_]+)?|poem|alt|group|block|table)|^```(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$|^`:quote_(?:open|close)`/ \ - and @@flag[:code]==:off \ - and @@flag[:poem]==:off \ - and @@flag[:group]==:off \ - and @@flag[:block]==:off \ - and @@flag[:alt]==:off \ - and @@flag[:box]==:off \ - and @@flag[:table]==:off + and @per.code==:off \ + and @per.poem==:off \ + and @per.group==:off \ + and @per.block==:off \ + and @per.alt==:off \ + and @per.box==:off \ + and @per.table==:off t_o=case t_o when /^#{Mx[:meta_o]}\S+?#{Mx[:meta_c]}/ #metadata, header if t_o=~/^#{Mx[:meta_o]}(\S+?)#{Mx[:meta_c]}\s*(.+)/m @@ -340,14 +316,14 @@ module SiSU_AO_DocumentStructureExtract obj=$1 note=endnote_test?(obj) obj,tags=extract_tags(obj) - if @@flag[:ocn]==:ocn_off_headings_dummy_lev1 \ - or @@flag[:ocn]==:ocn_off_headings_keep + if @per.ocn==:ocn_off_headings_dummy_lev1 \ + or @per.ocn==:ocn_off_headings_keep unless obj =~ /[~-][#]\s*$/ - if @@flag[:ocn]==:ocn_off_headings_dummy_lev1 \ + if @per.ocn==:ocn_off_headings_dummy_lev1 \ and t_o =~/^1\~\S*\s+/m obj << ' -#' - elsif @@flag[:ocn]==:ocn_off_headings_dummy_lev1 \ - or @@flag[:ocn]==:ocn_off_headings_keep + elsif @per.ocn==:ocn_off_headings_dummy_lev1 \ + or @per.ocn==:ocn_off_headings_keep obj << ' ~#' end end @@ -364,14 +340,14 @@ module SiSU_AO_DocumentStructureExtract name,obj=$1,$2 note=endnote_test?(obj) obj,tags=extract_tags(obj) - if @@flag[:ocn]==:ocn_off_headings_dummy_lev1 \ - or @@flag[:ocn]==:ocn_off_headings_keep + if @per.ocn==:ocn_off_headings_dummy_lev1 \ + or @per.ocn==:ocn_off_headings_keep unless obj =~ /[~-][#]\s*$/ - if @@flag[:ocn]==:ocn_off_headings_dummy_lev1 \ + if @per.ocn==:ocn_off_headings_dummy_lev1 \ and t_o =~/^1\~\S*\s+/m obj << ' -#' - elsif @@flag[:ocn]==:ocn_off_headings_dummy_lev1 \ - or @@flag[:ocn]==:ocn_off_headings_keep + elsif @per.ocn==:ocn_off_headings_dummy_lev1 \ + or @per.ocn==:ocn_off_headings_keep obj << ' ~#' end end @@ -389,14 +365,14 @@ module SiSU_AO_DocumentStructureExtract name,obj=$1,$2 note=endnote_test?(obj) obj,tags=extract_tags(obj,name) - if @@flag[:ocn]==:ocn_off_headings_dummy_lev1 \ - or @@flag[:ocn]==:ocn_off_headings_keep + if @per.ocn==:ocn_off_headings_dummy_lev1 \ + or @per.ocn==:ocn_off_headings_keep unless obj =~ /[~-][#]\s*$/ - if @@flag[:ocn]==:ocn_off_headings_dummy_lev1 \ + if @per.ocn==:ocn_off_headings_dummy_lev1 \ and t_o =~/^1\~\S*\s+/m obj << ' -#' - elsif @@flag[:ocn]==:ocn_off_headings_dummy_lev1 \ - or @@flag[:ocn]==:ocn_off_headings_keep + elsif @per.ocn==:ocn_off_headings_dummy_lev1 \ + or @per.ocn==:ocn_off_headings_keep obj << ' ~#' end end @@ -424,8 +400,8 @@ module SiSU_AO_DocumentStructureExtract note=endnote_test?(obj) obj,tags=extract_tags(obj) unless obj=~/\A\s*\Z/m - if @@flag[:ocn]==:ocn_off_headings_dummy_lev1 \ - or @@flag[:ocn]==:ocn_off_headings_keep + if @per.ocn==:ocn_off_headings_dummy_lev1 \ + or @per.ocn==:ocn_off_headings_keep unless obj =~ /[~-][#]\s*$/ obj << ' ~#' end @@ -457,8 +433,8 @@ module SiSU_AO_DocumentStructureExtract note=endnote_test?(obj) obj,tags=extract_tags(obj) unless obj=~/\A\s*\Z/m - if @@flag[:ocn]==:ocn_off_headings_dummy_lev1 \ - or @@flag[:ocn]==:ocn_off_headings_keep + if @per.ocn==:ocn_off_headings_dummy_lev1 \ + or @per.ocn==:ocn_off_headings_keep unless obj =~ /[~-][#]\s*$/ obj << ' ~#' end @@ -489,8 +465,8 @@ module SiSU_AO_DocumentStructureExtract image=image_test(t_o) note=endnote_test?(t_o) obj,tags=extract_tags(t_o) - if @@flag[:ocn]==:ocn_off_headings_dummy_lev1 \ - or @@flag[:ocn]==:ocn_off_headings_keep + if @per.ocn==:ocn_off_headings_dummy_lev1 \ + or @per.ocn==:ocn_off_headings_keep unless obj =~ /[~-][#]\s*$/ obj << ' ~#' end @@ -511,14 +487,14 @@ module SiSU_AO_DocumentStructureExtract end t_o=SiSU_AO_DocumentStructureExtract::Structure.new(@md).structure_markup(t_o) #must happen earlier, node info etc. require end - elsif @@flag[:code]==:off + elsif @per.code==:off if t_o =~/^(?:code(?:\.[a-z][0-9a-z_]+)?\{|```[ ]+code(?:\.[a-z][0-9a-z_]+)?)/ - @@flag[:code]=case t_o + @per.code=case t_o when /^code(?:\.[a-z][0-9a-z_]+)?\{/ then :curls when /^```[ ]+code/ then :tics - else @@flag[:code] #error + else @per.code #error end - @@flag[:lngsyn]=if t_o =~/^(?:code\.[a-z][0-9a-z_]+\{|```[ ]+code\.[a-z_]+)/ + @per.lngsyn=if t_o =~/^(?:code\.[a-z][0-9a-z_]+\{|```[ ]+code\.[a-z_]+)/ case t_o when /^code\.([a-z][0-9a-z_]+)\{/ :"#{$1}" @@ -539,14 +515,14 @@ module SiSU_AO_DocumentStructureExtract obj: '', sym: :code_block_open, num: @num_id[:code_block], - syntax: @@flag[:lngsyn], + syntax: @per.lngsyn, } t_o=SiSU_AO_DocumentStructure::ObjectLayout.new.open_close(h) elsif t_o =~/^(?:poem\{|```[ ]+poem)/ - @@flag[:poem]=case t_o + @per.poem=case t_o when /^poem\{/ then :curls when /^```[ ]+poem/ then :tics - else @@flag[:poem] #error + else @per.poem #error end @num_id[:poem] +=1 h={ @@ -558,10 +534,10 @@ module SiSU_AO_DocumentStructureExtract t_o=SiSU_AO_DocumentStructure::ObjectLayout.new.open_close(h) tuned_file << t_o elsif t_o =~/^(?:box(?:\.[a-z_]+)?\{|```[ ]+box(?:\.[a-z_]+)?)/ - @@flag[:box]=case t_o + @per.box=case t_o when /^box\{/ then :curls when /^```[ ]+box/ then :tics - else @@flag[:box] #error + else @per.box #error end @num_id[:box] +=1 h={ @@ -573,10 +549,10 @@ module SiSU_AO_DocumentStructureExtract t_o=SiSU_AO_DocumentStructure::ObjectLayout.new.open_close(h) tuned_file << t_o elsif t_o =~/^(?:group\{|```[ ]+group)/ - @@flag[:group]=case t_o + @per.group=case t_o when /^group\{/ then :curls when /^```[ ]+group/ then :tics - else @@flag[:group] #error + else @per.group #error end @num_id[:group] +=1 h={ @@ -588,10 +564,10 @@ module SiSU_AO_DocumentStructureExtract t_o=SiSU_AO_DocumentStructure::ObjectLayout.new.open_close(h) tuned_file << t_o elsif t_o =~/^(?:block\{|```[ ]+block)/ - @@flag[:block]=case t_o + @per.block=case t_o when /^block\{/ then :curls when /^```[ ]+block/ then :tics - else @@flag[:block] #error + else @per.block #error end @num_id[:block] +=1 h={ @@ -603,10 +579,10 @@ module SiSU_AO_DocumentStructureExtract t_o=SiSU_AO_DocumentStructure::ObjectLayout.new.open_close(h) tuned_file << t_o elsif t_o =~/^(?:alt\{|```[ ]+alt)/ - @@flag[:alt]=case t_o + @per.alt=case t_o when /^alt\{/ then :curls when /^```[ ]+alt/ then :tics - else @@flag[:alt] #error + else @per.alt #error end @num_id[:alt] +=1 h={ @@ -618,7 +594,7 @@ module SiSU_AO_DocumentStructureExtract t_o=SiSU_AO_DocumentStructure::ObjectLayout.new.open_close(h) tuned_file << t_o elsif t_o =~/^`:quote_open`/ - @@flag[:quote]=:open + @per.quote=:open @num_id[:quote] +=1 h={ is_for: :quote, @@ -639,7 +615,7 @@ module SiSU_AO_DocumentStructureExtract ins_o=SiSU_AO_DocumentStructure::ObjectLayout.new.open_close(h) tuned_file << ins_o if t_o=~/^table\{(?:~h)?\s+/ - @@flag[:table]=:curls + @per.table=:curls @rows='' case t_o when /table\{~h\s+c(\d+);\s+(.+)/ @@ -658,7 +634,7 @@ module SiSU_AO_DocumentStructureExtract idx: idx, } elsif t_o=~/^```[ ]+table(?:~h)?\s+c\d+/ - @@flag[:table]=:tics + @per.table=:tics @rows='' case t_o when /^```[ ]+table~h\s+c(\d+);\s+(.+)/ @@ -797,12 +773,12 @@ module SiSU_AO_DocumentStructureExtract end t_o end - if @@flag[:table]==:curls or @@flag[:table]==:tics - if (@@flag[:table]==:curls \ + if @per.table==:curls or @per.table==:tics + if (@per.table==:curls \ and t_o =~/^\}table/) \ - or (@@flag[:table]==:tics \ + or (@per.table==:tics \ and t_o =~/^```(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/) - @@flag[:table]=:off + @per.table=:off headings,columns,widths,idx=@h[:head_],@h[:cols],@h[:widths],@h[:idx] @h={ head_: headings, @@ -832,13 +808,13 @@ module SiSU_AO_DocumentStructureExtract t_o=nil end end - if @@flag[:code]==:curls \ - or @@flag[:code]==:tics - if (@@flag[:code]==:curls \ + if @per.code==:curls \ + or @per.code==:tics + if (@per.code==:curls \ && t_o =~/^\}code/) \ - or (@@flag[:code]==:tics \ + or (@per.code==:tics \ && t_o =~/^```(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/m) - @@flag[:code]=:off + @per.code=:off if @tuned_code[-1] @tuned_code[-1]. gsub!(/\s*(?:#{Mx[:br_line]}|#{Mx[:br_nl]})\s*\Z/m,'') @@ -848,12 +824,12 @@ module SiSU_AO_DocumentStructureExtract h={ obj: obj, idx: idx, - syntax: @@flag[:lngsyn], + syntax: @per.lngsyn, tags: tags, num: @num_id[:code_block], number_: @codeblock_numbered, } - @@flag[:lngsyn]=:txt + @per.lngsyn=:txt t_o=SiSU_AO_DocumentStructure::ObjectBlockTxt.new.code(h) @tuned_code=[] tuned_file << t_o @@ -865,8 +841,8 @@ module SiSU_AO_DocumentStructureExtract } t_o=SiSU_AO_DocumentStructure::ObjectLayout.new.open_close(h) end - if (@@flag[:code]==:curls \ - || @@flag[:code]==:tics) \ + if (@per.code==:curls \ + || @per.code==:tics) \ and t_o.is_a?(String) sub_array=t_o.dup + "#{Mx[:br_nl]}" @line_mode=[] @@ -875,23 +851,23 @@ module SiSU_AO_DocumentStructureExtract @tuned_code << t_o t_o=nil end - elsif (@@flag[:poem]==:curls \ - || @@flag[:poem]==:tics) \ - or (@@flag[:box]==:curls \ - || @@flag[:box]==:tics) \ - or (@@flag[:group]==:curls \ - || @@flag[:group]==:tics) \ - or (@@flag[:block]==:curls \ - || @@flag[:block]==:tics) \ - or (@@flag[:alt]==:curls \ - || @@flag[:alt]==:tics) \ - or (@@flag[:quote]==:open \ + elsif (@per.poem==:curls \ + || @per.poem==:tics) \ + or (@per.box==:curls \ + || @per.box==:tics) \ + or (@per.group==:curls \ + || @per.group==:tics) \ + or (@per.block==:curls \ + || @per.block==:tics) \ + or (@per.alt==:curls \ + || @per.alt==:tics) \ + or (@per.quote==:open \ && t_o =~/`:quote_close`/m) #not - if (@@flag[:poem]==:curls \ + if (@per.poem==:curls \ && t_o =~/^\}poem$/m) \ - or (@@flag[:poem]==:tics \ + or (@per.poem==:tics \ && t_o =~/^```(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/) - @@flag[:poem]=:off + @per.poem=:off h={ is_for: :poem, obj: '', @@ -900,11 +876,11 @@ module SiSU_AO_DocumentStructureExtract num: @num_id[:poem], } t_o=SiSU_AO_DocumentStructure::ObjectLayout.new.open_close(h) - elsif (@@flag[:box]==:curls \ + elsif (@per.box==:curls \ && t_o =~/^\}box/) \ - or (@@flag[:box]==:tics \ + or (@per.box==:tics \ && t_o =~/^```(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/) - @@flag[:box]=:off + @per.box=:off obj,tags=extract_tags(@tuned_block.join("\n")) h={ obj: obj, @@ -923,11 +899,11 @@ module SiSU_AO_DocumentStructureExtract num: @num_id[:box], } t_o=SiSU_AO_DocumentStructure::ObjectLayout.new.open_close(h) - elsif (@@flag[:group]==:curls \ + elsif (@per.group==:curls \ && t_o =~/^\}group/) \ - or (@@flag[:group]==:tics \ + or (@per.group==:tics \ && t_o =~/^```(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/) - @@flag[:group]=:off + @per.group=:off obj,tags=extract_tags(@tuned_block.join("\n")) h={ obj: obj, @@ -945,11 +921,11 @@ module SiSU_AO_DocumentStructureExtract num: @num_id[:group], } t_o=SiSU_AO_DocumentStructure::ObjectLayout.new.open_close(h) - elsif (@@flag[:block]==:curls \ + elsif (@per.block==:curls \ && t_o =~/^\}block/) \ - or (@@flag[:block]==:tics \ + or (@per.block==:tics \ && t_o =~/^```(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/) - @@flag[:block]=:off + @per.block=:off obj,tags=extract_tags(@tuned_block.join("\n")) h={ obj: obj, @@ -967,11 +943,11 @@ module SiSU_AO_DocumentStructureExtract num: @num_id[:block], } t_o=SiSU_AO_DocumentStructure::ObjectLayout.new.open_close(h) - elsif (@@flag[:alt]==:curls \ + elsif (@per.alt==:curls \ && t_o =~/^\}alt/) \ - or (@@flag[:alt]==:tics \ + or (@per.alt==:tics \ && t_o =~/^```(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/) - @@flag[:alt]=:off + @per.alt=:off obj,tags=extract_tags(@tuned_block.join("\n")) h={ obj: obj, @@ -989,9 +965,9 @@ module SiSU_AO_DocumentStructureExtract num: @num_id[:alt], } t_o=SiSU_AO_DocumentStructure::ObjectLayout.new.open_close(h) - elsif @@flag[:quote]==:open \ + elsif @per.quote==:open \ and t_o =~/`:quote_close`/m - @@flag[:quote]=:off + @per.quote=:off h={ is_for: :quote, idx: idx, @@ -1000,7 +976,7 @@ module SiSU_AO_DocumentStructureExtract num: @num_id[:quote], } t_o=SiSU_AO_DocumentStructure::ObjectLayout.new.open_close(h) - elsif @@flag[:quote]==:open + elsif @per.quote==:open t_o,tags=extract_tags(t_o) h={ indent: 1, @@ -1013,18 +989,18 @@ module SiSU_AO_DocumentStructureExtract } SiSU_AO_DocumentStructure::ObjectPara.new.paragraph(h) end - if (@@flag[:poem]==:curls \ - || @@flag[:poem]==:tics) \ - or (@@flag[:group]==:curls \ - || @@flag[:group]==:tics) \ - or (@@flag[:alt]==:curls \ - || @@flag[:alt]==:tics) \ + if (@per.poem==:curls \ + || @per.poem==:tics) \ + or (@per.group==:curls \ + || @per.group==:tics) \ + or (@per.alt==:curls \ + || @per.alt==:tics) \ and t_o =~/\S/ \ and t_o !~/^(?:\}(?:verse|code|box|alt|group|block)|(?:verse|code(?:\.[a-z][0-9a-z_]+)?|box(?:\.[a-z_]+)?|alt|group|block)\{)/ \ and t_o !~/^```[ ]+(?:code(?:\.[a-z][0-9a-z_]+)?|box(?:\.[a-z_]+)?|poem|alt|group|block)|^```(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/ # fix logic sub_array=t_o.dup @line_mode=sub_array.scan(/.+/) - type=if @@flag[:poem]==:curls or @@flag[:poem]==:tics + type=if @per.poem==:curls or @per.poem==:tics t_o=SiSU_AO_DocumentStructureExtract::Build.new(@md,@line_mode).build_lines(type).join poem=t_o.split(/\n\n/) poem.each do |v| @@ -1042,14 +1018,14 @@ module SiSU_AO_DocumentStructureExtract else :group end end - @verse_count+=1 if @@flag[:poem]==:curls or @@flag[:poem]==:tics + @verse_count+=1 if @per.poem==:curls or @per.poem==:tics end - if @@flag[:code]==:off - if @@flag[:poem]==:curls or @@flag[:poem]==:tics \ - or @@flag[:box]==:curls or @@flag[:box]==:tics \ - or @@flag[:group]==:curls or @@flag[:group]==:tics \ - or @@flag[:alt]==:curls or @@flag[:alt]==:tics \ - or (@@flag[:quote]==:open and t_o =~/`:quote_close`/m) + if @per.code==:off + if @per.poem==:curls or @per.poem==:tics \ + or @per.box==:curls or @per.box==:tics \ + or @per.group==:curls or @per.group==:tics \ + or @per.alt==:curls or @per.alt==:tics \ + or (@per.quote==:open and t_o =~/`:quote_close`/m) if t_o.is_a?(String) t_o=t_o.gsub(/\n/m,"#{Mx[:br_nl]}"). gsub(/[ ][ ]/m,"#{Mx[:nbsp]*2}"). @@ -1168,7 +1144,7 @@ module SiSU_AO_DocumentStructureExtract and line !~/^(?:code(?:\.[a-z][0-9a-z_]+)?\{|\}code)/ \ and line !~/^(?:```[ ]+code(?:\.[a-z][0-9a-z_]+)?|```(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$)/ \ and not line.is_a?(Hash) #watch - @@counter+=1 if @@flag[:code]==:curls or @@flag[:code]==:tics + @@counter+=1 if @per.code==:curls or @per.code==:tics line=line.gsub(/\s\s/,"#{Mx[:nbsp]*2}"). gsub(/#{Mx[:nbsp]}\s/,"#{Mx[:nbsp]*2}") line=line.gsub(/^/,"#{Mx[:gr_o]}codeline#{Mx[:gr_c]}") if type==:code # REMOVE try sort for texpdf special case |