From e4af625ffea32eac44715f4f44c105cb8e1ce2b4 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Wed, 28 Aug 2019 10:57:33 -0400 Subject: re-introduce depreciated table markup for table attributes --- lib/sisu/ao_doc_str.rb | 177 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 176 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/sisu/ao_doc_str.rb b/lib/sisu/ao_doc_str.rb index 5b1f8f61..eec2cbad 100644 --- a/lib/sisu/ao_doc_str.rb +++ b/lib/sisu/ao_doc_str.rb @@ -296,7 +296,7 @@ module SiSU_AO_DocumentStructureExtract else nil end end - if t_o !~/^(?:code(?:\.[a-z][0-9a-z_]+)?|box(?:\.[a-z_]+)?|poem|alt|group|block)\{|^\}(?:code|poem|alt|group|block)|^(?:table\(.+?\)\{|\{table\()/ \ + if t_o !~/^(?:code(?:\.[a-z][0-9a-z_]+)?|box(?:\.[a-z_]+)?|poem|alt|group|block)\{|^\}(?:code|poem|alt|group|block)|^(?:table\(.+?\)\{|\{table\()|^(?: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 @per.code==:off \ and @per.poem==:off \ @@ -779,6 +779,181 @@ module SiSU_AO_DocumentStructureExtract t_o=SiSU_AO_DocumentStructure::ObjectLayout.new.open_close(h) t_o end +## depreciated markup, code should work for new markup after removal { + elsif t_o =~/^(?:table\{|```[ ]+table|\{table)[ ~]/ + puts "WARNING document using depreciated markup for tables" + puts "use table([table attributes]) instead:" + puts "table(){" + puts "``` table()" + puts "{table()}" + @num_id[:table] +=1 + h={ + is_for: :table, + obj: '', + sym: :table_open, + num: @num_id[:table], + } + ins_o=SiSU_AO_DocumentStructure::ObjectLayout.new.open_close(h) + tuned_file << ins_o + if t_o=~/^table\{(?:~h)?\s+/ + @per.table=:curls + @rows='' + case t_o + when /table\{~h\s+c(\d+);\s+(.+)/ + cols=$1 + col=$2.scan(/\d+/) + heading=true + when /table\{\s+c(\d+);\s+(.+)/ + cols=$1 + col=$2.scan(/\d+/) + heading=false + end + @h={ + head_: heading, + cols: cols, + widths: col, + idx: idx, + } + elsif t_o=~/^```[ ]+table(?:~h)?\s+c\d+/ + @per.table=:tics + @rows='' + case t_o + when /^```[ ]+table~h\s+c(\d+);\s+(.+)/ + cols=$1 + col=$2.scan(/\d+/) + heading=true + when /^```[ ]+table\s+c(\d+);\s+(.+)/ + cols=$1 + col=$2.scan(/\d+/) + heading=false + end + @h={ + head_: heading, + cols: cols, + widths: col, + idx: idx, + } + elsif t_o=~/^\{table(?:~h)?(?:\s+\d+;?)?\}\n.+\Z/m + m1,m2,hd=nil,nil,nil + tbl=/^\{table(?:~h)?(?:\s+\d+;?)?\}\n(.+)\Z/m.match(t_o)[1] + hd=((t_o =~/^\{table~h/) ? true : false) + tbl,tags=extract_tags(tbl) + rws=tbl.split(/\n/) + rows='' + cols=nil + rws.each do |r| + cols=(cols ? cols : (r.scan('|').length) +1) + r=r.gsub(/\s*\|\s*/m,"#{Mx[:tc_p]}") #r.gsub!(/\|/m,"#{Mx[:tc_p]}") + rows += r + Mx[:tc_c] + end + col=[] + if t_o =~/^\{table(?:~h)?\s+(\d+);?\}/ #width of col 1 given as %, usually when wider than rest that are even + c1=$1.to_i + width=(100 - c1)/(cols - 1) + col=[ c1 ] + (cols - 1).times { col << width } + else #all columns of equal width + width=100.00/cols + cols.times { col << width } + end + h={ + head_: hd, + cols: cols, + widths: col, + obj: rows, + idx: idx, + tags: tags, + num: @num_id[:table], + } + t_o=SiSU_AO_DocumentStructure::ObjectTable.new.table(h) \ + unless h.nil? + tuned_file << t_o + h={ + is_for: :table, + obj: '', + sym: :table_close, + num: @num_id[:table], + } + t_o=SiSU_AO_DocumentStructure::ObjectLayout.new.open_close(h) + t_o + elsif t_o=~/^```[ ]+table(?:~h)?\s+/ + m1,m2,hd=nil,nil,nil + h=case t_o + when /^```[ ]+table~h\s+(.+?)\n(.+)\Z/m #two table representations should be consolidated as one + m1,tbl,hd=$1,$2,true + when /^```[ ]+table\s+(.+?)\n(.+)\Z/m #two table representations should be consolidated as one + m1,tbl,hd=$1,$2,false + else nil + end + tbl,tags=extract_tags(tbl) + col=m1.scan(/\d+/) + rws=tbl.split(/\n/) + rows='' + rws.each do |r| + r=r.gsub(/\s*\|\s*/m,"#{Mx[:tc_p]}") #r.gsub!(/\|/m,"#{Mx[:tc_p]}") + rows += r + Mx[:tc_c] + end + h={ + head_: hd, + cols: col.length, + widths: col, + obj: rows, + idx: idx, + tags: tags, + num: @num_id[:table], + } + t_o=SiSU_AO_DocumentStructure::ObjectTable.new.table(h) \ + unless h.nil? + tuned_file << t_o + h={ + is_for: :table, + obj: '', + sym: :table_close, + num: @num_id[:table], + } + t_o=SiSU_AO_DocumentStructure::ObjectLayout.new.open_close(h) + t_o + elsif t_o=~/^\{table(?:~h)?\s+/ + m1,m2,hd=nil,nil,nil + h=case t_o + when /\{table~h\s+(.+?)\}\n(.+)\Z/m #two table representations should be consolidated as one + m1,tbl,hd=$1,$2,true + when /\{table\s+(.+?)\}\n(.+)\Z/m #two table representations should be consolidated as one + m1,tbl,hd=$1,$2,false + else nil + end + tbl,tags=extract_tags(tbl) + col=m1.scan(/\d+/) + rws=tbl.split(/\n/) + rows='' + rws.each do |r| + r=r.gsub(/\s*\|\s*/m,"#{Mx[:tc_p]}") #r.gsub!(/\|/m,"#{Mx[:tc_p]}") + rows += r + Mx[:tc_c] + end + h={ + head_: hd, + cols: col.length, + widths: col, + obj: rows, + idx: idx, + tags: tags, + num: @num_id[:table], + } + t_o=SiSU_AO_DocumentStructure::ObjectTable.new.table(h) \ + unless h.nil? + tuned_file << t_o + h={ + is_for: :table, + obj: '', + sym: :table_close, + num: @num_id[:table], + } + t_o=SiSU_AO_DocumentStructure::ObjectLayout.new.open_close(h) + t_o +## } depreciated markup, code should (continue to) work for new markup after removal, +# when removing depreciated markup check only pass-through for new table attributes format +# table(.+?){ ``` table(.+?) {table(.+?)} formats + end end t_o end -- cgit v1.2.3