diff options
Diffstat (limited to 'lib/sisu/ao_doc_str.rb')
-rw-r--r-- | lib/sisu/ao_doc_str.rb | 191 |
1 files changed, 99 insertions, 92 deletions
diff --git a/lib/sisu/ao_doc_str.rb b/lib/sisu/ao_doc_str.rb index 40f5a045..9a46cebf 100644 --- a/lib/sisu/ao_doc_str.rb +++ b/lib/sisu/ao_doc_str.rb @@ -1,57 +1,55 @@ -# encoding: utf-8 -=begin - -* Name: SiSU - -** Description: documents, structuring, processing, publishing, search -*** document abstraction - -** Author: Ralph Amissah - [ralph@amissah.com] - [ralph.amissah@gmail.com] - -** Copyright: (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, - 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Ralph Amissah, - All Rights Reserved. - -** License: GPL 3 or later: - - SiSU, a framework for document structuring, publishing and search - - Copyright (C) Ralph Amissah - - This program is free software: you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by the Free - Software Foundation, either version 3 of the License, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for - more details. - - You should have received a copy of the GNU General Public License along with - this program. If not, see [http://www.gnu.org/licenses/]. - - If you have Internet connection, the latest version of the GPL should be - available at these locations: - [http://www.fsf.org/licensing/licenses/gpl.html] - [http://www.gnu.org/licenses/gpl.html] - -** SiSU uses: - * Standard SiSU markup syntax, - * Standard SiSU meta-markup syntax, and the - * Standard SiSU object citation numbering and system - -** Hompages: - [http://www.jus.uio.no/sisu] - [http://www.sisudoc.org] - -** Git - [http://git.sisudoc.org/gitweb/?p=code/sisu.git;a=summary] - [http://git.sisudoc.org/gitweb/?p=code/sisu.git;a=blob;f=lib/sisu/ao_doc_str.rb;hb=HEAD] - -=end +#encoding: utf-8 +#- Name: SiSU +# +# - Description: documents, structuring, processing, publishing, search +# abstraction +# +# - Author: Ralph Amissah +# <ralph.amissah@gmail.com> +# +# - Copyright: (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, +# 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2019, +# 2020, 2021, Ralph Amissah, +# All Rights Reserved. +# +# - License: GPL 3 or later: +# +# SiSU, a framework for document structuring, publishing and search +# +# Copyright (C) Ralph Amissah +# +# This program is free software: you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along with +# this program. If not, see <http://www.gnu.org/licenses/>. +# +# If you have Internet connection, the latest version of the GPL should be +# available at these locations: +# <http://www.fsf.org/licensing/licenses/gpl.html> +# <http://www.gnu.org/licenses/gpl.html> +# +# <http://www.sisudoc.org/sisu/en/manifest/gpl.fsf.html> +# +# - SiSU uses: +# - Standard SiSU markup syntax, +# - Standard SiSU meta-markup syntax, and the +# - Standard SiSU object citation numbering and system +# +# - Homepages: +# <http://www.sisudoc.org> +# +# - Git +# <https://git.sisudoc.org/projects/> +# <https://git.sisudoc.org/projects/?p=software/sisu.git;a=summary> +# <https://git.sisudoc.org/projects/?p=markup/sisu-markup-samples.git;a=summary> module SiSU_AO_DocumentStructureExtract require_relative 'ao_persist' # ao_persist.rb class Instantiate < SiSU_Param::Parameters::Instructions @@ -296,15 +294,17 @@ 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\()|^(?: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 \ - and @per.group==:off \ - and @per.block==:off \ - and @per.alt==:off \ - and @per.box==:off \ - and @per.table==:off + if (t_o.is_a?(String) \ + && t_o !~/^(?:code(?:\.[a-z][0-9a-z_]+)?(?:\(.+?\))?|box(?:\.[a-z_]+)?|poem|alt|group|block)\{|^\}(?:code|poem|alt|group|block)|^(?:table\(.+?\)\{|\{table\()|^(?:table\{|\{table)[ ~]/ \ + && 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 \ + 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 @@ -962,9 +962,9 @@ module SiSU_AO_DocumentStructureExtract end if @per.table==:curls or @per.table==:tics if (@per.table==:curls \ - and t_o =~/^\}table/) \ + and (t_o.is_a?(String) and t_o =~/^\}table/)) \ or (@per.table==:tics \ - and t_o =~/^```(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/) + and (t_o.is_a?(String) and t_o =~/^```(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/)) @per.table=:off headings,columns,widths,idx=@h[:head_],@h[:cols],@h[:widths],@h[:idx] @h={ @@ -998,9 +998,10 @@ module SiSU_AO_DocumentStructureExtract if @per.code==:curls \ or @per.code==:tics if (@per.code==:curls \ - && t_o =~/^\}code/) \ + && (t_o.is_a?(String) && t_o =~/^\}code/)) \ or (@per.code==:tics \ - && t_o =~/^```(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/m) + && (t_o.is_a?(String) && t_o =~/^```(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/m) \ + ) @per.code=:off if @tuned_code[-1] @tuned_code[-1]. @@ -1049,11 +1050,11 @@ module SiSU_AO_DocumentStructureExtract or (@per.alt==:curls \ || @per.alt==:tics) \ or (@per.quote==:open \ - && t_o =~/`:quote_close`/m) #not + && (t_o.is_a?(String) && t_o =~/`:quote_close`/m)) if (@per.poem==:curls \ - && t_o =~/^\}poem$/m) \ + && (t_o.is_a?(String) && t_o.to_s =~/^\}poem$/m)) \ or (@per.poem==:tics \ - && t_o =~/^```(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/) + && (t_o.is_a?(String) && t_o =~/^```(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/)) @per.poem=:off h={ is_for: :poem, @@ -1064,9 +1065,9 @@ module SiSU_AO_DocumentStructureExtract } t_o=SiSU_AO_DocumentStructure::ObjectLayout.new.open_close(h) elsif (@per.box==:curls \ - && t_o =~/^\}box/) \ + && (t_o.is_a?(String) && t_o =~/^\}box/)) \ or (@per.box==:tics \ - && t_o =~/^```(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/) + && (t_o.is_a?(String) && t_o.to_s =~/^```(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/)) @per.box=:off obj,tags=extract_tags(@tuned_block.join("\n")) h={ @@ -1087,9 +1088,9 @@ module SiSU_AO_DocumentStructureExtract } t_o=SiSU_AO_DocumentStructure::ObjectLayout.new.open_close(h) elsif (@per.group==:curls \ - && t_o =~/^\}group/) \ + && ( t_o.is_a?(String) && t_o.to_s =~/^\}group/)) \ or (@per.group==:tics \ - && t_o =~/^```(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/) + && (t_o.is_a?(String) && t_o.to_s =~/^```(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/)) @per.group=:off obj,tags=extract_tags(@tuned_block.join("\n")) h={ @@ -1109,9 +1110,11 @@ module SiSU_AO_DocumentStructureExtract } t_o=SiSU_AO_DocumentStructure::ObjectLayout.new.open_close(h) elsif (@per.block==:curls \ - && t_o =~/^\}block/) \ + && t_o.to_s =~/^\}block/) \ or (@per.block==:tics \ - && t_o =~/^```(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/) + && (t_o.is_a?(String) \ + && t_o =~/^```(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/) \ + ) @per.block=:off obj,tags=extract_tags(@tuned_block.join("\n")) h={ @@ -1131,9 +1134,11 @@ module SiSU_AO_DocumentStructureExtract } t_o=SiSU_AO_DocumentStructure::ObjectLayout.new.open_close(h) elsif (@per.alt==:curls \ - && t_o =~/^\}alt/) \ + && (t_o.is_a?(String) && t_o =~/^\}alt/)) \ or (@per.alt==:tics \ - && t_o =~/^```(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/) + && t_o.is_a?(String) \ + && (t_o =~/^```(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/) + ) @per.alt=:off obj,tags=extract_tags(@tuned_block.join("\n")) h={ @@ -1153,7 +1158,7 @@ module SiSU_AO_DocumentStructureExtract } t_o=SiSU_AO_DocumentStructure::ObjectLayout.new.open_close(h) elsif @per.quote==:open \ - and t_o =~/`:quote_close`/m + and (t_o.is_a?(String) && t_o =~/`:quote_close`/m) @per.quote=:off h={ is_for: :quote, @@ -1184,10 +1189,12 @@ module SiSU_AO_DocumentStructureExtract || @per.block==: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 + and (t_o.is_a?(String) \ + and t_o.to_s =~/\S/ \ + and t_o.to_s !~/^(?:\}(?:verse|code|box|alt|group|block)|(?:verse|code(?:\.[a-z][0-9a-z_]+)?|box(?:\.[a-z_]+)?|alt|group|block)\{)/ \ + and t_o.to_s !~/^```[ ]+(?:code(?:\.[a-z][0-9a-z_]+)?|box(?:\.[a-z_]+)?|poem|alt|group|block)|^```(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/ + ) + sub_array=t_o.to_s.dup @line_mode=sub_array.scan(/.+/) type=if @per.poem==:curls or @per.poem==:tics t_o=SiSU_AO_DocumentStructureExtract::Build.new(@md,@line_mode).build_lines(type).join @@ -1230,7 +1237,7 @@ module SiSU_AO_DocumentStructureExtract gsub(/[ ][ ]/m,"#{Mx[:nbsp]*2}"). gsub(/#{Mx[:nbsp]}\s/,"#{Mx[:nbsp]*2}") end - @tuned_block << t_o if t_o =~/\S+/ + @tuned_block << t_o if t_o.to_s =~/\S+/ else tuned_file << t_o end else tuned_file << t_o @@ -1700,7 +1707,7 @@ SKIPPED processing file: ocnh+=1 end if ln==0 \ - or ln=~@md.lv0 + or ln.to_s =~@md.lv0 @lev_occurences[:a] += 1 if not dob.obj =~/~#|-#/ ocn_flag=true @@ -1716,7 +1723,7 @@ SKIPPED processing file: collapsed_level=@collapsed_lv0 node,ocn_sp,parent=node0,"h#{ocnh}",'ROOT' elsif ln==1 \ - or ln=~@md.lv1 + or ln.to_s =~@md.lv1 @lev_occurences[:b] += 1 if not dob.obj =~/~#|-#/ ocn_flag=true @@ -1739,7 +1746,7 @@ SKIPPED processing file: collapsed_level=@collapsed_lv1 node,ocn_sp,parent=node1,"h#{ocnh}",node0 #FIX elsif ln==2 \ - or ln=~@md.lv2 + or ln.to_s =~@md.lv2 @lev_occurences[:c] += 1 if not dob.obj =~/~#|-#/ ocn_flag=true @@ -1762,7 +1769,7 @@ SKIPPED processing file: collapsed_level=@collapsed_lv2 node,ocn_sp=node2,"h#{ocnh}" elsif ln==3 \ - or ln=~@md.lv3 + or ln.to_s =~@md.lv3 @lev_occurences[:d] += 1 if not dob.obj =~/~#|-#/ ocn_flag=true @@ -1793,7 +1800,7 @@ or this level should be level :B~ rather than #{dob.lv}} collapsed_level=@collapsed_lv3 node,ocn_sp=node3,"h#{ocnh}" elsif ln==4 \ - or ln=~@md.lv4 + or ln.to_s =~@md.lv4 @lev_occurences[:l1] += 1 if not dob.obj =~/~#|-#/ ocn_flag=true @@ -1827,7 +1834,7 @@ or this level should be level :B~ rather than #{dob.lv}} collapsed_level=@collapsed_lv4 node,ocn_sp=node4,"h#{ocnh}" elsif ln==5 \ - or ln=~@md.lv5 + or ln.to_s =~@md.lv5 @lev_occurences[:l2] += 1 if not dob.obj =~/~#|-#/ ocn_flag=true @@ -1864,7 +1871,7 @@ or this level should be level :B~ rather than #{dob.lv}} collapsed_level=@collapsed_lv5 node,ocn_sp=node5,"h#{ocnh}" elsif ln==6 \ - or ln=~@md.lv6 + or ln.to_s =~@md.lv6 @lev_occurences[:l3] += 1 if not dob.obj =~/~#|-#/ ocn_flag=true @@ -1909,7 +1916,7 @@ or this level should be #5 (2~) rather ##{dob.ln} (#{dob.lv}~)" collapsed_level=@collapsed_lv6 node,ocn_sp=node6,"h#{ocnh}" elsif ln==7 \ - or ln=~@md.lv7 + or ln.to_s =~@md.lv7 @lev_occurences[:l4] += 1 if not dob.obj =~/~#|-#/ ocn_flag=true |