From 9b51aed57ab048b76cf322c8c56e6b83d68f50d0 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Mon, 2 Dec 2013 23:43:22 -0500 Subject: v5: renaming files & modules ao & AO (from dal & DAL) * ao (abstract objects) shorter, also easily searched, higher sort location abstract as representation of & extraction of document objects (dal (document abstraction layer)) --- lib/sisu/v5/ao.rb | 537 +++++++++ lib/sisu/v5/ao_character_check.rb | 107 ++ lib/sisu/v5/ao_doc_objects.rb | 481 ++++++++ lib/sisu/v5/ao_doc_str.rb | 1427 +++++++++++++++++++++++ lib/sisu/v5/ao_endnotes.rb | 128 ++ lib/sisu/v5/ao_expand_insertions.rb | 450 +++++++ lib/sisu/v5/ao_hash_digest.rb | 157 +++ lib/sisu/v5/ao_idx.rb | 326 ++++++ lib/sisu/v5/ao_images.rb | 165 +++ lib/sisu/v5/ao_metadata.rb | 82 ++ lib/sisu/v5/ao_misc_arrange.rb | 157 +++ lib/sisu/v5/ao_numbering.rb | 486 ++++++++ lib/sisu/v5/ao_syntax.rb | 631 ++++++++++ lib/sisu/v5/dal.rb | 537 --------- lib/sisu/v5/dal_character_check.rb | 107 -- lib/sisu/v5/dal_doc_objects.rb | 481 -------- lib/sisu/v5/dal_doc_str.rb | 1427 ----------------------- lib/sisu/v5/dal_endnotes.rb | 128 -- lib/sisu/v5/dal_expand_insertions.rb | 450 ------- lib/sisu/v5/dal_hash_digest.rb | 157 --- lib/sisu/v5/dal_idx.rb | 326 ------ lib/sisu/v5/dal_images.rb | 165 --- lib/sisu/v5/dal_metadata.rb | 82 -- lib/sisu/v5/dal_misc_arrange.rb | 157 --- lib/sisu/v5/dal_numbering.rb | 486 -------- lib/sisu/v5/dal_syntax.rb | 631 ---------- lib/sisu/v5/db_import.rb | 4 +- lib/sisu/v5/git.rb | 6 +- lib/sisu/v5/html_format.rb | 2 +- lib/sisu/v5/hub.rb | 4 +- lib/sisu/v5/manpage.rb | 4 +- lib/sisu/v5/odf.rb | 2 +- lib/sisu/v5/particulars.rb | 16 +- lib/sisu/v5/plaintext.rb | 4 +- lib/sisu/v5/po4a.rb | 10 +- lib/sisu/v5/sst_do_inline_footnotes.rb | 4 +- lib/sisu/v5/sst_to_s_xml_sax.rb | 4 +- lib/sisu/v5/sysenv.rb | 4 +- lib/sisu/v5/texpdf.rb | 8 +- lib/sisu/v5/wikispeak.rb | 4 +- lib/sisu/v5/xml_dom.rb | 2 +- lib/sisu/v5/xml_scaffold_structure_collapsed.rb | 2 +- lib/sisu/v5/xml_scaffold_structure_sisu.rb | 2 +- 43 files changed, 5175 insertions(+), 5175 deletions(-) create mode 100644 lib/sisu/v5/ao.rb create mode 100644 lib/sisu/v5/ao_character_check.rb create mode 100644 lib/sisu/v5/ao_doc_objects.rb create mode 100644 lib/sisu/v5/ao_doc_str.rb create mode 100644 lib/sisu/v5/ao_endnotes.rb create mode 100644 lib/sisu/v5/ao_expand_insertions.rb create mode 100644 lib/sisu/v5/ao_hash_digest.rb create mode 100644 lib/sisu/v5/ao_idx.rb create mode 100644 lib/sisu/v5/ao_images.rb create mode 100644 lib/sisu/v5/ao_metadata.rb create mode 100644 lib/sisu/v5/ao_misc_arrange.rb create mode 100644 lib/sisu/v5/ao_numbering.rb create mode 100644 lib/sisu/v5/ao_syntax.rb delete mode 100644 lib/sisu/v5/dal.rb delete mode 100644 lib/sisu/v5/dal_character_check.rb delete mode 100644 lib/sisu/v5/dal_doc_objects.rb delete mode 100644 lib/sisu/v5/dal_doc_str.rb delete mode 100644 lib/sisu/v5/dal_endnotes.rb delete mode 100644 lib/sisu/v5/dal_expand_insertions.rb delete mode 100644 lib/sisu/v5/dal_hash_digest.rb delete mode 100644 lib/sisu/v5/dal_idx.rb delete mode 100644 lib/sisu/v5/dal_images.rb delete mode 100644 lib/sisu/v5/dal_metadata.rb delete mode 100644 lib/sisu/v5/dal_misc_arrange.rb delete mode 100644 lib/sisu/v5/dal_numbering.rb delete mode 100644 lib/sisu/v5/dal_syntax.rb (limited to 'lib') diff --git a/lib/sisu/v5/ao.rb b/lib/sisu/v5/ao.rb new file mode 100644 index 00000000..00484ff9 --- /dev/null +++ b/lib/sisu/v5/ao.rb @@ -0,0 +1,537 @@ +# encoding: utf-8 +=begin + + * Name: SiSU + + * Description: a framework for document structuring, publishing and search + + * 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. + + * 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 . + + If you have Internet connection, the latest version of the GPL should be + available at these locations: + + + + + + * SiSU uses: + * Standard SiSU markup syntax, + * Standard SiSU meta-markup syntax, and the + * Standard SiSU object citation numbering and system + + * Hompages: + + + + * Download: + + + * Git + + + + * Ralph Amissah + + + + ** Description: preprocessing, (document abstraction), data abstraction used + in subsequent processing + +=end +module SiSU_AO + require_relative 'defaults' # defaults.rb + include SiSU_Viz + require_relative 'sysenv' # sysenv.rb + include SiSU_Env + require_relative 'param' # param.rb + include SiSU_Param + require_relative 'ao_doc_objects' # ao.rb + require_relative 'ao_syntax' # ao_syntax.rb + include SiSU_AO_Syntax + require_relative 'ao_doc_str' # ao_doc_str.rb + require_relative 'ao_idx' # ao_idx.rb + require_relative 'ao_numbering' # ao_numbering.rb + require_relative 'ao_hash_digest' # ao_hash_digest.rb + require_relative 'ao_endnotes' # ao_endnotes.rb + require_relative 'ao_images' # ao_images.rb + require_relative 'ao_metadata' # ao_metadata.rb + require_relative 'ao_character_check' # ao_character_check.rb + require_relative 'ao_misc_arrange' # ao_misc_arrange.rb + require_relative 'ao_expand_insertions' # ao_expand_insertions.rb + require_relative 'prog_text_translation' # prog_text_translation.rb + require_relative 'shared_sem' # shared_sem.rb + class Instantiate < SiSU_Param::Parameters::Instructions + def initialize + @@flag_vocab=0 + @@line_mode='' + end + end + class Source #{cf.meta}").txt_grey + end + end + dal.each {|s| dal_array << s} + if @opt.act[:maintenance][:set]==:on + dal_array.each do |obj| + if defined? obj.parent + if defined? obj.ln + if defined? obj.node + puts %{#{obj.ln}: #{obj.ocn} : #{obj.parent} : #{obj.node} - #{obj.lc}} + else + puts %{#{obj.ln}: #{obj.ocn} : #{obj.parent}} + end + else + if defined? obj.node + puts %{ #{obj.ocn} : #{obj.parent} : #{obj.node} - #{obj.lc}} + else + puts %{ #{obj.ocn} : #{obj.parent}} + end + end + end + end + end + dal_array + end + def read_fnm + dal=[] + dal=(FileTest.file?(@fnm)) \ + ? (File.open(@fnm,'r:utf-8'){ |f| dal=Marshal.load(f)}) + : SiSU_AO::Source.new(@opt).create_dal + end + def read_fnc + dal=[] + dal=(FileTest.file?(@fnc)) \ + ? (File.open(@fnc,'r:utf-8'){ |f| dal=Marshal.load(f)}) + : SiSU_AO::Source.new(@opt).create_dal + end + def read_idx_sst + m=[] + m=(FileTest.file?(@idx_sst)) \ + ? (File.open(@idx_sst,'r:utf-8'){ |f| m=Marshal.load(f)}) + : nil + end + def read_idx_raw + m=[] + m=(FileTest.file?(@idx_raw)) \ + ? (File.open(@idx_raw,'r:utf-8'){ |f| m=Marshal.load(f)}) + : nil + end + def read_idx_html + m=[] + m=(FileTest.file?(@idx_html)) \ + ? (File.open(@idx_html,'r:utf-8'){ |f| m=Marshal.load(f)}) + : nil + end + def read_idx_xhtml + m=[] + m=(FileTest.file?(@idx_xhtml)) \ + ? (File.open(@idx_xhtml,'r:utf-8'){ |f| m=Marshal.load(f)}) + : nil + end + def read_map_nametags + m=[] + m=(FileTest.file?(@map_nametags)) \ + ? (File.open(@map_nametags,'r:utf-8'){ |f| m=Marshal.load(f)}) + : nil + end + def read_map_ocn_htmlseg + m=[] + m=(FileTest.file?(@map_ocn_htmlseg)) \ + ? (File.open(@map_ocn_htmlseg,'r:utf-8'){ |f| m=Marshal.load(f)}) + : nil + end + end + class Output + def initialize(fn,md,data) + @fn,@md,@data=fn,md,data + @cf=SiSU_Env::CreateFile.new(@fn) + @make=SiSU_Env::InfoFile.new(@fn) + @dir=SiSU_Env::InfoEnv.new(@fn) + end + def screen_dump(o) + if defined? o.of + print %{OF: #{o.of}; } + end + if defined? o.is + print %{IS: #{o.is.to_s}; } + end + if defined? o.ocn + print %{OCN: #{o.ocn}; } + end + if defined? o.node + print %{NODE: #{o.node}; } + end + if defined? o.parent + print %{Parent: #{o.parent}; } + end + if defined? o.obj and not o.obj.empty? + puts %{\n#{o.obj}; } + else "\n" + end + end + def screen_print(t_o) + if defined? t_o + print ' ' + t_o.to_s + end + end + def screen_output(data) + data.each do |o| + print o.class + screen_print(o.ocn) + screen_print(o.obj) + puts "\n" + end + end + def hard_output + if @md.opt.act[:maintenance][:set]==:on + filename_meta=@cf.metaverse.file_meta + @data.each {|o| filename_meta.puts o.inspect.sub(/:0x[0-9a-f]{8}\s/,': ')} #to make diffing easier + filename_txt=@cf.metaverse.file_txt + @data.each do |o| + if defined? o.ocn + filename_txt.puts case o.is + when :heading + "[#{o.is.to_s} #{o.lv}~#{o.name} [#{o.ocn}]] #{o.obj}" + else "[#{o.is.to_s} [#{o.ocn}]] #{o.obj}" + end + else + filename_txt.puts case o.is + when :meta + "[m~#{o.tag}] #{o.obj}" + else "[#{o.is.to_s}] #{o.obj}" + end + end + end + filename_debug=@cf.file_debug + @data.each do |o| + if defined? o.ocn + case o.is + when :heading + filename_debug.puts "#{o.is.to_s} #{o.lv}~#{o.name} odv=#{o.odv} osp=#{o.osp} [#{o.ocn}] -->\n\t#{o.obj}" + end + end + end + else + hard="#{@dir.processing_path.dal}/#{@md.fns}.meta" + File.unlink(hard) if FileTest.file?(hard) + hard="#{@dir.processing_path.dal}/#{@md.fns}.txt" + File.unlink(hard) if FileTest.file?(hard) + hard="#{@dir.processing_path.dal}/#{@md.fns}.debug.txt" + File.unlink(hard) if FileTest.file?(hard) + end + end + def make_marshal_content + marshal_dal=@make.marshal.dal_content + File.open(marshal_dal,'w'){|f| Marshal.dump(@data,f)} if @data.is_a?(Array) + end + def make_marshal_metadata + marshal_dal=@make.marshal.dal_metadata + File.open(marshal_dal,'w'){|f| Marshal.dump(@data,f)} if @data.is_a?(Array) + end + def idx_html_hard_output + if @md.book_idx \ + and @md.opt.act[:maintenance][:set]==:on + filename_meta=@cf.file_meta_idx_html + if @data.is_a?(Array) + @data.each {|s| p s.inspect + "\n" unless s.is_a?(String)} + @data.each {|s| filename_meta.puts s.strip + "\n" unless s.strip.empty?} + end + else + hard_idx_html="#{@dir.processing_path.dal}/#{@md.fns}.idx.html" + File.unlink(hard_idx_html) if FileTest.file?(hard_idx_html) + end + end + def make_marshal_idx_sst_html_seg + marshal_dal=@make.marshal.dal_idx_sst_rel_html_seg + File.open(marshal_dal,'w'){|f| Marshal.dump(@data,f)} if @data.is_a?(Array) + end + def make_marshal_idx_sst_rel + marshal_dal=@make.marshal.dal_idx_sst_rel + File.open(marshal_dal,'w'){|f| Marshal.dump(@data,f)} if @data.is_a?(Array) + end + def make_marshal_idx_html + marshal_dal=@make.marshal.dal_idx_html + File.open(marshal_dal,'w'){|f| Marshal.dump(@data,f)} if @data.is_a?(Array) + end + def make_marshal_idx_xhtml + marshal_dal=@make.marshal.dal_idx_xhtml + File.open(marshal_dal,'w'){|f| Marshal.dump(@data,f)} if @data.is_a?(Array) + end + def make_marshal_map_nametags + marshal_dal=@make.marshal.dal_map_nametags + File.open(marshal_dal,'w'){|f| Marshal.dump(@data,f)} if @data.is_a?(Hash) + end + def make_marshal_map_name_ocn_htmlseg + marshal_dal=@make.marshal.dal_map_ocn_htmlseg + File.open(marshal_dal,'w'){|f| Marshal.dump(@data,f)} if @data.is_a?(Hash) + end + end + class Make + def initialize(fn,md,data) + @fn,@md,@data=fn,md,data + @env=SiSU_Env::InfoEnv.new(@md.fns) + end + def reset + @@flag_vocab=0 + @@line_mode='' + end + def song + reset + data=@data + data=SiSU_AO_Insertions::Insertions.new(@md,data).expand_insertions? # dal_expand_insertions.rb + data=SiSU_AO_MiscArrangeText::SI.new(@md,data).prepare_text # dal_misc_arrange.rb + data,metadata=SiSU_AO_DocumentStructureExtract::Build.new(@md,data).identify_parts # dal_doc_str.rb + data=SiSU_AO_Syntax::Markup.new(@md,data).songsheet # dal_syntax.rb + data,endnote_array=SiSU_AO_CharacterCheck::Check.new(data).character_check_and_oldstyle_endnote_array # dal_character_check.rb + data=SiSU_AO_Images::Images.new(@md,data).images # dal_images.rb + data,tags_map,ocn_html_seg_map=SiSU_AO_Numbering::Numbering.new(@md,data).numbering_song # dal_numbering.rb + data,book_index_rel,book_index_rel_html_seg,html_idx,xhtml_idx=SiSU_AO_BookIndex::BookIndex.new(@md,data,@env).indexing_song if @md.book_idx # dal_idx.rb + data=SiSU_AO_Endnotes::Endnotes.new(@md,data,endnote_array).endnotes # dal_endnotes.rb + outputdata=data + if (@md.opt.act[:dal][:set]==:on \ + || @md.opt.act[:maintenance][:set]==:on) + SiSU_AO::Output.new(@fn,@md,outputdata).hard_output + SiSU_AO::Output.new(@fn,@md,outputdata).make_marshal_content + SiSU_AO::Output.new(@fn,@md,metadata).make_marshal_metadata + SiSU_AO::Output.new(@fn,@md,html_idx).idx_html_hard_output + SiSU_AO::Output.new(@fn,@md,book_index_rel_html_seg).make_marshal_idx_sst_html_seg + SiSU_AO::Output.new(@fn,@md,book_index_rel).make_marshal_idx_sst_rel + SiSU_AO::Output.new(@fn,@md,html_idx).make_marshal_idx_html + SiSU_AO::Output.new(@fn,@md,xhtml_idx).make_marshal_idx_xhtml + SiSU_AO::Output.new(@fn,@md,tags_map).make_marshal_map_nametags + SiSU_AO::Output.new(@fn,@md,ocn_html_seg_map).make_marshal_map_name_ocn_htmlseg + end + reset + outputdata + end + protected + end +end +__END__ diff --git a/lib/sisu/v5/ao_character_check.rb b/lib/sisu/v5/ao_character_check.rb new file mode 100644 index 00000000..86f23f5b --- /dev/null +++ b/lib/sisu/v5/ao_character_check.rb @@ -0,0 +1,107 @@ +# encoding: utf-8 +=begin + + * Name: SiSU + + * Description: a framework for document structuring, publishing and search + + * 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. + + * 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 . + + If you have Internet connection, the latest version of the GPL should be + available at these locations: + + + + + + * SiSU uses: + * Standard SiSU markup syntax, + * Standard SiSU meta-markup syntax, and the + * Standard SiSU object citation numbering and system + + * Hompages: + + + + * Download: + + + * Git + + + + * Ralph Amissah + + + + ** Description: system environment, resource control and configuration details + +=end +module SiSU_AO_CharacterCheck + class Check + def initialize(data) + @data=data + @comment='%' + @endnote_array=[] + end + def character_check_and_oldstyle_endnote_array + data=@data + @tuned_file,@endnote_array=[],[] + endnote_no=1 + data.each do |dob| + unless dob.is ==:table + dob.obj=dob.obj.strip. + gsub(/^[{~}]\s*$/,''). + gsub(/~#\s*/,"#{Mx[:pa_non_object_no_heading]}"). + gsub(/-#\s*/,"#{Mx[:pa_non_object_dummy_heading]}"). + gsub(/(#{Mx[:en_a_o]})\s*\s+/,'\1 '). + gsub(/(~\{\s*)\s+/,'\1 '). + gsub(/ \/\//,"#{Mx[:br_line]}"). + gsub(/
/,"#{Mx[:br_line]}"). #needed by xml, xhtml etc. + gsub(/\t/,' '). + gsub(/\342\200\231/u,"'"). #if dob =~/’/ #Avoid #‘ ’ #“ ” + gsub(/\\copy(?:right)?\b/,'©'). + gsub(/\\trademark\b|\\tm\b/,'®') + dob.obj=dob.obj + "\n" + unless dob.is ==:code + case dob.obj + when /\^~/ #% Note must do this first (earlier loop) and then enter gathered data into ~^\d+ + sub_dob=dob.obj.dup + @endnote_array << sub_dob.gsub(/\n/,''). + gsub(/\^~\s+(.+)\s*/,%{#{Mx[:en_a_o]}#{endnote_no} \\1 #{Mx[:en_a_c]}}). + strip + endnote_no+=1 + dob=nil if dob.obj =~/\^~ .+/ #watch, removes 'binary' endnote now in endnote array for later insertion + end + end + end + @tuned_file << dob if dob.is_a?(Object) + end + @tuned_file=@tuned_file.flatten.compact + [@tuned_file,@endnote_array] + end + end +end +__END__ diff --git a/lib/sisu/v5/ao_doc_objects.rb b/lib/sisu/v5/ao_doc_objects.rb new file mode 100644 index 00000000..556304d4 --- /dev/null +++ b/lib/sisu/v5/ao_doc_objects.rb @@ -0,0 +1,481 @@ +# encoding: utf-8 +=begin + + * Name: SiSU + + * Description: a framework for document structuring, publishing and search + + * 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. + + * 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 . + + If you have Internet connection, the latest version of the GPL should be + available at these locations: + + + + + + * SiSU uses: + * Standard SiSU markup syntax, + * Standard SiSU meta-markup syntax, and the + * Standard SiSU object citation numbering and system + + * Hompages: + + + + * Download: + + + * Git + + + + * Ralph Amissah + + + + ** Description: document abstraction + +=end +module SiSU_AO_DocumentStructure + class Extract + def extract(h,o) + h ? h : o + end + end + class ObjectMetadata + attr_accessor :is,:of,:tags,:obj,:digest + def initialize + @tags={} + @is=@tmp=@digest=nil + @of=:meta + end + def metadata(tags) + of= @of #String, classification - group + is= :meta #String, classification - specific type + tags= tags || ((defined? o.tags) ? o.tags : {}) #String, metadata type/tag + obj= nil + @of,@is,@tags,@obj=of,is,tags,obj + self + end + end + class ObjectMeta + attr_accessor :obj,:is,:of,:tag,:digest,:tmp + def initialize + @is=@obj=@tag=@digest=@digest=@tmp=nil + @of=:meta + end + def metadata(h,o=nil) + of= @of #String, classification - group + is= :meta #String, classification - specific type + tag= h[:tag] || ((defined? o.tag) ? o.tag : nil) #String, metadata type/tag + obj= h[:obj] || ((defined? o.obj) ? o.obj : nil) #String, text content + tmp= h[:tmp] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use + digest= h[:digest] || ((defined? o.digest) ? o.digest : nil) #hash digests, either sha256 or md5 + @of,@is,@tag,@obj,@digest,@tmp=of,is,tag,obj,digest,tmp + self + end + end + class ObjectHeading + attr_accessor :obj,:is,:tags,:of,:lv,:ln,:lc,:toc_,:name,:idx,:ocn,:odv,:osp,:node,:parent,:ocn_,:note_,:autonum_,:digest,:tmp + def initialize + @of=:para + @is=@obj=@lv=@ln=@lc=@toc_=@name=@idx=@size=@ocn=@odv=@osp=@node=@parent=@ocn_=@note_=@autonum_=@digest=@tmp=nil + @tags=[] + end + def heading_ln(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 + end + end + def heading_lv(ln) + case ln.to_s + when /1/; 'A' + when /2/; 'B' + when /3/; 'C' + when /4/; '1' + when /5/; '2' + when /6/; '3' + when /7/; '4' + when /8/; '5' + when /9/; '6' + end + end + def heading(h,o=nil) + if not h[:ln] \ + and (h[:lv] and h[:lv]=~/[1-6A-C]/) + h[:ln]=heading_ln(h[:lv]) + elsif not h[:lv] \ + and (h[:ln] and h[:ln].to_s=~/[1-9]/) + h[:lv]=heading_lv(h[:ln]) + end + of= @of #String, classification - group + is= :heading #String, classification - specific type + name= h[:name] || ((defined? o.name) ? o.name : nil) #String, named object? + tags= h[:tags] || ((defined? o.tags) ? o.tags : []) #Array, associated object tags, names if any + obj= h[:obj] || ((defined? o.obj) ? o.obj : nil) #String, text content + idx= h[:idx] || ((defined? o.idx) ? o.idx : nil) #String, book index provided? + ocn= h[:ocn] || ((defined? o.ocn) ? o.ocn : nil) #Integer, sequential on substantive-content objects + odv= h[:odv] || ((defined? o.odv) ? o.odv : nil) + 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 + 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) + ocn_=if h[:ocn_].nil? then ((defined? o.ocn_) ? o.ocn_ : true) #Bool? no ocn, non-substantive content, do not include in toc #consider + else h[:ocn_] + end + autonum_= if h[:autonum_].nil? then ((defined? o.autonum_) ? o.autonum_ : true) #Bool? auto-numbering if requested default on, false suppresses + else h[:autonum_] + end + note_= h[:note_] || ((defined? o.note_) ? o.note_ : false) #Bool, endnotes/footnotes? (processing optimization) + digest= h[:digest] || ((defined? o.digest) ? o.digest : nil) #hash digests, either sha256 or md5 + tmp= h[:tmp] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use + @of,@is,@lv,@ln,@lc,@name,@tags,@obj,@idx,@ocn,@odv,@osp,@node,@parent,@toc_,@ocn_,@note_,@autonum_,@digest,@tmp=of,is,lv,ln,lc,name,tags,obj,idx,ocn,odv,osp,node,parent,toc_,ocn_,note_,autonum_,digest,tmp + self + end + def heading_insert(h,o=nil) + heading(h,o=nil) + @is= :heading_insert #String, classification - specific type + self + end + end + class ObjectPara + attr_accessor :obj,:is,:tags,:of,:name,:idx,:bullet_,:indent,:hang,:ocn,:odv,:osp,:parent,:note_,:image_,:ocn_,:digest,:tmp + def initialize + @of=:para + @is=@obj=@name=@idx=@bullet_=@indent=@hang=@size=@ocn=@odv=@osp=@parent=@note_=@image_=@ocn_=@digest=@tmp=nil + @tags=[] + end + def paragraph(h,o=nil) + of= @of #String, classification - group + is= :para #String, classification - specific type + name= h[:name] || ((defined? o.name) ? o.name : nil) #String, named object? + tags= h[:tags] || ((defined? o.tags) ? o.tags : []) #Array, associated object tags, names if any + obj= h[:obj] || ((defined? o.obj) ? o.obj : nil) #String, text content + idx= h[:idx] || ((defined? o.idx) ? o.idx : nil) #String, book index provided? + ocn= h[:ocn] || ((defined? o.ocn) ? o.ocn : nil) #Integer, sequential on substantive-content objects + odv= h[:odv] || ((defined? o.odv) ? o.odv : nil) + osp= h[:osp] || ((defined? o.osp) ? o.osp : nil) + parent= h[:parent] || ((defined? o.parent) ? o.parent : nil) #[Node parent] + indent= h[:indent].to_s || ((defined? o.indent) ? o.indent.to_s : nil) #Integer, indent level + hang= h[:hang].to_s || ((defined? o.hang) ? o.hang.to_s : nil) #Integer, hanging indent level + bullet_=h[:bullet_] || ((defined? o.bullet_) ? o.bullet_ : false) #Bool, bulleted? + note_= h[:note_] || ((defined? o.note_) ? o.note_ : false) #Bool, endnotes/footnotes? (processing optimization) + image_= h[:image_] || ((defined? o.image_) ? o.image_ : false) #Bool, images? (processing optimization) + ocn_=if h[:ocn_].nil? then ((defined? o.ocn_) ? o.ocn_ : true) #Bool? no ocn, non-substantive content, do not include in toc #consider + else h[:ocn_] + end + digest= h[:digest] || ((defined? o.digest) ? o.digest : nil) #hash digests, either sha256 or md5 + tmp= h[:tmp] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use + @of,@is,@name,@tags,@obj,@indent,@hang,@bullet_,@idx,@ocn,@odv,@osp,@parent,@image_,@note_,@ocn_,@digest,@tmp=of,is,name,tags,obj,indent,hang,bullet_,idx,ocn,odv,osp,parent,image_,note_,ocn_,digest,tmp + self + end + def docinfo(h,o=nil) + of= @of #String, classification - group + is= :docinfo #String, classification - specific type + name= h[:name] || ((defined? o.name) ? o.name : nil) #String, named object? + tags= h[:tags] || ((defined? o.tags) ? o.tags : nil) #Array, associated object tags, names if any + obj= h[:obj] || ((defined? o.obj) ? o.obj : nil) #String, text content + idx= nil #String, book index provided? + ocn= nil #Integer, sequential on substantive-content objects + odv= h[:odv] || ((defined? o.odv) ? o.odv : nil) + osp= h[:osp] || ((defined? o.osp) ? o.osp : nil) + parent= h[:parent] || ((defined? o.parent) ? o.parent : nil) #[Node parent] + indent= nil #Integer, indent level + hang= nil #Integer, indent level + bullet_=false #Bool, bulleted? + note_= false #Bool, endnotes/footnotes? (processing optimization) + image_= h[:image_] || ((defined? o.image_) ? o.image_ : false) #Bool, images? (processing optimization) + ocn_=if h[:ocn_].nil? then ((defined? o.ocn_) ? o.ocn_ : true) #Bool? no ocn, non-substantive content, do not include in toc #consider + else h[:ocn_] + end + digest= h[:digest] || ((defined? o.digest) ? o.digest : nil) #hash digests, either sha256 or md5 + tmp= h[:tmp] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use + @of,@is,@name,@tags,@obj,@indent,@hang,@bullet_,@idx,@ocn,@odv,@osp,@parent,@image_,@note_,@ocn_,@digest,@tmp=of,is,name,tags,obj,indent,hang,bullet_,idx,ocn,odv,osp,parent,image_,note_,ocn_,digest,tmp + self + end + end + class ObjectBlockTxt + attr_accessor :obj,:is,:of,:tags,:idx,:ocn,:odv,:osp,:parent,:note_,:number_,:ocn_,:digest,:tmp + def initialize + @of=:block + @is=@obj=@idx=@ocn=@odv=@osp=@parent=@note_=@number_=@ocn_=@digest=@tmp=nil + @tags=[] + end + def code(h,o=nil) + of= @of #String, classification - group #alt 'code' + is= :code #String, classification - specific type + tags= h[:tags] || ((defined? o.tags) ? o.tags : []) #Array, associated object tags, names if any + obj= h[:obj] || ((defined? o.obj) ? o.obj : nil) #String, text content + idx= h[:idx] || ((defined? o.idx) ? o.idx : nil) #String, book index provided? + ocn= h[:ocn] || ((defined? o.ocn) ? o.ocn : nil) #Integer, sequential on substantive-content objects + odv= h[:odv] || ((defined? o.odv) ? o.odv : nil) + osp= h[:osp] || ((defined? o.osp) ? o.osp : nil) + parent= h[:parent] || ((defined? o.parent) ? o.parent : nil) #[Node parent] + number_= h[:number_] || ((defined? o.number_) ? o.number_ : false) #Bool, numbered or not? + note_= h[:note_] || ((defined? o.note_) ? o.note_ : false) #Bool, endnotes/footnotes? (processing optimization) + ocn_= if h[:ocn_].nil? then ((defined? o.ocn_) ? o.ocn_ : true) #Bool? no ocn, non-substantive content, do not include in toc #consider + else h[:ocn_] + end + digest= h[:digest] || ((defined? o.digest) ? o.digest : nil) #hash digests, either sha256 or md5 + tmp= h[:tmp] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use + @of,@is,@tags,@obj,@idx,@ocn,@odv,@osp,@parent,@number_,@note_,@ocn_,@digest,@tmp=of,is,tags,obj,idx,ocn,odv,osp,parent,number_,note_,ocn_,digest,tmp + self + end + def block(h,o=nil) + of= @of #String, classification - group + is= :block #String, classification - specific type + tags= h[:tags] || ((defined? o.tags) ? o.tags : []) #Array, associated object tags, names if any + obj= h[:obj] || ((defined? o.obj) ? o.obj : nil) #String, text content + idx= h[:idx] || ((defined? o.idx) ? o.idx : nil) #String, book index provided? + ocn= h[:ocn] || ((defined? o.ocn) ? o.ocn : nil) #Integer, sequential on substantive-content objects + odv= h[:odv] || ((defined? o.odv) ? o.odv : nil) + osp= h[:osp] || ((defined? o.osp) ? o.osp : nil) + parent= h[:parent] || ((defined? o.parent) ? o.parent : nil) #[Node parent] + note_= h[:note_] || ((defined? o.note_) ? o.note_ : false) #Bool, endnotes/footnotes? (processing optimization) + ocn_= if h[:ocn_].nil? then ((defined? o.ocn_) ? o.ocn_ : true) #Bool? no ocn, non-substantive content, do not include in toc #consider + else h[:ocn_] + end + digest= h[:digest] || ((defined? o.digest) ? o.digest : nil) #hash digests, either sha256 or md5 + tmp= h[:tmp] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use + @of,@is,@tags,@obj,@idx,@ocn,@odv,@osp,@parent,@note_,@ocn_,@digest,@tmp=of,is,tags,obj,idx,ocn,odv,osp,parent,note_,ocn_,digest,tmp + self + end + def group(h,o=nil) + of= @of #String, classification - group + is= :group #String, classification - specific type + tags= h[:tags] || ((defined? o.tags) ? o.tags : []) #Array, associated object tags, names if any + obj= h[:obj] || ((defined? o.obj) ? o.obj : nil) #String, text content + idx= h[:idx] || ((defined? o.idx) ? o.idx : nil) #String, book index provided? + ocn= h[:ocn] || ((defined? o.ocn) ? o.ocn : nil) #Integer, sequential on substantive-content objects + odv= h[:odv] || ((defined? o.odv) ? o.odv : nil) + osp= h[:osp] || ((defined? o.osp) ? o.osp : nil) + parent= h[:parent] || ((defined? o.parent) ? o.parent : nil) #[Node parent] + note_= h[:note_] || ((defined? o.note_) ? o.note_ : false) #Bool, endnotes/footnotes? (processing optimization) + ocn_= if h[:ocn_].nil? then ((defined? o.ocn_) ? o.ocn_ : true) #Bool? no ocn, non-substantive content, do not include in toc #consider + else h[:ocn_] + end + digest= h[:digest] || ((defined? o.digest) ? o.digest : nil) #hash digests, either sha256 or md5 + tmp= h[:tmp] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use + @of,@is,@tags,@obj,@idx,@ocn,@odv,@osp,@parent,@note_,@ocn_,@digest,@tmp=of,is,tags,obj,idx,ocn,odv,osp,parent,note_,ocn_,digest,tmp + self + end + def alt(h,o=nil) #see block + of= @of #String, classification - group + is= :alt #String, classification - specific type + tags= h[:tags] || ((defined? o.tags) ? o.tags : []) #Array, associated object tags, names if any + obj= h[:obj] || ((defined? o.obj) ? o.obj : nil) #String, text content + idx= h[:idx] || ((defined? o.idx) ? o.idx : nil) #String, book index provided? + ocn= h[:ocn] || ((defined? o.ocn) ? o.ocn : nil) #Integer, sequential on substantive-content objects + odv= h[:odv] || ((defined? o.odv) ? o.odv : nil) + osp= h[:osp] || ((defined? o.osp) ? o.osp : nil) + parent= h[:parent] || ((defined? o.parent) ? o.parent : nil) #[Node parent] + note_= h[:note_] || ((defined? o.note_) ? o.note_ : false) #Bool, endnotes/footnotes? (processing optimization) + ocn_= if h[:ocn_].nil? then ((defined? o.ocn_) ? o.ocn_ : true) #Bool? no ocn, non-substantive content, do not include in toc #consider + else h[:ocn_] + end + digest= h[:digest] || ((defined? o.digest) ? o.digest : nil) #hash digests, either sha256 or md5 + tmp= h[:tmp] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use + @of,@is,@tags,@obj,@idx,@ocn,@odv,@osp,@parent,@note_,@ocn_,@digest,@tmp=of,is,tags,obj,idx,ocn,odv,osp,parent,note_,ocn_,digest,tmp + self + end + def verse(h,o=nil) #part of poem decide how you deal with this + of= @of #String, classification - group + is= :verse #String, classification - specific type + tags= h[:tags] || ((defined? o.tags) ? o.tags : []) #Array, associated object tags, names if any + obj= h[:obj] || ((defined? o.obj) ? o.obj : nil) #String, text content + idx= h[:idx] || ((defined? o.idx) ? o.idx : nil) #String, book index provided? + ocn= h[:ocn] || ((defined? o.ocn) ? o.ocn : nil) #Integer, sequential on substantive-content objects + odv= h[:odv] || ((defined? o.odv) ? o.odv : nil) + osp= h[:osp] || ((defined? o.osp) ? o.osp : nil) + parent= h[:parent] || ((defined? o.parent) ? o.parent : nil) #[Node parent] + ocn_= if h[:ocn_].nil? then ((defined? o.ocn_) ? o.ocn_ : true) #Bool? no ocn, non-substantive content, do not include in toc #consider + else h[:ocn_] + end + digest= h[:digest] || ((defined? o.digest) ? o.digest : nil) #hash digests, either sha256 or md5 + tmp= h[:tmp] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use + @of,@is,@tags,@obj,@idx,@ocn,@odv,@osp,@parent,@note_,@ocn_,@digest,@tmp=of,is,tags,obj,idx,ocn,odv,osp,parent,note_,ocn_,digest,tmp + @h=nil + self + end + end + class ObjectTable + attr_accessor :obj,:is,:of,:lv,:tags,:name,:idx,:indent,:hang,:size,:ocn,:number,:head_,:cols,:widths,:odv,:osp,:parent,:note_,:ocn_,:digest,:tmp + def initialize + @of=:block + @is=@obj=@lv=@name=@idx=@indent=@hang=@size=@ocn,@number,@head_,@cols,@widths=@odv=@osp=@parent=@note_=@ocn_=@digest=@tmp=nil + @tags=[] + end + def table(h,o=nil) + of= @of #String, classification - group + is= :table #String, classification - specific type + tags= h[:tags] || ((defined? o.tags) ? o.tags : []) #Array, associated object tags, names if any + cols= h[:cols] || ((defined? o.cols) ? o.cols : nil) + widths= h[:widths] || ((defined? o.widths) ? o.widths : nil) + obj= h[:obj] || ((defined? o.obj) ? o.obj : nil) #String, text content + idx= h[:idx] || ((defined? o.idx) ? o.idx : nil) #String, book index provided? + ocn= h[:ocn] || ((defined? o.ocn) ? o.ocn : nil) #Integer, sequential on substantive-content objects + odv= h[:odv] || ((defined? o.odv) ? o.odv : nil) + osp= h[:osp] || ((defined? o.osp) ? o.osp : nil) + parent= h[:parent] || ((defined? o.parent) ? o.parent : nil) #[Node parent] + head_= h[:head_] || ((defined? o.head_) ? o.head_ : false) + note_= h[:note_] || ((defined? o.note_) ? o.note_ : false) #Bool, endnotes/footnotes? (processing optimization) + ocn_=if h[:ocn_].nil? then ((defined? o.ocn_) ? o.ocn_ : true) #Bool? no ocn, non-substantive content, do not include in toc #consider + else h[:ocn_] + end + digest= h[:digest] || ((defined? o.digest) ? o.digest : nil) #hash digests, either sha256 or md5 + tmp= h[:tmp] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use + @of,@is,@tags,@cols,@widths,@obj,@idx,@ocn,@odv,@osp,@parent,@head_,@note_,@ocn_,@digest,@tmp=of,is,tags,cols,widths,obj,idx,ocn,odv,osp,parent,head_,note_,ocn_,digest,tmp + self + end + end + class ObjectImage + attr_accessor :obj,:is,:of,:lv,:idx,:size,:ocn,:parent,:note_,:ocn_,:digest,:tmp + def initialize + @of=:image + @is=@obj=@lv=@idx=@size=@ocn=@parent=@note_=@ocn_=@tmp=@digest=nil + @tags=[] + end + def image(h,o=nil) #not yet used, and what of a paragraph containing several images, consider + of= @of #String, classification - group + is= :image #String, classification - specific type + tags= h[:tags] || ((defined? o.tags) ? o.tags : []) #Array, associated object tags, names if any + obj= h[:obj] || ((defined? o.obj) ? o.obj : nil) #String, text content + size= h[:size] || ((defined? o.size) ? o.size : nil) + idx= h[:idx] || ((defined? o.idx) ? o.idx : nil) #String, book index provided? + ocn= h[:ocn] || ((defined? o.ocn) ? o.ocn : nil) #Integer, sequential on substantive-content objects + odv= h[:odv] || ((defined? o.odv) ? o.odv : nil) + osp= h[:osp] || ((defined? o.osp) ? o.osp : nil) + parent= h[:parent] || ((defined? o.parent) ? o.parent : nil) #[Node parent] + note_= h[:note_] || ((defined? o.note_) ? o.note_ : false) #Bool, endnotes/footnotes? (processing optimization) + ocn_=if h[:ocn_].nil? then ((defined? o.ocn_) ? o.ocn_ : true) #Bool? no ocn, non-substantive content, do not include in toc #consider + else h[:ocn_] + end + digest= h[:digest] || ((defined? o.digest) ? o.digest : nil) #hash digests, either sha256 or md5 + tmp= h[:tmp] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use + @of,@is,@tags,@obj,@size,@idx,@ocn,@odv,@osp,@parent,@note_,@ocn_,@digest,@tmp=of,is,tags,obj,size,idx,ocn,odv,osp,parent,note_,ocn_,digest,tmp + self + end + end + class ObjectStructure + attr_accessor :obj,:tag,:node,:lv,:ln,:lc,:status,:is,:of,:tmp + def initialize + @of=:structure + @is=@obj=@node=@lv=@ln=@lc=@status=@tmp=nil + end + def xml_dom(h,o=nil) + 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 + 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] + status= h[:status] || ((defined? o.status) ? o.status : nil) #tag status open or close + tmp= h[:tmp] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use + @of,@is,@obj,@status,@node,@lv,@ln,@lc,@tmp=of,is,obj,status,node,lv,ln,lc,tmp + self + end + end + class ObjectComment + attr_accessor :obj,:is,:of,:tmp + def initialize + @of=:comment + @is=@obj=@tmp=nil + end + def comment(h,o=nil) + of= @of #String, classification - group + is= :comment #String, classification - specific type + obj= h[:obj] || ((defined? o.obj) ? o.obj : nil) #String, text content + tmp= h[:tmp] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use + @of,@is,@obj,@tmp=of,is,obj,tmp + self + end + end + class ObjectFlag + attr_accessor :obj,:is,:of,:flag,:mod,:tmp + def initialize + @of=:flag + @is=@obj=@flag=@mod=@tmp=nil + end + def flag(h,o=nil) + of= @of #String, classification - group + is= :flag #String, classification - specific type + obj= nil #String, text content + flag= h[:flag] || ((defined? o.flag) ? o.flag : nil) #String, text content + mod= h[:mod] || ((defined? o.mod) ? o.mod : nil) #String, text content + tmp= h[:flag] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use + @of,@is,@obj,@flag,@mod,@tmp=of,is,obj,flag,mod,tmp + self + end + def flag_ocn(h,o=nil) + of= @of #String, classification - group + is= :flag_ocn #String, classification - specific type + obj= nil #String, text content + flag= h[:flag] || ((defined? o.flag) ? o.flag : nil) #String, text content + mod= h[:mod] || ((defined? o.mod) ? o.mod : nil) #String, text content + tmp= h[:flag] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use + @of,@is,@obj,@flag,@mod,@tmp=of,is,obj,flag,mod,tmp + self + end + end + class ObjectLayout + attr_accessor :obj,:is,:of,:from,:tmp + def initialize + @of=:layout + @is=@obj=@from=@tmp=nil + end + def break(h,f=nil) #decide how to deal with + of= @of #String, classification - group + is= :break #String, classification - specific type + obj= h[:obj] #String, text content + from= f + tmp= h[:tmp] #available for processing, empty after use + @of,@is,@obj,@from,@tmp=of,is,obj,from,tmp + self + end + def insert(h,o=nil) #decide how to deal with, could mimic paragraph? + of= @of #String, classification - group + is= :insert #String, classification - specific type + obj= h[:obj] || ((defined? o.obj) ? o.obj : nil) #String, text content + tmp= h[:tmp] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use + @of,@is,@obj,@tmp=of,is,obj,tmp + self + end + end +end +__END__ +# ~# |-# no paragraph number # -# not included in toc diff --git a/lib/sisu/v5/ao_doc_str.rb b/lib/sisu/v5/ao_doc_str.rb new file mode 100644 index 00000000..465a5666 --- /dev/null +++ b/lib/sisu/v5/ao_doc_str.rb @@ -0,0 +1,1427 @@ +# encoding: utf-8 +=begin + + * Name: SiSU + + * Description: a framework for document structuring, publishing and search + + * 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. + + * 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 . + + If you have Internet connection, the latest version of the GPL should be + available at these locations: + + + + + + * SiSU uses: + * Standard SiSU markup syntax, + * Standard SiSU meta-markup syntax, and the + * Standard SiSU object citation numbering and system + + * Hompages: + + + + * Download: + + + * Git + + + + * Ralph Amissah + + + + ** Description: document abstraction + +=end +module SiSU_AO_DocumentStructureExtract + class Instantiate < SiSU_Param::Parameters::Instructions + @@flag={ + ocn: :on, + code: :off, + poem: :off, + block: :off, + group: :off, + alt: :off, + table: :off, + table_to: :off, + } + def initialize + @@counter=@@column=@@columns=0 + @@line_mode='' + end + end + class Build + @@flag={ + ocn: :on, + code: :off, + poem: :off, + block: :off, + group: :off, + alt: :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]) + 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 + end + end + def image_test(str) + str=~/\{\s*\S+?\.png.+?\}https?:\/\/\S+/ \ + ? true + : false + end + def bullet_test(str) + (str=~/\*/) \ + ? true + : false + end + def hang_and_indent_test(str) + hang_indent=if str=~/^_([1-9])[^_]/ + [$1,$1] + elsif str=~/^__([1-9])/ + [0,$1] + elsif str=~/^_([0-9])_([0-9])/ + [$1,$2] + else + [0,0] + end + hang,indent=hang_indent[0],hang_indent[1] + [hang,indent] + end + def hang_and_indent_def_test(str1,str2) + hang_indent=if str1=~/^_([1-9])[^_]/ + [$1,$1] + elsif str1=~/^__([1-9])/ + [0,$1] + elsif str1=~/^_([0-9])_([0-9])/ + [$1,$2] + else + [0,0] + end + obj=if str2 =~/^(.+?)\s+\\\\(?:\s+|\n)/ + str2.gsub(/^(.+?)(\s+\\\\(?:\s+|\n))/,"#{Mx[:fa_bold_o]}\\1#{Mx[:fa_bold_c]}\\2") + else + str2.gsub(/^(.+?)\n/,"#{Mx[:fa_bold_o]}\\1#{Mx[:fa_bold_c]}\n") + end + hang,indent=hang_indent[0],hang_indent[1] + [hang,indent,obj] + end + def endnote_test?(str) + (str=~/~\{.+?\}~|~\[.+?\]~/) \ + ? true + : false + end + def extract_tags(str,nametag=nil) + tags=[] + if str.nil? + else + if str =~/(?:^|[ ])\*~([a-z0-9._-]+)(?=[ #{Mx[:br_nl]}]|$)/ + str=str.gsub(/(^|[ ])\*~([a-z0-9._-]+)(?=[ #{Mx[:br_nl]}]|$)/i, + "\\1#{Mx[:tag_o]}\\2#{Mx[:tag_c]}"). + gsub(/ [ ]+/i,' ') + tags=str.scan(/#{Mx[:tag_o]}(\S+?)#{Mx[:tag_c]}/).flatten + str=str.gsub(/[ ]?#{Mx[:tag_o]}\S+?#{Mx[:tag_c]}[ ]?/,' ') #may be issues with spaces would leave one, but "code" blocks? + end + tags=nametag ? (tags << nametag) : tags + end + [str,tags] + end + def rgx_idx_ocn_seg + @rgx_idx_ocn_seg=/(.+?)\s*[+](\d+)/ + end + def construct_idx_array_and_hash(idxraw) + idx_array_raw=idxraw.scan(/[^;]+/) + idx_hash,idx_array,idx_lst={},[],[] + idx_array_raw.each do |idx| + idx_lst=case idx + when /\S+?\s*:/ + idx_couplet_tmp=[] + idx_couplet=idx.scan(/\s*[^:]+\s*/) + if idx_couplet[1] =~/[|]/ + idx_couplet_tmp << idx_couplet[0] << idx_couplet[1].scan(/\s*[^|]+\s*/) + else + idx_couplet_tmp << idx_couplet[0] << [idx_couplet[1]] + end + idx_couplet=idx_couplet_tmp + else [idx] + end + term_nodes=[] + idx_lst.each do |term_node| + case term_node + when String + term_node=term_node[0].chr.capitalize + term_node[1,term_node.length] + term_node=(term_node =~/.+?[+]\d+/) \ + ? term_node + : (term_node + '+0') + term_nodes << term_node + use,plus=rgx_idx_ocn_seg.match(term_node)[1,2] + @use=use.strip + idx_hash[@use]={ sub: [], plus: plus } unless idx_hash[@use] and defined? idx_hash[@use] + when Array + subterm_nodes=[] + term_node.each do |subterm_node| + subterm_node=(subterm_node =~/.+?[+]\d+/) \ + ? subterm_node + : (subterm_node + '+0') + subterm_nodes << subterm_node + sub,sub_plus=rgx_idx_ocn_seg.match(subterm_node)[1,2] + idx_hash[@use]={ sub: [], plus: 0 } unless idx_hash[@use] and defined? idx_hash[@use] + idx_hash[@use][:sub] << {sub.strip => { plus: sub_plus }} + end + term_nodes << subterm_nodes + end + end + idx_array << term_nodes + end + { hash: idx_hash, array: idx_array } + end + def identify_parts + tuned_file=[] + @tuned_block,@tuned_code=[],[] + @@counter,@verse_count=0,0 + @metadata={} + @data.each do |t_o| + if t_o =~/^--([+~-])[#]$/ + h=case $1 + when /[+]/ + @@flag[:ocn]=:on + {flag: :ocn_on} + when /[~]/ + @@flag[:ocn]=:off_headings_substantive + {flag: :ocn_off, mod: :headings_substantive} + when /[-]/ + @@flag[:ocn]=:off_headings_exclude + {flag: :ocn_off, mod: :headings_exclude} + else + @@flag[:ocn]=:on + {flag: :ocn_on} + end + 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 + if t_o !~/^(?:code|poem|alt|group|block)\{|^\}(?:code|poem|alt|group|block)|^(?:table\{|\{table)[ ~]/ \ + and t_o !~/^[`]{3}\s+(?:code|poem|alt|group|block|table)|^[`]{3}(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/ \ + and @@flag[:code]==:off \ + and @@flag[:poem]==:off \ + and @@flag[:group]==:off \ + and @@flag[:block]==:off \ + and @@flag[:alt]==:off \ + and @@flag[:table]==:off + unless t_o =~/^(?:@\S+?:|%+)\s/ # extract book index for paragraph if any + idx=if t_o=~/^=\{(.+)\}\s*$\Z/m; m=$1 + m=m.split(/\n/).join(' '). + gsub(/\s+([|:;])\s+/,'\1'). + gsub(/\s+([+]\d+)\s+/,'\1') + t_o=t_o.gsub(/\n=\{.+\}\s*$\Z/m,'') + idx_array_and_hash=construct_idx_array_and_hash(m) + idx_array_and_hash[:hash] + else nil + end + end + 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 + tag,obj=$1,$2 + @metadata[tag]=obj + end + t_o=nil + when /^%+\s/ #comment + t_o=if t_o=~/^%+\s+(.+)/ + h={obj: $1} + SiSU_AO_DocumentStructure::ObjectComment.new.comment(h) + else nil + end + when /^:?([A-C1-6])\~/ #heading / lv + lv=$1 + ln=ln_get(lv) + t_o=if t_o=~/^:?[A-C1-6]\~\s+(.+)/m + obj=$1 + note=endnote_test?(obj) + obj,tags=extract_tags(obj) + if @@flag[:ocn]==:off_headings_exclude \ + or @@flag[:ocn]==:off_headings_substantive + unless obj =~ /[~-][#]\s*$/ + if @@flag[:ocn]==:off_headings_exclude + obj << ' -#' + elsif @@flag[:ocn]==:off_headings_substantive + obj << ' ~#' + end + end + 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 + name,obj=$1,$2 + note=endnote_test?(obj) + obj,tags=extract_tags(obj) + if @@flag[:ocn]==:off_headings_exclude \ + or @@flag[:ocn]==:off_headings_substantive + unless obj =~ /[~-][#]\s*$/ + if @@flag[:ocn]==:off_headings_exclude + obj << ' -#' + elsif @@flag[:ocn]==:off_headings_substantive + obj << ' ~#' + end + end + 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 + name,obj=$1,$2 + note=endnote_test?(obj) + obj,tags=extract_tags(obj,name) + if @@flag[:ocn]==:off_headings_exclude \ + or @@flag[:ocn]==:off_headings_substantive + unless obj =~ /[~-][#]\s*$/ + if @@flag[:ocn]==:off_headings_exclude + obj << ' -#' + elsif @@flag[:ocn]==:off_headings_substantive + obj << ' ~#' + end + end + end + h={ lv: lv, name: name, obj: obj, idx: idx, tags: tags } + SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h) + else nil + end + when /^_(?:[1-9]!?|[1-9]?\*)\s+/ #indented and/or bullet paragraph + t_o=if t_o=~/^(_(?:[1-9]?\*|[1-9]!?)\s+)(.+)/m + tst,obj=$1,$2 + if t_o=~/^_[1-9]!\s+.+/m + hang,indent,obj=hang_and_indent_def_test(tst,obj) + else + hang,indent=hang_and_indent_test(tst) + end + bullet=bullet_test(tst) + image=image_test(obj) + note=endnote_test?(obj) + obj,tags=extract_tags(obj) + unless obj=~/\A\s*\Z/m + if @@flag[:ocn]==:off_headings_exclude \ + or @@flag[:ocn]==:off_headings_substantive + unless obj =~ /[~-][#]\s*$/ + obj << ' ~#' + end + end + h={ bullet_: bullet, hang: hang, indent: indent, obj: obj, idx: idx, note_: note, image_: image, tags: tags } + SiSU_AO_DocumentStructure::ObjectPara.new.paragraph(h) + end + else nil + end + when /^_[0-9]?_[0-9]!?\s+/ #hanging indent paragraph + t_o=if t_o=~/^(_[0-9]?_[0-9]!?\s+)(.+)/m + tst,obj=$1,$2 + if t_o=~/^_[0-9]?_[0-9]!\s+.+/m + hang,indent,obj=hang_and_indent_def_test(tst,obj) + else + hang,indent=hang_and_indent_test(tst) + end + image=image_test(obj) + note=endnote_test?(obj) + obj,tags=extract_tags(obj) + unless obj=~/\A\s*\Z/m + if @@flag[:ocn]==:off_headings_exclude \ + or @@flag[:ocn]==:off_headings_substantive + unless obj =~ /[~-][#]\s*$/ + obj << ' ~#' + end + end + h={ hang: hang, indent: indent, obj: obj, idx: idx, note_: note, image_: image, tags: tags } + SiSU_AO_DocumentStructure::ObjectPara.new.paragraph(h) + end + else nil + end + when /^<(?:br)?:(?:pa?r|o(?:bj|---)?)>\s*$/ #[br:par] #[br:obj] + SiSU_AO_DocumentStructure::ObjectLayout.new.break(Hx[:br_obj]) + when /^(?:-\\\\-|<:pb>)\s*$/ #[br:pg] + SiSU_AO_DocumentStructure::ObjectLayout.new.break(Hx[:br_page],:markup) + when /^(?:=\\\\=|<:pn>)\s*$/ #[br:pgn] + SiSU_AO_DocumentStructure::ObjectLayout.new.break(Hx[:br_page_new],:markup) + when /^-\.\.-\s*$/ #[br:pgl] + SiSU_AO_DocumentStructure::ObjectLayout.new.break(Hx[:br_page_line],:markup) + else #paragraph + image=image_test(t_o) + note=endnote_test?(t_o) + obj,tags=extract_tags(t_o) + if @@flag[:ocn]==:off_headings_exclude \ + or @@flag[:ocn]==:off_headings_substantive + unless obj =~ /[~-][#]\s*$/ + obj << ' ~#' + end + end + unless obj=~/\A\s*\Z/m + h={ bullet_: false, indent: 0, hang: 0, obj: obj, idx: idx, note_: note, image_: image, tags: tags } + SiSU_AO_DocumentStructure::ObjectPara.new.paragraph(h) + end + end + elsif @@flag[:code]==:off + if t_o =~/^(?:code\{|[`]{3}\s+code)/ + @@flag[:code]=case t_o + when /^code\{/; :curls + when /^[`]{3}\s+code/; :tics + else @@flag[:code] #error + end + @@counter=1 + @codeblock_numbered=(t_o =~/^(?:code\{#|[`]{3}\s+code\s[#])/) ? true : false + h={ obj: 'code block start' } #introduce a counter + 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 + else @@flag[:poem] #error + end + h={ obj: 'poem start' } #introduce a counter + t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h) + tuned_file << t_o + elsif t_o =~/^(?:group\{|[`]{3}\s+group)/ + @@flag[:group]=case t_o + when /^group\{/; :curls + when /^[`]{3}\s+group/; :tics + else @@flag[:group] #error + end + h={ obj: 'group text start' } #introduce a counter + t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h) + tuned_file << t_o + elsif t_o =~/^(?:block\{|[`]{3}\s+block)/ + @@flag[:block]=case t_o + when /^block\{/; :curls + when /^[`]{3}\s+block/; :tics + else @@flag[:block] #error + end + h={ obj: 'block text start' } #introduce a counter + t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h) + tuned_file << t_o + elsif t_o =~/^(?:alt\{|[`]{3}\s+alt)/ + @@flag[:alt]=case t_o + when /^alt\{/; :curls + when /^[`]{3}\s+alt/; :tics + else @@flag[:alt] #error + end + h={ obj: 'alt text start' } #introduce a counter + t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h) + tuned_file << t_o + elsif t_o =~/^(?:table\{|[`]{3}\s+table|\{table)[ ~]/ + h={ obj: 'table start' } #introduce a counter + ins=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h) + tuned_file << ins + if t_o=~/^table\{(?:~h)?\s+/ + @@flag[: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=~/^[`]{3}\s+table(?:~h)?\s+c\d+/ + @@flag[:table]=:tics + @rows='' + case t_o + when /^[`]{3}\s+table~h\s+c(\d+);\s+(.+)/ + cols=$1 + col=$2.scan(/\d+/) + heading=true + when /^[`]{3}\s+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 } + t_o=SiSU_AO_DocumentStructure::ObjectTable.new.table(h) unless h.nil? + tuned_file << t_o + h={ obj: 'table end' } #introduce a counter + t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h) + t_o + elsif t_o=~/^[`]{3}\s+table(?:~h)?\s+/ + m1,m2,hd=nil,nil,nil + h=case t_o + when /^[`]{3}\s+table~h\s+(.+?)\n(.+)\Z/m #two table representations should be consolidated as one + m1,tbl,hd=$1,$2,true + when /^[`]{3}\s+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 } + t_o=SiSU_AO_DocumentStructure::ObjectTable.new.table(h) unless h.nil? + tuned_file << t_o + h={ obj: 'table end' } #introduce a counter + t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(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 } + t_o=SiSU_AO_DocumentStructure::ObjectTable.new.table(h) unless h.nil? + tuned_file << t_o + h={ obj: 'table end' } #introduce a counter + t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h) + t_o + end + end + t_o + end + if @@flag[:table]==:curls or @@flag[:table]==:tics + if (@@flag[:table]==:curls \ + and t_o =~/^\}table/) \ + or (@@flag[:table]==:tics \ + and t_o =~/^[`]{3}(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/) + @@flag[:table]=:off + headings,columns,widths,idx=@h[:head_],@h[:cols],@h[:widths],@h[:idx] + @h={ head_: headings, cols: columns, widths: widths, idx: idx, obj: @rows } + t_o=SiSU_AO_DocumentStructure::ObjectTable.new.table(@h) + tuned_file << t_o + @h,@rows=nil,'' + h={ obj: 'table end' } #introduce a counter + t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h) + t_o + else + if t_o.is_a?(String) \ + and t_o !~/^(?:table\{|[`]{3}\s+table)/ + t_o=t_o.gsub(/^\n+/m,''). #check added for ruby 1.9.2 not needed in 1.8 series (tested in v2) + gsub(/\n+/m,"#{Mx[:tc_p]}") + @rows += t_o + Mx[:tc_c] + end + t_o=nil + end + end + if @@flag[:code]==:curls or @@flag[:code]==:tics + if (@@flag[:code]==:curls and t_o =~/^\}code/) \ + or (@@flag[:code]==:tics and t_o =~/^[`]{3}(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/) + @@flag[:code]=:off + obj=@tuned_code.join("\n") + tags=[] + h={ obj: obj, tags: tags, number_: @codeblock_numbered } + t_o=SiSU_AO_DocumentStructure::ObjectBlockTxt.new.code(h) + @tuned_code=[] + tuned_file << t_o + h={ obj: 'code block end' } #introduce a counter + t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h) + end + if (@@flag[:code]==:curls or @@flag[:code]==:tics) \ + and t_o.is_a?(String) + sub_array=t_o.dup + "#{Mx[:br_nl]}" + @line_mode=[] + sub_array.scan(/.+/) {|w| @line_mode << w if w =~/[\S]+/} + t_o=SiSU_AO_DocumentStructureExtract::Build.new(@md,@line_mode).build_lines(:code).join + @tuned_code << t_o + t_o=nil + end + elsif (@@flag[:poem]==:curls or @@flag[:poem]==:tics) \ + or (@@flag[:group]==:curls or @@flag[:group]==:tics) \ + or (@@flag[:block]==:curls or @@flag[:block]==:tics) \ + or (@@flag[:alt]==:curls or @@flag[:alt]==:tics) + if (@@flag[:poem]==:curls and t_o =~/^\}poem/) \ + or (@@flag[:poem]==:tics and t_o =~/^[`]{3}(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/) + @@flag[:poem]=:off + h={ obj: 'poem end' } #introduce a counter + t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h) + elsif (@@flag[:group]==:curls and t_o =~/^\}group/) \ + or (@@flag[:group]==:tics and t_o =~/^[`]{3}(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/) + @@flag[:group]=:off + obj,tags=extract_tags(@tuned_block.join("\n")) + h={ obj: obj, tags: tags } + @tuned_block=[] + t_o=SiSU_AO_DocumentStructure::ObjectBlockTxt.new.group(h) + tuned_file << t_o + h={ obj: 'group text end' } #introduce a counter + t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h) + elsif (@@flag[:block]==:curls and t_o =~/^\}block/) \ + or (@@flag[:block]==:tics and t_o =~/^[`]{3}(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/) + @@flag[:block]=:off + obj,tags=extract_tags(@tuned_block.join("\n")) + h={ obj: obj, tags: tags } + @tuned_block=[] + t_o=SiSU_AO_DocumentStructure::ObjectBlockTxt.new.block(h) + tuned_file << t_o + h={ obj: 'block text end' } #introduce a counter + t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h) + elsif (@@flag[:alt]==:curls and t_o =~/^\}alt/) \ + or (@@flag[:alt]==:tics and t_o =~/^[`]{3}(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/) + @@flag[:alt]=:off + obj,tags=extract_tags(@tuned_block.join("\n")) + h={ obj: obj, tags: tags } + t_o=SiSU_AO_DocumentStructure::ObjectBlockTxt.new.alt(h) + @tuned_block=[] + tuned_file << t_o + h={ obj: 'alt text end' } #introduce a counter + t_o=SiSU_AO_DocumentStructure::ObjectComment.new.comment(h) + end + if (@@flag[:poem]==:curls or @@flag[:poem]==:tics \ + or @@flag[:group]==:curls or @@flag[:group]==:tics \ + or @@flag[:alt]==:curls or @@flag[:alt]==:tics) \ + and t_o =~/\S/ \ + and t_o !~/^(?:\}(?:verse|code|alt|group|block)|(?:verse|code|alt|group|block)\{)/ \ + and t_o !~/^[`]{3}\s+(?:code|poem|alt|group|block)|^[`]{3}(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/ # fix logic + sub_array=t_o.dup + @line_mode=sub_array.scan(/.+/) + type=if @@flag[:poem]==:curls or @@flag[: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| + v=v.gsub(/\n/m,"#{Mx[:br_nl]}\n") + obj,tags=extract_tags(v) + h={ obj: obj, tags: tags } + t_o=SiSU_AO_DocumentStructure::ObjectBlockTxt.new.verse(h) + tuned_file << t_o + end + :poem + else :group + end + end + @verse_count+=1 if @@flag[:poem]==:curls or @@flag[:poem]==:tics + end + if @@flag[:code]==:off + if @@flag[:poem]==:curls or @@flag[:poem]==:tics \ + or @@flag[:group]==:curls or @@flag[:group]==:tics \ + or @@flag[:alt]==:curls or @@flag[:alt]==:tics + if t_o.is_a?(String) + t_o=t_o.gsub(/\n/m,"#{Mx[:br_nl]}"). + gsub(/[ ][ ]/m,"#{Mx[:nbsp]*2}"). + gsub(/#{Mx[:nbsp]}\s/,"#{Mx[:nbsp]*2}") + t_o=t_o + Mx[:br_nl] if t_o =~/\S+/ + elsif t_o.is==:group \ + || t_o.is==:block \ + || t_o.is==:alt \ + || t_o.is==:verse + t_o.obj=t_o.obj.gsub(/\n/m,"#{Mx[:br_nl]}"). + gsub(/[ ][ ]/m,"#{Mx[:nbsp]*2}"). + gsub(/#{Mx[:nbsp]}\s/,"#{Mx[:nbsp]*2}") + end + @tuned_block << t_o if t_o =~/\S+/ + else tuned_file << t_o + end + else tuned_file << t_o + end + end + if @md.flag_endnotes + tuned_file << @pb + h={ ln: 2, lc: 2, 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 } + 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 } + tuned_file << SiSU_AO_DocumentStructure::ObjectHeading.new.heading_insert(h) + h={ ln: 4, lc: 3, 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 } + 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 } + tuned_file << SiSU_AO_DocumentStructure::ObjectHeading.new.heading_insert(h) + h={ obj: 'eof' } + meta=SiSU_AO_DocumentStructure::ObjectMetadata.new.metadata(@metadata) + [tuned_file,meta] + end + def table_rows_and_columns_array(table_str) + table=[] + table_str.split(/#{Mx[:tc_c]}/).each do |table_row| + table_row_with_columns=table_row.split(/#{Mx[:tc_p]}/) + table << table_row_with_columns + end + table + end + def meta_heading(h) + h={ lv: h[:lv], ln: h[:ln], name: h[:name], obj: h[:obj], ocn: '0' } + SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h) + end + def meta_para(str) + h={ obj: str, ocn_: false } + SiSU_AO_DocumentStructure::ObjectPara.new.paragraph(h) + end + def build_lines(type=:none) + lines,lines_new=@data,[] + lines.each do |line| + line=if line =~/\S/ \ + and line !~/^(?:code\{|\}code)/ \ + and line !~/^(?:[`]{3}\s+code|[`]{3}(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$)/ \ + and not line.is_a?(Hash) #watch + @@counter+=1 if @@flag[:code]==:curls or @@flag[: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 + line=if line =~/(?:https?|file|ftp):\/\/\S+$/ + line.gsub(/\s*$/," #{Mx[:br_nl]}") + else line.gsub(/\s*$/,"#{Mx[:br_nl]}") #unless type=='code' + end + elsif line =~/^\s*$/ + line.gsub(/\s*$/,"#{Mx[:br_nl]}") + else line + end + lines_new << line + end + lines_new + end + end + class Structure # this must happen early + def initialize(md,dob) + @md,@dob=md,dob + end + def structure + structure_markup + @dob + end + def structure_markup #build structure where structure provided only in meta header + @dob=if @dob.is==:para \ + && (((@dob.hang !~/[1-9]/) && (@dob.indent !~/[1-9]/)) \ + || (@dob.hang != @dob.indent)) \ + and not @dob.bullet_ + @dob=case @dob.obj + when /^#{@md.lv1}/ + h={ lv: 'A', ln: 1 } + SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h,@dob) + when /^#{@md.lv2}/ + h={ lv: 'B', ln: 2 } + SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h,@dob) + when /^#{@md.lv3}/ + h={ lv: 'C', ln: 3 } + SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h,@dob) + when /^#{@md.lv4}/ + h={ lv: '1', ln: 4 } + SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h,@dob) + when /^#{@md.lv5}/ + h={ lv: '2', ln: 5 } + SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h,@dob) + when /^#{@md.lv6}/ + h={ lv: '3', ln: 6 } + SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h,@dob) + else @dob + end + else @dob + end + @dob + end + end + class OCN + def initialize(md,data) + @md,@data=md,data + end + def structure_info + def lv + %w[0 A~ B~ C~ 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' + 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' + end + end + self + end + def document_structure_check_info(node,node_parent,status=:ok) + node_ln=/^([0-6])/.match(node)[1].to_i + node_parent_ln=/^([0-6])/.match(node_parent)[1].to_i + if status==:error \ + or @md.opt.act[:maintenance][:set]==:on + puts %{node: #{node}, parent node: #{node_parent} #{status.upcase}} + if status==:error + node_ln=/^([0-6])/.match(node)[1].to_i + node_parent_ln=/^([0-6])/.match(node_parent)[1].to_i + puts %{current level: #{structure_info.lv[node_ln]} (possible parent levels: #{structure_info.possible_parents(structure_info.lv[node_ln])}) +parent level: #{structure_info.lv[node_parent_ln]} (possible child levels: #{structure_info.possible_children(structure_info.lv[node_parent_ln])}) +-- } + end + end + end + def warning_incorrect_parent_level_or_level(txt) + puts %{warning, +#{txt} +has incorrect level and/or parent level} + end + 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 + regex_exclude_ocn_and_node = /#{Rx[:meta]}|^@\S+?:\s|^4~endnotes|^#{Mx[:lv_o]}4:endnotes#{Mx[:lv_c]}|^\^~ |<:e[:_]\d+?>|^<:\#|<:- |<[:!]!4|
+ 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 + end + end + if not dob.obj =~/~#|-#/ + ocn+=1 + end + if dob.is==:heading \ + and (ln.to_s =~/^[1-9]/ \ + or ln.to_s =~@md.lv1 \ + or ln.to_s =~@md.lv2 \ + or ln.to_s =~@md.lv3 \ + or ln.to_s =~@md.lv4 \ + or ln.to_s =~@md.lv5 \ + or ln.to_s =~@md.lv6) + if not dob.obj =~/~#|-#/ + ocnh+=1 + end + if ln==1 \ + or ln=~@md.lv1 + if not dob.obj =~/~#|-#/ + ocn_flag=true + ocnh1+=1 #heading + node1="1:#{ocnh1};#{ocn}" + else + ocn_flag=false + node1="1:0;0" + end + document_structure_check_info(node1,node0) + @collapsed_lv1=1 + collapsed_level=@collapsed_lv1 + node,ocn_sp,parent=node1,"h#{ocnh}",node0 #FIX + elsif ln==2 \ + or ln=~@md.lv2 + if not dob.obj =~/~#|-#/ + ocn_flag=true + ocnh2+=1 + node2="2:#{ocnh2};#{ocn}" + else + ocn_flag=false + node2="2:0;0" + end + parent=if node1 + document_structure_check_info(node2,node1) + @collapsed_lv2=@collapsed_lv1+1 + node1 + else + document_structure_check_info(node2,node0,:error) + node0 + end + collapsed_level=@collapsed_lv2 + node,ocn_sp=node2,"h#{ocnh}" + elsif ln==3 \ + or ln=~@md.lv3 + if not dob.obj =~/~#|-#/ + ocn_flag=true + ocnh3+=1 + node3="3:#{ocnh3};#{ocn}" + else + ocn_flag=false + node3="3:0;0" + end + parent=if node2 + document_structure_check_info(node3,node2) + @collapsed_lv3=@collapsed_lv2+1 + node2 + elsif node1 + warning_incorrect_parent_level_or_level(dob.obj) + puts %{parent is :A~ & this level #{dob.lv} +either parent should be level :B~ +or this level should be level :B~ rather than #{dob.lv}} + document_structure_check_info(node3,node1,:error) + @collapsed_lv3=@collapsed_lv1+1 + node1 + else + document_structure_check_info(node3,node0,:error) + warning_incorrect_parent_level_or_level(dob.obj) + node0 + end + collapsed_level=@collapsed_lv3 + node,ocn_sp=node3,"h#{ocnh}" + elsif ln==4 \ + or ln=~@md.lv4 + if not dob.obj =~/~#|-#/ + ocn_flag=true + ocnh4+=1 + node4="4:#{ocnh4};#{ocn}" + else + ocn_flag=false + node4="4:0;0" + end + parent=if node3 + document_structure_check_info(node4,node3) + @collapsed_lv4=@collapsed_lv3+1 + node3 + elsif node2 + document_structure_check_info(node4,node2) + @collapsed_lv4=@collapsed_lv2+1 + node2 + elsif node1 + document_structure_check_info(node4,node1) + @collapsed_lv4=@collapsed_lv1+1 + node1 + else + warning_incorrect_parent_level_or_level(dob.obj) + document_structure_check_info(node4,node0,:error) + node0 + end + collapsed_level=@collapsed_lv4 + node,ocn_sp=node4,"h#{ocnh}" + elsif ln==5 \ + or ln=~@md.lv5 + if not dob.obj =~/~#|-#/ + ocn_flag=true + ocnh5+=1 + node5="5:#{ocnh5};#{ocn}" + else + ocn_flag=false + node5="5:0;0" + end + parent=if node4 + document_structure_check_info(node5,node4) + @collapsed_lv5=@collapsed_lv4+1 + node4 + elsif node3 + warning_incorrect_parent_level_or_level(dob.obj) + document_structure_check_info(node5,node3,:error) + @collapsed_lv5=@collapsed_lv3+1 + node3 + elsif node2 + warning_incorrect_parent_level_or_level(dob.obj) + document_structure_check_info(node5,node2,:error) + @collapsed_lv5=@collapsed_lv2+1 + node2 + elsif node1 + warning_incorrect_parent_level_or_level(dob.obj) + document_structure_check_info(node5,node1,:error) + @collapsed_lv5=@collapsed_lv1+1 + node1 + else + document_structure_check_info(node5,node0,:error) + node0 + end + collapsed_level=@collapsed_lv5 + node,ocn_sp=node5,"h#{ocnh}" + elsif ln==6 \ + or ln=~@md.lv6 + if not dob.obj =~/~#|-#/ + ocn_flag=true + ocnh6+=1 + node6="6:#{ocnh6};#{ocn}" + else + ocn_flag=false + node6="6:0;0" + end + parent=if node5 + document_structure_check_info(node6,node5) + @collapsed_lv6=@collapsed_lv5+1 + node5 + elsif node4 + warning_incorrect_parent_level_or_level(dob.obj) + puts "parent is level 4~ & this level #{dob.lv} +either parent should be level 5~ +or this level should be 5~ rather #{dob.lv}" #level 6 + document_structure_check_info(node6,node4,:error) + @collapsed_lv6=@collapsed_lv4+1 + node4 + elsif node3 + warning_incorrect_parent_level_or_level(dob.obj) + document_structure_check_info(node6,node3,:error) + @collapsed_lv6=@collapsed_lv3+1 + node3 + elsif node2 + warning_incorrect_parent_level_or_level(dob.obj) + document_structure_check_info(node6,node2,:error) + @collapsed_lv6=@collapsed_lv2+1 + node2 + elsif node1 + warning_incorrect_parent_level_or_level(dob.obj) + document_structure_check_info(node6,node1,:error) + @collapsed_lv6=@collapsed_lv1+1 + node1 + else + document_structure_check_info(node6,node0,:error) + node0 + end + collapsed_level=@collapsed_lv6 + node,ocn_sp=node6,"h#{ocnh}" + end + else + if not dob.obj =~/~#|-#/ + ocn_flag=true + else + ocn_flag=false + end + ocno+=1 + if dob.is==:table + ocnt+=1 + ocn_sp,parent="t#{ocnt}",node + elsif dob.is==:code + ocnc+=1 + ocn_sp,parent="c#{ocnc}",node + elsif dob.is==:group \ + || dob.is==:block \ + || dob.is==:alt \ + || dob.is==:verse + ocng+=1 #group, poem + ocn_sp,parent="g#{ocng}",node + elsif dob.is==:image #check + ocni+=1 + ocn_sp,parent="i#{ocni}",node + else ocnp+=1 #paragraph + ocn_sp,parent="p#{ocnp}",node + end + end + if dob.is==:heading + if ocn_flag==true + dob.ln,dob.node,dob.ocn,dob.ocn_,dob.odv,dob.osp,dob.parent,dob.lc=ln,node,ocn,ocn_flag,ocn_dv,ocn_sp,parent,collapsed_level + else + ocnu+=1 + dob.obj=dob.obj.gsub(/#{Mx[:fa_o]}[~-]##{Mx[:fa_c]}/,'') if dob.obj + ocn_dv,ocn_sp="u#{ocnu}","u#{ocnu}" + dob.ln,dob.node,dob.ocn,dob.ocn_,dob.odv,dob.osp,dob.parent,dob.lc=ln,node,nil,ocn_flag,ocn_dv,ocn_sp,parent,collapsed_level + end + else + if dob.of !=:meta \ + && dob.of !=:comment \ + && dob.of !=:layout + if ocn_flag == true + dob.ocn,dob.ocn_,dob.odv,dob.osp,dob.parent=ocn,ocn_flag,ocn_dv,ocn_sp,parent + else + ocnu+=1 + dob.obj=dob.obj.gsub(/#{Mx[:fa_o]}[~-]##{Mx[:fa_c]}/,'') if dob.obj + ocn_dv,ocn_sp="u#{ocnu}","u#{ocnu}" + dob.ocn,dob.ocn_,dob.odv,dob.osp,dob.parent=nil,ocn_flag,ocn_dv,ocn_sp,parent + end + end + end + h + elsif dob.obj=~/#{Mx[:pa_non_object_no_heading]}/ + dob.obj=dob.obj.gsub(/#{Mx[:pa_non_object_no_heading]}/,'') + if dob.is==:para + h={ obj: dob.obj, ocn_: false, ocn: nil, hang: dob.hang, indent: dob.indent, bullet_: dob.bullet_, tags: dob.tags, parent: dob.parent } + dob=SiSU_AO_DocumentStructure::ObjectPara.new.paragraph(h,dob) + elsif dob.is==:heading + h={ obj: dob.obj, ocn_: false, ocn: nil, toc_: true, parent: dob.parent } + dob=SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h,dob) + end + elsif dob.obj=~/#{Mx[:pa_non_object_dummy_heading]}/ + dob.obj=dob.obj.gsub(/#{Mx[:pa_non_object_dummy_heading]}/,'') + if dob.is==:para + h={ obj: dob.obj, ocn_: false, ocn: nil, hang: dob.hang, indent: dob.indent, bullet_: dob.bullet_, tags: dob.tags, parent: dob.parent } + dob=SiSU_AO_DocumentStructure::ObjectPara.new.paragraph(h,dob) + elsif dob.is==:heading + h={ obj: dob.obj, ocn_: false, ocn: nil, toc_: false, parent: dob.parent } + dob=SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h,dob) + end + else dob + end + if dob.is==:code \ + || dob.is==:verse \ + || dob.is==:alt \ + || dob.is==:group \ + || dob.is==:block + dob.obj=dob.obj.gsub(/\n\n/,"\n") #newlines taken out + end + @o_array << dob + end + @o_array + end + end + class XML + def initialize(md,data) + @data,@md=data,md + end + def dom + @s=['0', + 'A', + 'B', + 'C', + '1', + '2', + '3' + ] + @sp=' ' + tuned_file=structure_build + tuned_file + end + def structure_build + data=@data + tuned_file=[] + hs=[0,false,false,false] + t={ lv: @s[0], status: 'open' } + tuned_file << tags(t) + if @md.opt.act[:verbose_plus][:set]==:on + puts "\nXML sisu structure outline --->\n" + puts "<#{@s[0]}>" + end + data.each_with_index do |o,i| + if o.is==:heading \ + || o.is==:heading_insert + case o.ln + when 1 + 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=[1,true,false,false] + when 2 + 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=[2,true,true,false] + when 3 + 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=[3,true,true,true] + when 4 + 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]=4 + when 5 + 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]=5 + when 6 + 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]=6 + end + end + tuned_file << o + end + if @md.opt.act[:verbose_plus][:set]==:on + puts_tag_close(0,hs) + end + tuned_file << tag_close(0,hs) + tuned_file=tuned_file.flatten + end + def tags(o) + tag=(o[:status]=='open') \ + ? %{<#{o[:lv]} id="#{o[:node]}">} + : "" + 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 + 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 + end + def tag_open(o,tag) + t={ lv: tag[o.ln], node: o.node, status: 'open' } + t_o=tags(t) + t_o + end + def tag_close(lev,hs) + ary=[] + case hs[0] + when 1 + if (lev <= 1) and hs[1] + t={ lv: @s[1], status: 'close' } + ary << tags(t) + end + if (lev==0) + t={ lv: @s[0], status: 'close' } + ary << tags(t) + end + when 2 + if (lev <= 2) and hs[2] + t={ lv: @s[2], status: 'close' } + ary << tags(t) + end + if (lev <= 1) and hs[1] + t={ lv: @s[1], status: 'close' } + ary << tags(t) + end + if (lev==0) + t={ lv: @s[0], status: 'close' } + ary << tags(t) + end + when 3 + if (lev <= 3) and hs[3] + t={ lv: @s[3], status: 'close' } + ary << tags(t) + end + if (lev <= 2) and hs[2] + t={ lv: @s[2], status: 'close' } + ary << tags(t) + end + if (lev <= 1) and hs[1] + t={ lv: @s[1], status: 'close' } + ary << tags(t) + end + if (lev==0) + t={ lv: @s[0], status: 'close' } + ary << tags(t) + end + when 4 + if (lev <= 4) + t={ lv: @s[4], status: 'close' } + ary << tags(t) + end + if (lev <= 3) and hs[3] + t={ lv: @s[3], status: 'close' } + ary << tags(t) + end + if (lev <= 2) and hs[2] + t={ lv: @s[2], status: 'close' } + ary << tags(t) + end + if (lev <= 1) and hs[1] + t={ lv: @s[1], status: 'close' } + ary << tags(t) + end + if (lev==0) + t={ lv: @s[0], status: 'close' } + ary << tags(t) + end + when 5 + if (lev <= 5) + t={ lv: @s[5], status: 'close' } + ary << tags(t) + end + if (lev <= 4) + t={ lv: @s[4], status: 'close' } + ary << tags(t) + end + if (lev <= 3) and hs[3] + t={ lv: @s[3], status: 'close' } + ary << tags(t) + end + if (lev <= 2) and hs[2] + t={ lv: @s[2], status: 'close' } + ary << tags(t) + end + if (lev <= 1) and hs[1] + t={ lv: @s[1], status: 'close' } + ary << tags(t) + end + if (lev==0) + t={ lv: @s[0], status: 'close' } + ary << tags(t) + end + when 6 + if (lev <= 6) + t={ lv: @s[6], status: 'close' } + ary << tags(t) + end + if (lev <= 5) + t={ lv: @s[5], status: 'close' } + ary << tags(t) + end + if (lev <= 4) + t={ lv: @s[4], status: 'close' } + ary << tags(t) + end + if (lev <= 3) and hs[3] + t={ lv: @s[3], status: 'close' } + ary << tags(t) + end + if (lev <= 2) and hs[2] + t={ lv: @s[2], status: 'close' } + ary << tags(t) + end + if (lev <= 1) and hs[1] + t={ lv: @s[1], status: 'close' } + ary << tags(t) + end + if (lev==0) + t={ lv: @s[0], status: 'close' } + ary << tags(t) + end + end + ary + end + def puts_tag_open(o,tag) + puts %{#{@sp*o.ln}<#{tag[o.ln]} id="#{o.node}">} + end + def puts_tag_close(lev,hs) + case hs[0] + when 1 + puts "#{@sp*1}" if (lev <= 1) and hs[1] + puts "" if (lev==0) + when 2 + puts "#{@sp*2}" if (lev <= 2) and hs[2] + puts "#{@sp*1}" if (lev <= 1) and hs[1] + puts "" if (lev==0) + when 3 + puts "#{@sp*3}" if (lev <= 3) and hs[3] + puts "#{@sp*2}" if (lev <= 2) and hs[2] + puts "#{@sp*1}" if (lev <= 1) and hs[1] + puts "" if (lev==0) + when 4 + puts "#{@sp*4}" if (lev <= 4) + puts "#{@sp*3}" if (lev <= 3) and hs[3] + puts "#{@sp*2}" if (lev <= 2) and hs[2] + puts "#{@sp*1}" if (lev <= 1) and hs[1] + puts "" if (lev==0) + when 5 + puts "#{@sp*5}" if (lev <= 5) + puts "#{@sp*4}" if (lev <= 4) + puts "#{@sp*3}" if (lev <= 3) and hs[3] + puts "#{@sp*2}" if (lev <= 2) and hs[2] + puts "#{@sp*1}" if (lev <= 1) and hs[1] + puts "" if (lev==0) + when 6 + puts "#{@sp*6}" if (lev <= 6) + puts "#{@sp*5}" if (lev <= 5) + puts "#{@sp*4}" if (lev <= 4) + puts "#{@sp*3}" if (lev <= 3) and hs[3] + puts "#{@sp*2}" if (lev <= 2) and hs[2] + puts "#{@sp*1}" if (lev <= 1) and hs[1] + puts "" if (lev==0) + end + end + end +end +__END__ diff --git a/lib/sisu/v5/ao_endnotes.rb b/lib/sisu/v5/ao_endnotes.rb new file mode 100644 index 00000000..981c97f6 --- /dev/null +++ b/lib/sisu/v5/ao_endnotes.rb @@ -0,0 +1,128 @@ +# encoding: utf-8 +=begin + + * Name: SiSU + + * Description: a framework for document structuring, publishing and search + + * 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. + + * 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 . + + If you have Internet connection, the latest version of the GPL should be + available at these locations: + + + + + + * SiSU uses: + * Standard SiSU markup syntax, + * Standard SiSU meta-markup syntax, and the + * Standard SiSU object citation numbering and system + + * Hompages: + + + + * Download: + + + * Git + + + + * Ralph Amissah + + + + ** Description: system environment, resource control and configuration details + +=end +module SiSU_AO_Endnotes + class Endnotes + def initialize(md,data,endnote_array=nil) + @md,@data,@endnote_array=md,data,endnote_array + @endnote_counter,@endnote_counter_asterisk,@endnote_counter_dag=1,1,1 + end + def endnotes + data=@data + @tuned_file=[] + endnote_ref=1 + data.each do |dob| + # manually numbered endnotes --> + if @md.opt.mod.inspect =~/--no-asterisk|--no-annotate/ + dob.obj=dob.obj.gsub(/#{Mx[:en_b_o]}\s.+?#{Mx[:en_b_c]}/,'') + end + if @md.opt.mod.inspect =~/--no-dagger|--no-annotate/ + dob.obj=dob.obj.gsub(/#{Mx[:en_b_o]}[+]\s.+?#{Mx[:en_b_c]}/,'') + end + if (defined? dob.obj) \ + && (defined? dob.is) \ + && dob.is !=:code + case dob.obj # auto-numbered endnotes --> + when /#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}[*+]\s+.+?#{Mx[:en_b_c]}/ + dob.obj=dob.obj.gsub(/\s*(#{Mx[:en_a_c]}|#{Mx[:en_b_c]})/,'\1') + word_mode=dob.obj.scan(/\S+/m) + word_mode=endnote_call_number(word_mode) + dob.obj=word_mode.join(' ') + endnote_ref+=1 + when /~\^(?:\s|$)|<:e>/ #%note inserts endnotes previously gathered from /^(|[-~]\{{3})/ (in earlier loop) + word_mode=dob.obj.scan(/\S+/m) + word_mode=endnote_call_number(word_mode) + dob.obj=word_mode.join(' ') + endnote_ref+=1 + end + end + @tuned_file << dob + end + @endnote_counter,@endnote_counter_asterisk,@endnote_counter_dag=1,1,1 + @tuned_file=@tuned_file.flatten + end + def endnote_call_number(words) + words.each do |word| + case word + when /#{Mx[:en_a_o]}/ + unless word =~/#{Mx[:en_a_o]}[*+]+/ + word.gsub!(/#{Mx[:en_a_o]}/,"#{Mx[:en_a_o]}#{@endnote_counter} ") + @endnote_counter+=1 + end + when /#{Mx[:en_b_o]}/ + if word =~/#{Mx[:en_b_o]}[+]/ + word.gsub!(/#{Mx[:en_b_o]}[+]/,"#{Mx[:en_b_o]}\+#{@endnote_counter_dag} ") + @endnote_counter_dag+=1 + else + word.gsub!(/#{Mx[:en_b_o]}[*]?/,"#{Mx[:en_b_o]}\*#{@endnote_counter_asterisk} ") + @endnote_counter_asterisk+=1 + end + when /~\^|<:e>/ + if @endnote_array + word.gsub!(/~\^|<:e>/,"#{@endnote_array[@endnote_counter-1]}") + @endnote_counter+=1 + end + end + end + end + end +end +__END__ diff --git a/lib/sisu/v5/ao_expand_insertions.rb b/lib/sisu/v5/ao_expand_insertions.rb new file mode 100644 index 00000000..44ae1f60 --- /dev/null +++ b/lib/sisu/v5/ao_expand_insertions.rb @@ -0,0 +1,450 @@ +# encoding: utf-8 +=begin + + * Name: SiSU + + * Description: a framework for document structuring, publishing and search + + * 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. + + * 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 . + + If you have Internet connection, the latest version of the GPL should be + available at these locations: + + + + + + * SiSU uses: + * Standard SiSU markup syntax, + * Standard SiSU meta-markup syntax, and the + * Standard SiSU object citation numbering and system + + * Hompages: + + + + * Download: + + + * Git + + + + * Ralph Amissah + + + + ** Description: system environment, resource control and configuration details + +=end +module SiSU_AO_Insertions + class Insertions + def initialize(md,data) + @md,@data=md,data + end + def output_filetypes_in_cmd(cmd_shortcut,lnk=nil) #make list of file types in shortcut command (as configured), e.g. when sisu -3 is used + cf_defaults=SiSU_Env::InfoProcessingFlag.new + cmd_list=case cmd_shortcut.inspect + when /0/; cf_defaults.cf_0 + when /1/; cf_defaults.cf_1 + when /2/; cf_defaults.cf_2 + when /3/; cf_defaults.cf_3 + when /4/; cf_defaults.cf_4 + when /5/; cf_defaults.cf_5 + end + file_type_names={} + file_type_names[:gen],file_type_names[:src]=[],[] + file_type_names[:gen] <<= if cmd_list =~ /y/ then "~^ { document manifest }#{lnk[:manifest]}" + end + file_type_names[:gen] <<= if cmd_list =~ /h/ then [" { html, segmented text }#{lnk[:html_toc]}"," { html, scroll, document in one }#{lnk[:html_doc]}"] + end + file_type_names[:gen] <<= if cmd_list =~ /e/ then [" { epub }#{lnk[:epub]}"] + end + file_type_names[:gen] <<= if cmd_list =~ /p/ then [" { pdf, landscape }#{lnk[:pdf_landscape]}"," { pdf, portrait }#{lnk[:pdf_portrait]}"] + end + file_type_names[:gen] <<= if cmd_list =~ /o/ then " { odf:odt, open document text }#{lnk[:odt]}" + end + file_type_names[:gen] <<= if cmd_list =~ /b/ then " { xhtml scroll }#{lnk[:xhtml]}" + end + file_type_names[:gen] <<= if cmd_list =~ /x/ then " { xml, sax }#{lnk[:xml_sax]}" + end + file_type_names[:gen] <<= if cmd_list =~ /X/ then " { xml, dom }#{lnk[:xml_dom]}" + end + file_type_names[:gen] <<= if cmd_list =~ /a/ then " { plain text utf-8 }#{lnk[:txt]}" + end + file_type_names[:gen] <<= if cmd_list =~ /g/ then 'wiki.txt' + end + file_type_names[:gen] <<= if cmd_list =~ /w/ then " { concordance }#{lnk[:html_concordance]}" + end + file_type_names[:gen] <<= if cmd_list =~ /N/ then " { dcc, document content certificate (digests) }#{lnk[:digest]}" + end + file_type_names[:src] <<= if source and cmd_shortcut =~ /s/ then " { markup source text }#{lnk[:source]}" + end + file_type_names[:src] <<= if cmd_shortcut =~ /S/ then " { markup source (zipped) pod }#{lnk[:sisupod]}" + end + file_type_names[:gen]=file_type_names[:gen].flatten + file_type_names[:src]=file_type_names[:src].flatten + file_type_names + end + def by_language(linked_doc,lng,src=nil) + @linked_doc,@lng,@src=linked_doc,lng,src + @base_path="#{@md.file.output_path.base.url}/#{lng}" + def fnh + { + fn: @linked_doc, + } + end + def path_and_file(fn,pth) + "#{@base_path}/#{pth}/#{fn}" + end + def manifest + fn=@md.file.base_filename.manifest(fnh) + path_and_file(fn,'manifest') + end + def html_toc + fn=@md.file.base_filename.html_segtoc(fnh) + "#{@base_path}/html/#{@linked_doc}/#{fn}" + end + def html_doc + fn=@md.file.base_filename.html_scroll(fnh) + path_and_file(fn,'html') + end + def html_concordance + fn=@md.file.base_filename.html_concordance + "#{@base_path}/html/#{@linked_doc}/#{fn}" + end + def epub + fn=@md.file.base_filename.epub(fnh) + path_and_file(fn,'epub') + end + def pdf_landscape + fn=@md.file.base_filename.pdf_l_a4(fnh) + path_and_file(fn,'pdf') + end + def pdf_portrait + fn=@md.file.base_filename.pdf_p_a4(fnh) + path_and_file(fn,'pdf') + end + def odt + fn=@md.file.base_filename.odt(fnh) + path_and_file(fn,'odt') + end + def xhtml + fn=@md.file.base_filename.xhtml(fnh) + path_and_file(fn,'xhtml') + end + def xml_sax + fn=@md.file.base_filename.xml_sax(fnh) + path_and_file(fn,'xml_sax') + end + def xml_dom + fn=@md.file.base_filename.xml_dom(fnh) + path_and_file(fn,'xml_dom') + end + def txt + fn=@md.file.base_filename.txt(fnh) + path_and_file(fn,'txt') + end + def digest + fn=@md.file.base_filename.hash_digest(fnh) + path_and_file(fn,'digest') + end + def source + "#{@base_path}/src/#{@src}" + end + def sisupod + "#{@base_path}/src/#{@src}.zip" + end + self + end + def by_filetype(linked_doc,lng,src=nil) + @linked_doc,@lng,@src=linked_doc,lng,src + @lc=SiSU_Env::FilenameLanguageCodeInsert.new(@md.opt,lng).language_code_insert + @base_path="#{@md.file.output_path.base.url}" + def fnh + { + fn: @linked_doc, + lng: @lc, + } + end + def path_and_file(fn,pth) + "#{@base_path}/#{pth}/#{fn}" + end + def manifest + fn=@md.file.base_filename.manifest(fnh) + path_and_file(fn,'manifest') + end + def html_toc + fn=@md.file.base_filename.html_segtoc(fnh) + path_and_file(fn,'html') + end + def html_doc + fn=@md.file.base_filename.html_scroll(fnh) + path_and_file(fn,'html') + end + def html_concordance + fn=@md.file.base_filename.html_concordance + path_and_file(fn,'html') + end + def epub + fn=@md.file.base_filename.epub(fnh) + path_and_file(fn,'epub') + end + def pdf_landscape + fn=@md.file.base_filename.pdf_l_a4(fnh) + path_and_file(fn,'pdf') + end + def pdf_portrait + fn=@md.file.base_filename.pdf_p_a4(fnh) + path_and_file(fn,'pdf') + end + def odt + fn=@md.file.base_filename.odt(fnh) + path_and_file(fn,'odt') + end + def xhtml + fn=@md.file.base_filename.xhtml(fnh) + path_and_file(fn,'xhtml') + end + def xml_sax + fn=@md.file.base_filename.xml_sax(fnh) + path_and_file(fn,'xml_sax') + end + def xml_dom + fn=@md.file.base_filename.xml_dom(fnh) + path_and_file(fn,'xml_dom') + end + def txt + fn=@md.file.base_filename.txt(fnh) + path_and_file(fn,'txt') + end + def digest + fn=@md.file.base_filename.hash_digest(fnh) + path_and_file(fn,'digest') + end + def source + "#{@base_path}/src/#{@src}" + end + def sisupod + "#{@base_path}/src/#{@src}.zip" + end + self + end + def by_filename(linked_doc,lng,src=nil) + @linked_doc,@lng,@src=linked_doc,lng,src + @lc=SiSU_Env::FilenameLanguageCodeInsert.new(@md.opt,lng).language_code_insert + @base_path="#{@md.file.output_path.base.url}/#{@linked_doc}" + def fnh + { + fn: @linked_doc, + lng: @lc, + } + end + def path_and_file(fn,pth=nil) + (pth.nil?) \ + ? "#{@base_path}/#{fn}" + : "#{@base_path}/#{pth}/#{fn}" + end + def manifest + fn=@md.file.base_filename.manifest(fnh) + path_and_file(fn) + end + def html_toc + fn=@md.file.base_filename.html_segtoc(fnh) + path_and_file(fn) + end + def html_doc + fn=@md.file.base_filename.html_scroll(fnh) + path_and_file(fn) + end + def html_concordance + fn=@md.file.base_filename.html_concordance + path_and_file(fn) + end + def epub + fn=@md.file.base_filename.epub(fnh) + path_and_file(fn,'epub') + end + def pdf_landscape + fn=@md.file.base_filename.pdf_l_a4(fnh) + path_and_file(fn) + end + def pdf_portrait + fn=@md.file.base_filename.pdf_p_a4(fnh) + path_and_file(fn) + end + def odt + fn=@md.file.base_filename.odt(fnh) + path_and_file(fn) + end + def xhtml + fn=@md.file.base_filename.xhtml(fnh) + path_and_file(fn) + end + def xml_sax + fn=@md.file.base_filename.xml_sax(fnh) + path_and_file(fn) + end + def xml_dom + fn=@md.file.base_filename.xml_dom(fnh) + path_and_file(fn) + end + def txt + fn=@md.file.base_filename.txt(fnh) + path_and_file(fn) + end + def digest + fn=@md.file.base_filename.hash_digest(fnh) + path_and_file(fn) + end + def source + "#{@base_path}/#{@src}" + end + def sisupod + "#{@base_path}/#{@src}.zip" + end + self + end + def expand_insertions? + data=@data + tuned_file,tuned_file_tmp=[],[] + codeblock_=false + data.each do |para| + codeblock_=if para =~/^(?:code\{|[`]{3}\s+code)/ + true + elsif para =~/^(?:\}code|[`]{3}(?:\s|$))/m + false + else codeblock_ + end + if para !~/^%+\s/ \ + and not codeblock_ \ + and para =~/\{(?:~\^\s+)?(.+?)\s\[(?:\d(?:[sS]*))\]\}(?:\.\.\/\S+?\/|\S+?\.ss[tm]\b)/ + manifest=nil + @u=SiSU_Env::InfoEnv.new.url + m_cmd='' + if defined? @u.remote + if /(?.+?)\{(?.+?)\s\[(?\d[sS]*)\]\}(?(?\S+?)\.ss[tm]\b)(?.*)/m =~ para + m_pre=m_pre.strip + elsif /\{(?.+?)\s\[(?\d[sS]*)\]\}(?(?\S+?)\.ss[tm]\b)(?.*)/m =~ para + end + if m_linked_doc =~ /(\S+?)\/(\S+)/ + m_linked_doc,m_linked_doc_lang=$1,$2 + else + m_linked_doc,m_linked_doc_lang=m_linked_doc,@md.opt.lng_base + end + else + puts "error, does currently support relative paths (reltive paths were removed, as had problems for citation, and was not suited to all output types should possibly reconsider) #{__FILE__} #{__LINE__}" + if /\{(?:~\^\s+)?(?.+?)\s\[(?\d[sS]*)\]\}\.\.\/(?\S+?)\/(?\s+#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]})?/ =~ para + end + end + lnk=case @md.opt.dir_structure_by + when :language + { + manifest: by_language(m_linked_doc,m_linked_doc_lang).manifest, + html_toc: by_language(m_linked_doc,m_linked_doc_lang).html_toc, + html_doc: by_language(m_linked_doc,m_linked_doc_lang).html_doc, + epub: by_language(m_linked_doc,m_linked_doc_lang).epub, + pdf_landscape: by_language(m_linked_doc,m_linked_doc_lang).pdf_landscape, + pdf_portrait: by_language(m_linked_doc,m_linked_doc_lang).pdf_landscape, + odt: by_language(m_linked_doc,m_linked_doc_lang).odt, + xhtml: by_language(m_linked_doc,m_linked_doc_lang).xhtml, + xml_sax: by_language(m_linked_doc,m_linked_doc_lang).xml_sax, + xml_dom: by_language(m_linked_doc,m_linked_doc_lang).xml_dom, + txt: by_language(m_linked_doc,m_linked_doc_lang).txt, + html_concordance: by_language(m_linked_doc,m_linked_doc_lang).html_concordance, + digest: by_language(m_linked_doc,m_linked_doc_lang).digest, + sisupod: by_language(m_linked_doc,m_linked_doc_lang,m_source).sisupod, + source: by_language(m_linked_doc,m_linked_doc_lang,m_source).source, + } + when :filetype + { + manifest: by_filetype(m_linked_doc,m_linked_doc_lang).manifest, + html_toc: by_filetype(m_linked_doc,m_linked_doc_lang).html_toc, + html_doc: by_filetype(m_linked_doc,m_linked_doc_lang).html_doc, + epub: by_filetype(m_linked_doc,m_linked_doc_lang).epub, + pdf_landscape: by_filetype(m_linked_doc,m_linked_doc_lang).pdf_landscape, + pdf_portrait: by_filetype(m_linked_doc,m_linked_doc_lang).pdf_landscape, + odt: by_filetype(m_linked_doc,m_linked_doc_lang).odt, + xhtml: by_filetype(m_linked_doc,m_linked_doc_lang).xhtml, + xml_sax: by_filetype(m_linked_doc,m_linked_doc_lang).xml_sax, + xml_dom: by_filetype(m_linked_doc,m_linked_doc_lang).xml_dom, + txt: by_filetype(m_linked_doc,m_linked_doc_lang).txt, + html_concordance: by_filetype(m_linked_doc,m_linked_doc_lang).html_concordance, + digest: by_filetype(m_linked_doc,m_linked_doc_lang).digest, + sisupod: by_filetype(m_linked_doc,m_linked_doc_lang,m_source).sisupod, + source: by_filetype(m_linked_doc,m_linked_doc_lang,m_source).source, + } + else + { + manifest: by_filename(m_linked_doc,m_linked_doc_lang).manifest, + html_toc: by_filename(m_linked_doc,m_linked_doc_lang).html_toc, + html_doc: by_filename(m_linked_doc,m_linked_doc_lang).html_doc, + epub: by_filename(m_linked_doc,m_linked_doc_lang).epub, + pdf_landscape: by_filename(m_linked_doc,m_linked_doc_lang).pdf_landscape, + pdf_portrait: by_filename(m_linked_doc,m_linked_doc_lang).pdf_landscape, + odt: by_filename(m_linked_doc,m_linked_doc_lang).odt, + xhtml: by_filename(m_linked_doc,m_linked_doc_lang).xhtml, + xml_sax: by_filename(m_linked_doc,m_linked_doc_lang).xml_sax, + xml_dom: by_filename(m_linked_doc,m_linked_doc_lang).xml_dom, + txt: by_filename(m_linked_doc,m_linked_doc_lang).txt, + html_concordance: by_filename(m_linked_doc,m_linked_doc_lang).html_concordance, + digest: by_filename(m_linked_doc,m_linked_doc_lang).digest, + sisupod: by_filename(m_linked_doc,m_linked_doc_lang,m_source).sisupod, + source: by_filename(m_linked_doc,m_linked_doc_lang,m_source).source, + } + end + linked_title="#{m_pre}{#{m_txt} }#{lnk[:manifest]}#{m_note}\n\n" + tuned_file_tmp << linked_title + output_filetypes=output_filetypes_in_cmd(m_cmd,lnk) + output_filetypes[:gen].each do |o_f| + describe = o_f + if describe + tuned_file_tmp << if @u.remote #to double space <:br> at beginning of entry + "#{Mx[:nbsp]*4} #{describe} " + else # remove ... + "[provide document placement host location]" + end + end + end + output_filetypes[:src].each do |o_f| + describe = o_f + if describe + tuned_file_tmp << if @u.remote + "#{Mx[:nbsp]*4} #{describe} " + else + "[provide document placement host location]" + end + end + end + tuned_file << 'group{' << tuned_file_tmp.join("\n") << '}group' + tuned_file_tmp=[] + else tuned_file << para + end + end + tuned_file + end + end +end +__END__ diff --git a/lib/sisu/v5/ao_hash_digest.rb b/lib/sisu/v5/ao_hash_digest.rb new file mode 100644 index 00000000..70deee80 --- /dev/null +++ b/lib/sisu/v5/ao_hash_digest.rb @@ -0,0 +1,157 @@ +# encoding: utf-8 +=begin + + * Name: SiSU + + * Description: a framework for document structuring, publishing and search + + * 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. + + * 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 . + + If you have Internet connection, the latest version of the GPL should be + available at these locations: + + + + + + * SiSU uses: + * Standard SiSU markup syntax, + * Standard SiSU meta-markup syntax, and the + * Standard SiSU object citation numbering and system + + * Hompages: + + + + * Download: + + + * Git + + + + * Ralph Amissah + + + + ** Description: system environment, resource control and configuration details + +=end +module SiSU_AO_Hash + require_relative 'shared_markup_alt.rb' #shared_markup_alt.rb + class ObjectDigest + def initialize(md,data,env=nil) + @md,@data,@env=md,data,env + @env ||=SiSU_Env::InfoEnv.new(@md.fns) + end + def object_digest + # 1. clean/stripped text without any markup, paragraph, headings etc. without endnotes + # 2. endnotes clean/stripped text digest only (there may be several endnotes within a paragraph) + # 3. whole object, text with markup and any endnotes, (question: with or without the endnote digests??? presumption better without, [however may be easier to check with?]) + # [digests should not include other digests] + data=@data.compact + @tuned_file=[] + sha_ =(@env.digest.type=='sha256' ? true : false) + sha_ ? (require 'digest/sha2') : (require 'digest/md5') + data.each do |t_o| + unless t_o.obj.is_a?(Array) + t_o.obj=t_o.obj.strip + end + if (t_o.of !=:structure \ + && t_o.of !=:comment \ + && t_o.of !=:layout) \ + && t_o.ocn.is_a?(Fixnum) + if sha_ + for hash_class in [ Digest::SHA256 ] + @tuned_file << stamped(t_o,hash_class) + end + else + for hash_class in [ Digest::MD5 ] + @tuned_file << stamped(t_o,hash_class) + end + end + else @tuned_file << t_o unless t_o.nil? + end + end + @tuned_file=@tuned_file.flatten + #use md5 or to create hash of each dal object including ocn, & add into to each dal object + end + def endnote_digest(data) + t_o_bit=[] + data.each do |en_plus| + t_o_bit <<= case en_plus + when /#{Mx[:en_a_o]}|#{Mx[:en_b_o]}/ + if en_plus =~/#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]}/ + t_o_txt,en_open,en_txt,en_close=/(.*?)(#{Mx[:en_a_o]}|#{Mx[:en_b_o]})(.+?)(#{Mx[:en_a_c]}|#{Mx[:en_b_c]})/m.match(en_plus)[1..4] + stripped_en=SiSU_TextRepresentation::Alter.new(en_txt).strip_clean_of_markup + digest_en_strip=if @env.digest.type =~/sha256/ + Digest::SHA256.hexdigest(stripped_en) + else + Digest::MD5.hexdigest(stripped_en) + end + t_o_txt + en_open + en_txt + Mx[:id_o] + digest_en_strip + Mx[:id_c] + en_close + else STDERR.puts "Error Exception - problem encountered with:\n#{en_plus}" #arbitrary exception, tidy up + end + else en_plus + end + end + t_o_bit.join + end + def stamped(t_o,hash_class) #decide what hash information is most useful, is compromise necessary? + t_o.obj=SiSU_TextRepresentation::Alter.new(t_o).strip_clean_of_extra_spaces + #SiSU_TextRepresentation::Alter.new(t_o).strip_clean_of_markup #check + #SiSU_TextRepresentation::Alter.new(t_o).semi_revert_markup #check + #SiSU_TextRepresentation::ModifiedTextPlusHashDigest.new(@md,t_o).composite.dgst #check + unless t_o.is==:code + case t_o.obj + when /#{Mx[:en_a_o]}[\d*+]+\s+.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}[*+]\d+\s+.+?#{Mx[:en_b_c]}/m + en_and_t_o_digest=[] + t_o.obj=t_o.obj.gsub(/\s*(#{Mx[:en_a_c]}|#{Mx[:en_b_c]})/m,' \1') #watch + t_o_plus_en=t_o.obj.scan(/.*?#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|.*?#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]}/m) + t_o_tail=if t_o.obj =~/(?:.*?#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|.*?#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]})+([\s\S]+)/m + /(?:.*?#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|.*?#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]})+.*/m.match(t_o.obj)[1] + else '' + end + t_o_plus_en << t_o_tail + en_and_t_o_digest << endnote_digest(t_o_plus_en) + en_and_t_o_digest.join(' ') + else #@tuned << t_o + Mx[:id_o] + digest_strip + ':' + digest_all + Mx[:id_c] unless t_o.nil? + end + else #@tuned << t_o + Mx[:id_o] + digest_strip + ':' + digest_all + Mx[:id_c] unless t_o.nil? + end + t_o #KEEP intact + end + def strip_clean_extra_spaces(s) # dal output tuned + s=s.dup + s=s.gsub(/[ ]+([,.;:?](?:$|\s))/,'\1') unless s =~/#{Mx[:en_a_o]}|#{Mx[:en_b_o]}/ + s=s.gsub(/ [ ]+/,' '). + gsub(/^ [ ]+/,''). + gsub(/ [ ]+$/,''). + gsub(/((?:#{Mx[:fa_bold_c]}|#{Mx[:fa_italics_c]})')[ ]+(s )/,'\1\2'). + gsub(/((?:#{Mx[:fa_bold_c]}|#{Mx[:fa_italics_c]})')[ ]+(s )/,'\1\2') + end + end +end +__END__ diff --git a/lib/sisu/v5/ao_idx.rb b/lib/sisu/v5/ao_idx.rb new file mode 100644 index 00000000..94e3aff6 --- /dev/null +++ b/lib/sisu/v5/ao_idx.rb @@ -0,0 +1,326 @@ +# encoding: utf-8 +=begin + + * Name: SiSU + + * Description: a framework for document structuring, publishing and search + + * 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. + + * 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 . + + If you have Internet connection, the latest version of the GPL should be + available at these locations: + + + + + + * SiSU uses: + * Standard SiSU markup syntax, + * Standard SiSU meta-markup syntax, and the + * Standard SiSU object citation numbering and system + + * Hompages: + + + + * Download: + + + * Git + + + + * Ralph Amissah + + + + ** Description: system environment, resource control and configuration details + +=end +module SiSU_AO_BookIndex + class BookIndex + def initialize(md,data,env=nil) + @md,@data,@env=md,data,env + @rgx_idx=/#{Mx[:idx_o]}(?:.+?)#{Mx[:idx_c]}\s*/ + @rgx_idx_ocn_seg=/(.+?)~(\d+)~(\S+)/ + @rgx_idx_ocn=/(.+?)~(\d+)/ + @env ||=SiSU_Env::InfoEnv.new(@md.fns) + end + def indexing_song + data=@data + data,sisu_markup_idx_rel,sisu_markup_idx_rel_html_seg,html_idx,xhtml_idx=extract_book_index(data) + data=clean_and_insert_index(data,sisu_markup_idx_rel_html_seg) + [data,sisu_markup_idx_rel,sisu_markup_idx_rel_html_seg,html_idx,xhtml_idx] + end + def extract_book_index(data) + tuned_file=[] + idx_array=[] + data.each do |dob| + if (dob.is ==:heading \ + || dob.is ==:heading_insert) \ + && dob.ln==4 + @seg=dob.name + end + if defined? dob.idx \ + and dob.idx.is_a?(Hash) + idx_array << {idx: dob.idx, ocn: dob.ocn, seg: @seg } + end + tuned_file << dob if dob + end + if idx_array.length > 0 + the_idx=construct_book_index(idx_array) + sisu_markup_idx_rel,sisu_markup_idx_rel_html_seg,html_idx,xhtml_idx=nil,nil,nil,nil + if @md.book_idx + idx=index(the_idx) + sisu_markup_idx_rel,sisu_markup_idx_rel_html_seg,html_idx,xhtml_idx=idx[:sst_rel],idx[:sst_rel_html_seg],idx[:html],idx[:xhtml] + end + end + [tuned_file,sisu_markup_idx_rel,sisu_markup_idx_rel_html_seg,html_idx,xhtml_idx] + end + def construct_book_index(idx_array) + the_idx={} + idx_array.each do |idx| + idx[:idx].each_pair do |term,term_info| + location=(term_info[:plus].to_i > 0) \ + ? (%{#{idx[:ocn]}-#{idx[:ocn].to_i + term_info[:plus].to_i}}) + : idx[:ocn].to_s + the_idx[term]={} unless the_idx[term] and defined? the_idx[term] + the_idx[term]['node_0_terms']=[] unless the_idx[term]['node_0_terms'] and defined? the_idx[term]['node_0_terms'] + the_idx[term]['node_0_terms'] << { ocn: idx[:ocn], range: location, seg: idx[:seg] } + if term_info[:sub].is_a?(Array) \ + and term_info[:sub].length > 0 + term_info[:sub].each do |y| + y.each_pair do |subterm,subterm_info| + location=(subterm_info[:plus].to_i > 0) \ + ? (%{#{idx[:ocn]}-#{idx[:ocn].to_i + subterm_info[:plus].to_i}}) + : idx[:ocn].to_s + the_idx[term]={} unless the_idx[term] and defined? the_idx[term] + the_idx[term]['node_0_terms']=[] unless the_idx[term]['node_0_terms'] and defined? the_idx[term]['node_0_terms'] + the_idx[term]['node_1_subterms']={} unless the_idx[term]['node_1_subterms'] and defined? the_idx[term]['node_1_subterms'] + the_idx[term]['node_1_subterms'][subterm]=[] unless the_idx[term]['node_1_subterms'][subterm] and defined? the_idx[term]['node_1_subterms'][subterm] + the_idx[term]['node_1_subterms'][subterm] << { ocn: idx[:ocn], range: location, seg: idx[:seg] } + end + end + end + end + end + the_idx=the_idx.sort + the_idx + end + def clean_xml(str) + str=str.gsub(/&/,'&') + str + end + def index(the_idx) + @x=1 + idx={} + idx[:sst_rel_html_seg],idx[:sst_rel],idx[:html],idx[:xhtml]=[],[],[],[] + h={obj: Mx[:br_page]} + 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"} + o=SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h) + idx[:sst_rel_html_seg] << o + idx[:sst_rel] << o + h={lv: '4', name: 'idx', obj: " [Index] #{Mx[:pa_non_object_dummy_heading]}"} + o=SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h) + idx[:sst_rel_html_seg] << o + idx[:sst_rel] << o + alph=%W[9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z] + idx[:html] << '

' + idx[:xhtml] << '

' + alph.each do |x| + if x =~/[0-9]/ + idx[:html] << '' + idx[:xhtml] << '' + else + idx[:html] << %{#{x},#{$ep[:hsp]}} + idx[:xhtml] << %{#{x},#{$ep[:hsp]}} + end + end + idx[:html] << '

' + idx[:xhtml] << '

' + letter=alph.shift + idx[:html] << %{\n

} + idx[:xhtml] << %{\n

0 - 9

} + the_idx.each do |i| + i.each do |x| + if x.is_a?(String) + f=/^(\S)/.match(x)[1] + if letter < f + while letter < f + if alph.length > 0 + letter=alph.shift + idx[:html] << %{\n

#{letter}

} + idx[:xhtml] << %{\n

#{letter}

} + else break + end + end + end + idx[:sst_rel_html_seg] << %{\n\n#{Mx[:fa_bold_o]}#{x},#{Mx[:fa_bold_c]} } + idx[:sst_rel] << %{\n\n#{Mx[:fa_bold_o]}#{x},#{Mx[:fa_bold_c]} } + aname=x.gsub(/\s+/,'_') + idx[:html] << %{\n

#{x}, } + c=clean_xml(x.dup) + idx[:xhtml] << %{\n

#{c}, } + @o=idx[:sst_rel_html_seg].index(idx[:sst_rel_html_seg].last) + @t=idx[:sst_rel].index(idx[:sst_rel].last) + @q=idx[:html].index(idx[:html].last) + @r=idx[:xhtml].index(idx[:xhtml].last) + print "\n" + x + ', ' if @md.opt.act[:verbose_plus][:set]==:on + elsif x.is_a?(Array) + p 'array error? -->' + print x + elsif x.is_a?(Hash) + if x['node_0_terms'].is_a?(Array) + x['node_0_terms'].each do |a| + if a[:range] + idx[:sst_rel_html_seg][@o]=idx[:sst_rel_html_seg][@o] + %{#{Mx[:lnk_o]}#{a[:range]}#{Mx[:lnk_c]}#{Mx[:rel_o]}/#{a[:seg]}.html##{a[:ocn]}#{Mx[:rel_c]}, } + idx[:sst_rel][@t]=idx[:sst_rel][@t] + %{#{Mx[:lnk_o]}#{a[:range]}#{Mx[:lnk_c]}#{Mx[:rel_o]}#{a[:ocn]}#{Mx[:rel_c]}, } + idx[:html][@q]=idx[:html][@q] + %{#{a[:range]}, } + idx[:xhtml][@q]=idx[:xhtml][@q] + %{#{a[:range]}, } + print a[:range] + ', ' if @md.opt.act[:verbose_plus][:set]==:on + elsif a[:ocn] + idx[:sst_rel_html_seg][@o]=idx[:sst_rel_html_seg][@o] + %{#{Mx[:lnk_o]}#{a[:ocn]}#{Mx[:lnk_c]}#{Mx[:rel_o]}#{a[:seg]}.html##{a[:ocn]}#{Mx[:rel_c]}, } + idx[:sst_rel][@t]=idx[:sst_rel][@t] + %{#{Mx[:lnk_o]}#{a[:ocn]}#{Mx[:lnk_c]}#{Mx[:rel_o]}#{a[:ocn]}#{Mx[:rel_c]}, } + idx[:html][@q]=idx[:html][@q] + %{#{a[:ocn]}, } + idx[:xhtml][@q]=idx[:xhtml][@q] + %{#{a[:ocn]}, } + print a[:ocn] + ', ' if @md.opt.act[:verbose_plus][:set]==:on + else p 'error' + end + end + idx[:html][@q]=idx[:html][@q] + '

' + idx[:xhtml][@r]=idx[:xhtml][@r] + '

' + end + if x['node_1_subterms'] + x['node_1_subterms'].sort.each do |k,y| + if k !~/node_0_terms/ + idx[:sst_rel_html_seg][@o]=idx[:sst_rel_html_seg][@o] + %{#{k}, } + idx[:sst_rel][@t]=idx[:sst_rel][@t] + %{#{k}, } + idx[:html][@q]=idx[:html][@q] + %{\n

#{k}, } + c=clean_xml(k.dup) + idx[:xhtml][@r]=idx[:xhtml][@r] + %{\n

#{c}, } + print "\n\t" + k + ', ' if @md.opt.act[:verbose_plus][:set]==:on + y.each do |z| + if z[:range] + idx[:sst_rel_html_seg][@o]=idx[:sst_rel_html_seg][@o] + %{#{Mx[:lnk_o]}#{z[:range]}#{Mx[:lnk_c]}#{Mx[:rel_o]}#{z[:seg]}.html##{z[:ocn]}#{Mx[:rel_c]}, } + idx[:sst_rel][@t]=idx[:sst_rel][@t] + %{#{Mx[:lnk_o]}#{z[:range]}#{Mx[:lnk_c]}#{Mx[:rel_o]}#{z[:ocn]}#{Mx[:rel_c]}, } + idx[:html][@q]=idx[:html][@q] + %{#{z[:range]}, } + idx[:xhtml][@q]=idx[:xhtml][@q] + %{#{z[:range]}, } + print z[:range] + ', ' if @md.opt.act[:verbose_plus][:set]==:on + elsif z[:ocn] + idx[:sst_rel_html_seg][@o]=idx[:sst_rel_html_seg][@o] + %{#{Mx[:lnk_o]}#{z[:ocn]}#{Mx[:lnk_c]}#{Mx[:rel_o]}#{z[:seg]}.html##{z[:ocn]}#{Mx[:rel_c]}, } + idx[:sst_rel][@t]=idx[:sst_rel][@t] + %{#{Mx[:lnk_o]}#{z[:ocn]}#{Mx[:lnk_c]}#{Mx[:rel_o]}#{z[:ocn]}#{Mx[:rel_c]}, } + idx[:html][@q]=idx[:html][@q] + %{#{z[:ocn]}, } + idx[:xhtml][@q]=idx[:xhtml][@q] + %{#{z[:ocn]}, } + print z[:ocn] + ', ' if @md.opt.act[:verbose_plus][:set]==:on + else p 'error' + end + end + idx[:html][@q]=idx[:html][@q] + '

' + idx[:xhtml][@r]=idx[:xhtml][@r] + '

' + end + end + end + @x +=1 + end + end + end + print "\n" if @md.opt.act[:verbose_plus][:set]==:on + idx + end + def screen_print(the_idx) + the_idx.each do |i| + i.each do |x| + if x.is_a?(String) + print "\n" + x + ', ' + elsif x.is_a?(Array) + p 'array error? -->' + print x + elsif x.is_a?(Hash) + if x['node_0_terms'].is_a?(Array) + x['node_0_terms'].each do |a| + if a[:range] + print a[:range] + ', ' + elsif a[:ocn] + print a[:ocn] + ', ' + else p 'error' + end + end + end + if x['node_1_subterms'] + x['node_1_subterms'].sort.each do |k,y| + if k !~/node_0_terms/ + print "\n\t" + k + ', ' + y.each do |z| + if z[:range] + print z[:range] + ', ' + elsif z[:ocn] + print z[:ocn] + ', ' + else p 'error' + end + end + end + end + end + end + end + end + end + def output_idx(idx) + if @md.book_idx + path="#{@env.path.output}/#{@md.fnb}" + Dir.mkdir(path) unless FileTest.directory?(path) + puts "#{path}/#{@md.fn[:book_idx_html]} #{__FILE__}::#{__LINE__}" + html_index_file=File.new("#{path}/#{@md.fn[:book_idx_html]}",'w') + idx[:html].each {|x| html_index_file << x } + html_index_file.close + end + end + def clean_and_insert_index(data,sisu_markup_idx) + tuned_file=[] + data.each do |dob| + tuned_file << dob + if dob.obj =~/#{Mx[:br_endnotes]}/ \ + and sisu_markup_idx + sisu_markup_idx.each do |idx| + tuned_file << idx + end + end + end + tuned_file + end + def clean_index(data) #check on use of dob + tuned_file=[] + data.each do |para| + para=para.gsub(/\n*#{@rgx_idx}/m,'') + tuned_file << para + end + tuned_file + end + end +end +__END__ diff --git a/lib/sisu/v5/ao_images.rb b/lib/sisu/v5/ao_images.rb new file mode 100644 index 00000000..4354dfa9 --- /dev/null +++ b/lib/sisu/v5/ao_images.rb @@ -0,0 +1,165 @@ +# encoding: utf-8 +=begin + + * Name: SiSU + + * Description: a framework for document structuring, publishing and search + + * 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. + + * 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 . + + If you have Internet connection, the latest version of the GPL should be + available at these locations: + + + + + + * SiSU uses: + * Standard SiSU markup syntax, + * Standard SiSU meta-markup syntax, and the + * Standard SiSU object citation numbering and system + + * Hompages: + + + + * Download: + + + * Git + + + + * Ralph Amissah + + + + ** Description: system environment, resource control and configuration details + +=end +module SiSU_AO_Images + class Images + #require 'RMagick' + #include Magick + def initialize(md,data) + @md,@data=md,data + end + def images + data=@data + tuned_file=[] + @rmgk=false + imagemagick_=true #imagemagick_=SiSU_Env::InfoSettings.new.program?('rmagick') + if imagemagick_ + begin + @rmgk=SiSU_Env::Load.new('RMagick').prog + rescue + @rmgk=false + end + else + if (@md.opt.act[:verbose][:set]==:on \ + || @md.opt.act[:verbose_plus][:set]==:on \ + || @md.opt.act[:maintenance][:set]==:on) + SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set],'*WARN* use of RMagick is not enabled in sisurc.yml').warn + end + end + data.each do |dob| + unless dob.is ==:table + dob.obj=dob.obj.strip + if dob.obj =~/#{Mx[:lnk_o]}\s*\S+\.(?:png|jpg|gif)(?:\s*|\s+.+)?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|image)/ + if dob.obj !~/#{Mx[:lnk_o]}\s*\S+\.(?:png|jpg|gif)\s+\d+x\d+/ + m=/#{Mx[:lnk_o]}\s*(\S+\.(?:png|jpg|gif))/ + if imagemagick_ + imgs=dob.obj.scan(m).flatten + img_col=img_row=nil + images=imgs.each do |image| + dir=SiSU_Env::InfoEnv.new(@md.fns) + path_image=[dir.path.image_source_include_local,dir.path.image_source_include_remote,dir.path.image_source_include] + image_path=nil + path_image.each do |img_pth| + image_path=img_pth + break if FileTest.exist?("#{img_pth}/#{image}") + end + if FileTest.exist?("#{image_path}/#{image}") + if @rmgk + img=Magick::ImageList.new("#{image_path}/#{image}") + img_col,img_row=img.columns,img.rows + else + if (@md.opt.act[:verbose][:set]==:on \ + || @md.opt.act[:verbose_plus][:set]==:on \ + || @md.opt.act[:maintenance][:set]==:on) + SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set],'*WARN* RMagick not present, will attempt to use imagemagick (identify) directly').warn + end + imgk=SiSU_Env::SystemCall.new.imagemagick + gmgk=SiSU_Env::SystemCall.new.graphicksmagick + if imgk or gmgk + if imgk + imgsys=`identify #{image_path}/#{image}`.strip #system call + elsif gmgk + imgsys=`gm identify #{image_path}/#{image}`.strip #system call + end + img_col,img_row=/(\d+)x(\d+)/m.match(imgsys)[1,2] + img_col,img_row=img_col.to_i,img_row.to_i + end + end + row=((img && defined? img.rows) ? img.rows : img_row) + col=((img && defined? img.columns) ? img.columns : img_col) + if img_col > img_row #landscape + if img_col> 640 + img_col=640 + img_row=((1.00*img_col/col)*row).round + end + else #portrait + if img_col> 640 + img_col=640 + img_row=((1.00*img_col/col)*row).round + end + if img_row > 640 + img_row=640 + img_col=((1.00*img_row/row)*col).round + end + end + dob.obj=dob.obj.gsub(/(#{image})/,"#{image} #{img_col}x#{img_row}") + else dob.obj=dob.obj.gsub(/#{Mx[:lnk_o]}\s*(\S+)\.(png|jpg|gif).+?#{Mx[:lnk_c]}(#{Mx[:url_o]}\S+?#{Mx[:url_c]}|image)/,'[ \1 (\2 missing) ]') + end + end + else + images=dob.obj.scan(m) do |image| + SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set],'*WARN* where image dimensions have not been provided RMagick or imagemagick is required',image).warn unless @md.opt.act[:quiet][:set]==:on + end + end + end + end + if dob.obj =~/#{Mx[:lnk_o]}\s*\S+\.(?:png|jpg|gif).+?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|image)/ + dob.obj=dob.obj.gsub(/(#{Mx[:lnk_o]})\s*(\S+\.(?:png|jpg|gif))\s+/i,'\1\2 ') + end + end + tuned_file << dob unless dob.nil? + end + tuned_file + end + end +end +__END__ +imgsys=`identify #{image_path}/#{image}`.strip diff --git a/lib/sisu/v5/ao_metadata.rb b/lib/sisu/v5/ao_metadata.rb new file mode 100644 index 00000000..8d017769 --- /dev/null +++ b/lib/sisu/v5/ao_metadata.rb @@ -0,0 +1,82 @@ +# encoding: utf-8 +=begin + + * Name: SiSU + + * Description: a framework for document structuring, publishing and search + + * 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. + + * 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 . + + If you have Internet connection, the latest version of the GPL should be + available at these locations: + + + + + + * SiSU uses: + * Standard SiSU markup syntax, + * Standard SiSU meta-markup syntax, and the + * Standard SiSU object citation numbering and system + + * Hompages: + + + + * Download: + + + * Git + + + + * Ralph Amissah + + + + ** Description: system environment, resource control and configuration details + +=end +module SiSU_AO_Metadata + class Metadata + def initialize(md,metad) + @md,@metadata=md,metad + l=SiSU_Env::StandardiseLanguage.new(@md.opt.lng).language + language=l[:n] + @tr=SiSU_Translate::Source.new(md,language) + end + def make_para(obj,ocn) + h={ obj: obj, ocn: 0 } + SiSU_AO_DocumentStructure::ObjectPara.new.paragraph(h) + end + def make_heading(obj,ocn,name,lv,ln) + h={ lv: lv, ln: ln, name: name, obj: obj, ocn: 0 } + SiSU_AO_DocumentStructure::ObjectHeading.new.heading(h) + end + def metadata + end + end +end +__END__ diff --git a/lib/sisu/v5/ao_misc_arrange.rb b/lib/sisu/v5/ao_misc_arrange.rb new file mode 100644 index 00000000..8f7acbc4 --- /dev/null +++ b/lib/sisu/v5/ao_misc_arrange.rb @@ -0,0 +1,157 @@ +# encoding: utf-8 +=begin + + * Name: SiSU + + * Description: a framework for document structuring, publishing and search + + * 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. + + * 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 . + + If you have Internet connection, the latest version of the GPL should be + available at these locations: + + + + + + * SiSU uses: + * Standard SiSU markup syntax, + * Standard SiSU meta-markup syntax, and the + * Standard SiSU object citation numbering and system + + * Hompages: + + + + * Download: + + + * Git + + + + * Ralph Amissah + + + + ** Description: system environment, resource control and configuration details + +=end +module SiSU_AO_MiscArrangeText + class SI + def initialize(md,data) + @md,@data=md,data + 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 + 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") + end + para + end + def code_blocks(para) + def ticks(para) + block_open,block_close,text=nil,nil,nil + if para =~/\A[`]{3}\s+.+?\n.+?\n[`]{3}(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*\Z/m + block_open,text,block_close=/\A([`]{3}\s+.+?)\n(.+?)\n([`]{3}(\s+[~-][#]|\s+\~\{.+?\}\~)?)\s*\Z/m.match(para)[1..3] + ((para=~/^[`]{3}\s+table(?:~h)?\s+/) \ + and (para !~/^[`]{3}\s+table(?:~h)?\s+c\d+/)) \ + ? para + : (para=[]; para << block_open << text << block_close) + elsif para =~/\A[`]{3}\s+.+?\n.*?\Z/m #look at, study + block_open,text=/\A([`]{3}(?:\s+.+?))\n(.*?)\Z/m.match(para)[1,2] + para=[] + if not text.to_s.empty? + para << block_open << text + else + para << block_open + end + elsif para =~/\A.+?\n[`]{3}(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*\Z/m + text,block_close=/\A(.+?)\n([`]{3}(?:\s+[~-][#]|\s+\~\{.+?\}\~)?)\s*\Z/m.match(para)[1,2] + para=[] + if not text.to_s.empty? + para << text.to_s << block_close + else + para << block_close + end + else para + end + para + end + def curly_braces(para) + block_open,block_close,text=nil,nil,nil + para=if para =~/\A(?:code|poem|alt|group|block|table)\{ .+?\n.+?\n\}(?:code|poem|alt|group|block|table)(?: [~-][#])?\s*\Z/m + block_open,text,block_close=/\A((?:code|poem|alt|group|block|table)\{ .+?)\n(.+?)\n(\}(?:code|poem|alt|group|block|table)(?: [~-][#])?)\s*\Z/m.match(para)[1..3] + para=[] + para << block_open << text << block_close + elsif para =~/\A(?:code|poem|alt|group|block|table)\{ .+?\n.+?\Z/m + block_open,text=/\A((?:code|poem|alt|group|block|table)\{ .+?)\n(.+?)\Z/m.match(para)[1,2] + para=[] + if not text.to_s.empty? + para << block_open << text + else + para << block_open + end + elsif para =~/\A.+?\n\}(?:code|poem|alt|group|block|table)(?: [~-][#])?\s*\Z/m + text,block_close=/\A(.+?)\n(\}(?:code|poem|alt|group|block|table)(?: [~-][#])?)\s*\Z/m.match(para)[1,2] + para=[] + if not text.to_s.empty? + para << text.to_s << block_close + else + para << block_close + end + else para + end + para + end + para=para =~/^```/m \ + ? ticks(para) + : para + para=(para =~/^(?:code|poem|alt|group|block|table)\{|^\}(?:code|poem|alt|group|block|table)/m) \ + ? curly_braces(para) + : para + end + def prepare_text + data=@data + data_new=[],[] + if data[0] =~ /^#!\s*(?:\/usr\/bin\/env sisu|\/usr\/bin\/sisu)/ # remove bang from top #! (however file is stripped, so will be removed provided no content precedes it) + data[0]=data[0].gsub(/^#!\s*\/usr\/bin\/sisu/,''). + gsub(/^#!\s*\/usr\/bin\/env sisu/,'') + end + if data[0] =~ /^(SiSU\s+[\d.]*|sisu-[\d.]+)$/ # SiSU identifier + data[0]=data[0].gsub(/^(SiSU\s*[\d.]*)$/,'% \1'). + gsub(/^(sisu-[\d.]+)$/,'% \1') + end + data.each do |para| + para=conditional_headings(para) + data_new << code_blocks(para) + end + data_new=data_new.flatten + end + end +end +__END__ diff --git a/lib/sisu/v5/ao_numbering.rb b/lib/sisu/v5/ao_numbering.rb new file mode 100644 index 00000000..00afdfa5 --- /dev/null +++ b/lib/sisu/v5/ao_numbering.rb @@ -0,0 +1,486 @@ +# encoding: utf-8 +=begin + + * Name: SiSU + + * Description: a framework for document structuring, publishing and search + + * 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. + + * 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 . + + If you have Internet connection, the latest version of the GPL should be + available at these locations: + + + + + + * SiSU uses: + * Standard SiSU markup syntax, + * Standard SiSU meta-markup syntax, and the + * Standard SiSU object citation numbering and system + + * Hompages: + + + + * Download: + + + * Git + + + + * Ralph Amissah + + + + ** Description: system environment, resource control and configuration details + +=end +module SiSU_AO_Numbering + class Numbering + attr_accessor :obj,:osp,:ocn,:lv,:name,:index,:comment + def initialize(md,data) + @md,@data=md,data + @obj=@type=@ocn=@lv=@name=@index=@comment=nil + end + def numbering_song + data=@data + data=number_plaintext_para(data) + data=auto_number_heading_ie_title(data.compact) #tr issue + data=ocn(data.compact) #watch + data=xml(data.compact) + data=minor_numbering(data.compact) + data,tags_map,ocn_html_seg_map=name_para_seg_filename(data) + data=set_heading_top(data) unless @md.set_heading_top + [data,tags_map,ocn_html_seg_map] + end + def number_plaintext_para(data) + @tuned_file=[] + data.each do |dob| + if (dob.of !=:block \ + && dob.of !=:comment \ + && dob.of !=:layout) \ + && dob.ocn_ #and dob.obj !~ /#{Mx[:gr_o]}Th|#{Mx[:tc_o]}#{Mx[:tc_p]}#{Mx[:tc_p]}/ #FIX + dob.obj=dob.obj.gsub(/(.+)\n/,'\1 ') #messy, but idea is that tables should retain breaks + end + unless dob.obj.is_a?(Array) + dob.obj=dob.obj.gsub(/^\s+/,''). + gsub(/\s$/,"\n") + end + @tuned_file << dob + end + @tuned_file=@tuned_file.flatten + end + def number_sub_heading(dob,num,title_no) + unless dob.obj =~/\d+\.|(?:chapter|article|section|clause)\s+\d+/i #name selection arbitrary, fix + dob.obj=case dob.name + when /-/; dob.obj.gsub(/^/,"#{title_no} ") + when /^#/; dob.obj.gsub(/^/,"#{title_no} ") + when /^[a-z_\.]+/; dob.obj.gsub(/^/,"#{title_no} ") + else + dob.name=title_no if dob.name=~/^$/ #where title contains title number + dob.obj.gsub(/^/,"#{title_no} ") if title_no =~/\d+/ #main, where title number is to be provided #watch changed placement + end + if @md.toc_lev_limit \ + and @md.toc_lev_limit < num + dob.obj=dob.obj.gsub(/^/,'!_ ') #bold line, watch + end + end + dob + end + def heading_tag_clean(heading_tag) + heading_tag=heading_tag.gsub(/[ ]+/,'_'). + gsub(/["']/,''). + gsub(/[\/]/,'-'). + gsub(/#{Mx[:fa_bold_o]}|#{Mx[:fa_bold_c]}/,''). + gsub(/#{Mx[:fa_italics_o]}|#{Mx[:fa_italics_c]}/,''). + gsub(/#{Mx[:fa_underscore_o]}|#{Mx[:fa_underscore_c]}/,''). + gsub(/#{Mx[:fa_cite_o]}|#{Mx[:fa_cite_c]}/,''). + gsub(/#{Mx[:fa_insert_o]}|#{Mx[:fa_insert_c]}/,''). + gsub(/#{Mx[:fa_strike_o]}|#{Mx[:fa_strike_c]}/,''). + gsub(/#{Mx[:fa_superscript_o]}|#{Mx[:fa_superscript_c]}/,''). + gsub(/#{Mx[:fa_subscript_o]}|#{Mx[:fa_subscript_c]}/,''). + gsub(/#{Mx[:fa_hilite_o]}|#{Mx[:fa_hilite_c]}/,''). + gsub(/#{Mx[:gl_bullet]}/,'') + end + def auto_number_heading_ie_title(data) #also does some segment naming + @tuned_file=[] + if defined? @md.make.num_top \ + and @md.make.num_top \ + and @md.make.num_top !~/^$/ + input||=@md.make.num_top + end + num_top=(input ? input.to_i : nil) + t_no1=t_no2=t_no3=0 + if num_top + no1=num_top; no2=(num_top + 1); no3=(num_top + 2) + end + chapter_number_counter=0 + data=data.compact + data.each do |dob| #@md.seg_names << [additions to segment names] + title_no=nil + dob=SiSU_AO_DocumentStructureExtract::Structure.new(@md,dob).structure_markup #must happen earlier, node info etc. require + if dob.is ==:heading \ + && dob.autonum_ \ + and defined? @md.make.num_top \ + and @md.make.num_top !~/^$/ + if dob.lv=='1' \ + and dob.obj =~/^#\s|\s#(?:\s|$)/ + chapter_number_counter +=1 + dob.obj=dob.obj.gsub(/^#\s/,"#{chapter_number_counter} "). + gsub(/#([:,]?\s|[.]?$)/,"#{chapter_number_counter}\\1") + end + if dob.ln==no1 + @subnumber=1 + @subnumber=0 if dob.ln==no1 + end + if dob.ln.to_s =~/^[1-6]/ \ + and not dob.toc_ \ + and dob.obj !~/#{Mx[:fa_o]}(?:~#|-#)#{Mx[:fa_c]}/ # <-- fix + if dob.ln==no1 + t_no1+=1; t_no2=0; t_no3=0 + title_no="#{t_no1}" + if @md.seg_names.is_a?(Array) \ + and not @md.seg_names.include?(title_no) + if dob.ln==no1 + dob.name="#{title_no}" if not dob.name + dob.tags=[title_no,dob.tags].flatten if title_no !~/^\d+$/ #check whether will work across file types with stop signs + tag=dob.obj.gsub(/(Article|Clause|Section|Chapter)\s+/,"\\1_#{title_no}").downcase + tag=heading_tag_clean(tag) + dob.tags=[tag,dob.tags].flatten if tag !~/^\d+$/ #check whether will work across file types with stop signs + dob.obj=(dob.obj =~/(Article|Clause|Section)\s+/) \ + ? (dob.obj.gsub(/(Article|Clause|Section)\s+/,"\\1 #{title_no} ")) + : (dob.obj.gsub(/^/,"#{title_no}. ")) #fix stop later + end + if dob.ln !=no1 \ + and dob.obj =~/^[\d.]+\s/ #fix -> if the title starts with a numbering scheme, do not auto-number, review + dob.name ="#{title_no}" if not dob.name + dob.tags=[title_no,dob.tags].flatten if title_no !~/^\d+$/ #check whether will work across file types with stop signs + dob.obj=dob.obj.gsub(/^/,"#{title_no}. ") + end + @md.seg_names << title_no + end + if dob.ln!=no1 \ + and dob.name!~/^[a-z_\.]+$/ \ + and dob.obj !~/[A-Z]\.?\s/ #bug -> tmp fix, excludes A. B. C. lettering, but not roman numerals, is arbitrary, review required # not fixed, work on + dob.tags=[title_no,dob.tags].flatten if title_no !~/^\d+$/ #check whether will work across file types with stop signs + dob.obj=dob.obj.gsub(/^/i,"#{title_no}. ") + end + end + if dob.ln==no1 #watch because here you change dob.name + dob.tags=["h#{title_no}",dob.tags].flatten #check whether will work across file types with stop signs + end + if dob.ln==no2 #watch because here you change dob.name + t_no2+=1; t_no3=0 + title_no="#{t_no1}.#{t_no2}" + dob.tags=["h#{title_no}",dob.tags].flatten #check whether will work across file types with stop signs + dob=number_sub_heading(dob,no2,title_no) + end + if dob.ln==no3 #watch because here you change dob.name + t_no3+=1 + title_no="#{t_no1}.#{t_no2}.#{t_no3}" + 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]/ \ + 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') + end + elsif dob.is ==:heading \ + and dob.autonum_ \ + 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.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 + end + if @md.toc_lev_limit + end + elsif defined? dob.name \ + and dob.name + dob.tags=[dob.name,dob.tags].flatten if dob.name !~/^\d+$/ #check whether will work across file types with stop signs + end + dob.tags=dob.tags.uniq if defined? dob.tags + @tuned_file << dob + end + @tuned_file=@tuned_file.flatten + end + def ocn(data) #and auto segment numbering increment + @tuned_file=SiSU_AO_DocumentStructureExtract::OCN.new(@md,data).ocn + @tuned_file + end + def xml(data) + @tuned_file=SiSU_AO_DocumentStructureExtract::XML.new(@md,data).dom + @tuned_file + end + def minor_numbering(data) #and auto segment numbering increment + @tuned_file=[] + number_small,letter_small=0,0 + letter=%w( a b c d e f g h i j k l m n o p q r s t u v w x y z ) + data.each do |dob| + if dob.of ==:heading \ + || dob.of ==:heading_insert \ + || 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) + number_small,letter_small=0,0 + elsif dob.is ==:para + if dob.obj =~/^#[ 1]/ \ + and dob.obj !~/^#\s+(?:~#)?$/ + letter_small=0 + number_small=0 if dob.obj =~ /^#1/ + number_small+=1 + dob.obj=dob.obj.gsub(/^#[ 1]/,"#{number_small}. ") + end + if dob.obj =~/^_# / + dob.obj=dob.obj.gsub(/^_# /,"#{letter[letter_small]}. ") + dob.indent='1' + letter_small+=1 + end + end + end + @tuned_file << dob + end + @tuned_file=@tuned_file.flatten + end + def name_para_seg_filename(data) #segment naming, remaining + # paragraph name/numbering rules + # manual naming overrides, manual naming may be + # alpha-numeric characters mixed, + # numeric only (a number), if + # all segments have been named, + # the numbers used are over 1000 or + # it is not minded that auto-numbering uses a funny scheme for naming segments (not yet implemented) + # [for now a warning is printed for such documents on use of maintenance or very-verbose flag] + # auto-naming takes the form of giving numbers to segments + # the rules for which are as follows + # if the title/heading text starts with a numeric, then that is used (1 3.1 3rd etc.) + # otherwise the level 4 segment number from the embedded document structure info is used + # if there is none a sequential number is designated, preceded by an underscore + @tuned_file,@unique_auto_name=[],[] + tags={} + art_filename_auto=1 + @counter=1 + if not @md.seg_autoname_safe \ + and (@md.opt.act[:verbose_plus][:set]==:on \ + || @md.opt.act[:maintenance][:set]==:on) + puts 'manual segment names, numbers used as names, risk warning (segmented html)' + end + ocn_html_seg=[] + data.each do |dob| + if dob.is==:heading \ + && dob.ln \ + and dob.ln.to_s =~/^[456]/ + if dob.ln==4 \ + and not dob.name \ + and not @md.set_heading_seg + @md.set_heading_seg=true + end + if dob.name !~/^\S+/ \ + and dob.obj =~/^\s*(?:\S+\s+)?([\d.,:-]+)/m #heading starts with a recognised numeric or word followed by a recognised numerical construct, use that as name + possible_seg_name=$1 + possible_seg_name=possible_seg_name.gsub(/(?:[:,-]|\W)/,'.'). + gsub(/\.$/,'') + if @md.seg_names.is_a?(Array) \ + and not @md.seg_names.include?(possible_seg_name) + dob.name=possible_seg_name + dob.tags=[dob.name,dob.tags].flatten if dob.name !~/^\d+$/ + @md.seg_names << possible_seg_name + elsif (@md.opt.act[:verbose_plus][:set]==:on \ + or @md.opt.act[:maintenance][:set]==:on) + puts 'warn, there may be a conflicting numbering scheme' + end + end + if dob.ln==4 \ + and dob.name #extract segment name from embedded document structure info + if @md.seg_names.is_a?(Array) \ + and not @md.seg_names.include?(dob.name) + dob.tags=[dob.name,dob.tags].flatten if dob.name !~/^\d+$/ + @md.seg_names << dob.name + end + end + if dob.ln==4 \ + and not dob.name #if still no segment name, provide a numerical one + pf='_' #pg='' #may use e.g. '' or '~' or '_' + segn_auto="#{pf}#{art_filename_auto.to_s}" + if @md.seg_names.is_a?(Array) \ + and not @md.seg_names.include?(segn_auto) + dob.name=segn_auto + dob.tags=[dob.name,dob.tags].flatten if dob.name !~/^\d+$/ #check whether will work across file types with stop signs + @md.seg_names << segn_auto + else puts 'segment name (numbering) error' + end + art_filename_auto+=1 + end + if dob.ln==4 \ + and not dob.name #should not occur + puts "e r r o r -\t#{__FILE__}::#{__LINE__}\n#{dob.inspect}" + end + end + if (dob.is ==:heading \ + || dob.is ==:heading_insert) \ + && dob.ln==4 + @seg=dob.name + end + @tuned_file << if dob.is==:heading \ + && (@md.pagenew || @md.pagebreak || @md.pageline) + m=dob.ln.to_s + dob_tmp=[] + if @md.pagenew.inspect =~/#{m}/ + dob_tmp << SiSU_AO_DocumentStructure::ObjectLayout.new.break(Hx[:br_page_new]) << dob + elsif @md.pagebreak.inspect =~/#{m}/ + dob_tmp << SiSU_AO_DocumentStructure::ObjectLayout.new.break(Hx[:br_page]) << dob + elsif @md.pageline.inspect =~/#{m}/ + dob_tmp << SiSU_AO_DocumentStructure::ObjectLayout.new.break(Hx[:br_page_line]) << dob + end + unless dob_tmp.length > 0; dob + else dob_tmp + end + else dob + end + if defined? dob.ocn \ + and dob.ocn + @segname=((dob.is==:heading || dob.is==:heading_insert) && dob.ln==4 && (defined? dob.name)) \ + ? (dob.name) + : @segname + tags["#{dob.ocn}"]={ segname: @segname } + ocn_html_seg[dob.ocn]=if (dob.is==:heading || dob.is==:heading_insert) + if dob.ln =~/[1-3]/ + { seg: nil, level: dob.ln } + else #elsif dob.ln =~/[4-6]/ + { seg: @seg, level: dob.ln } + end + else + { seg: @seg, level: nil } + end + end + dob.tags=dob.tags.uniq if defined? dob.tags + if defined? dob.tags \ + and dob.tags.length > 0 + #@segname=((dob.is=='heading'|| dob.is=='heading_insert') && dob.ln==4 && (defined? dob.name)) \ + #? (dob.name) \ + #: @segname + dob.tags.each do |y| + tags[y]={ ocn: dob.ocn.to_s, segname: @segname } + end + end + dob + end + ocn_html_seg.each_with_index do |ocn,i| + if ocn \ + and ocn[:level].to_s=~/[1-3]/ + (1..4).each do |x| + if ocn_html_seg[i+x] and ocn_html_seg[i+x][:level]==4 + ocn[:seg]=ocn_html_seg[i+x][:seg] + end + end + end + end + if @md.seg_names.length > 0 + @md.set_heading_seg=true + end + tuned_file=@tuned_file.flatten + [tuned_file,tags,ocn_html_seg] + end + def set_heading_top(data) #% make sure no false positives + unless @md.set_heading_top + if (@md.opt.act[:verbose_plus][:set]==:on \ + or @md.opt.act[:maintenance][:set]==:on) + puts "\tdocument contains no top level heading, (will have to manufacture one)" + end + @tuned_file=[] + data.each do |t_o| + unless @md.set_heading_top + if t_o !~/^(?:#{Rx[:meta]}|@\S+:)\s/m \ + and t_o !~/\A\s*\Z/m + @md.set_heading_top=true + if defined? @md.title \ + and @md.title \ + and defined? @md.title.full \ + and defined? @md.creator \ + and @md.creator + head=@md.title.main ? ([@lv='1',@obj=@md.title.main]) : ([@lv='1',@obj='[no title provided]']) + @tuned_file << head + end + end + end + @tuned_file << t_o + end + @tuned_file=@tuned_file.flatten + end + end + def set_heading_seg(data) #% make sure no false positives + unless @md.set_heading_seg + if (@md.opt.act[:verbose_plus][:set]==:on \ + or @md.opt.act[:maintenance][:set]==:on) + puts "\tdocument contains no segment level, (will have to manufacture one)" + end + @tuned_file=[] + data.each do |dob| + unless @md.set_heading_seg + if defined? dob.ln and dob.ln.to_s !~/^[123]/m \ + and dob.obj !~/\A\s*\Z/m \ + and dob.is !=:layout + @md.set_heading_seg=true + head=@md.title.main \ + ? (dob.ln,dob.name,dob.obj=4,'seg',@md.title.main) + : (dob.ln,dob.name,dob.obj=4,'seg','[segment]') + @tuned_file << head + end + end + @tuned_file << dob + end + @tuned_file=@tuned_file.flatten + end + end + def set_header_title(data) #% make sure no false positives + unless @md.set_header_title + if (@md.opt.act[:verbose_plus][:set]==:on \ + or @md.opt.act[:maintenance][:set]==:on) + puts "\t no document title provided, (will have to manufacture one)" + end + @tuned_file=[] + data.each do |t_o| + unless @md.set_header_title + if t_o !~/^%{1,2}\s/m \ + and t_o !~/\A\s*\Z/m + @tuned_file << "#{Mx[:meta_o]}title#{Mx[:meta_c]} #{@md.heading_seg_first}" + @md.title.main=@md.heading_seg_first + @md.set_header_title=true + end + end + @tuned_file << t_o + end + @tuned_file=@tuned_file.flatten + end + end + end +end +__END__ diff --git a/lib/sisu/v5/ao_syntax.rb b/lib/sisu/v5/ao_syntax.rb new file mode 100644 index 00000000..22e0124c --- /dev/null +++ b/lib/sisu/v5/ao_syntax.rb @@ -0,0 +1,631 @@ +# encoding: utf-8 +=begin + + * Name: SiSU + + * Description: a framework for document structuring, publishing and search + + * 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. + + * 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 . + + If you have Internet connection, the latest version of the GPL should be + available at these locations: + + + + + + * SiSU uses: + * Standard SiSU markup syntax, + * Standard SiSU meta-markup syntax, and the + * Standard SiSU object citation numbering and system + + * Hompages: + + + + * Download: + + + * Git + + + + * Ralph Amissah + + + + ** Description: Syntax for markup, input markup syntaxes, determined here + +=end +module SiSU_AO_Syntax + class Words + def initialize(line,md,mkp) + @line,@md,@mkp=line,md,mkp + end + end + class Markup + def initialize(md='',data='') + @md,@data=md,data + @vz=SiSU_Viz::Defaults.new + @data_new=[] + url_and_stub=SiSU_Env::InfoEnv.new.url + @output_url="#{url_and_stub.remote}" + @env=SiSU_Env::InfoEnv.new + emph_set=if defined? @md.emphasis_set_to \ + and not @md.emphasis_set_to.nil? + @md.emphasis_set_to + else @env.markup_emphasis + end + @emph=case emph_set + when /bold/ + emph_italics=false + { o: Mx[:fa_bold_o], c: Mx[:fa_bold_c] } + when /italics/ + emph_italics=true + { o: Mx[:fa_italics_o], c: Mx[:fa_italics_c] } + when /underscore/ + emph_italics=false + { o: Mx[:fa_underscore_o], c: Mx[:fa_underscore_c] } + else p __LINE__.to_s + '::' + __FILE__ + end + @http_m=%r{\{.+?\}https?://\S+|https?:\S+|:\S+|\.\.\/\S+|#\S+|\S+?\.png\b|[*]~\S+|^#{Mx[:meta_o]}.+|#{Mx[:gr_o]}(?:code|block|group|alt|verse)(?:-end)?#{Mx[:gr_c]}|#{Mx[:fa_o]}:br#{Mx[:fa_c]}} + @manmkp_ital=emph_italics \ + ? '[i/*]\\{.+?\\}[i/*]' + : '[i/]\\{.+?\\}[i/]' + tail_m_ital=%q{(?:\s|[.,;:?!'")]|~\^|~\\\{\s|$)} + tail_m_bold=%{(?:(?:#{Mx[:fa_italics_c]})?(?:\s|[.,;:?!'")]|~\^|~\\\{\s|$))?} + bold_line=%{^!_\s.+?(?:#{Mx[:br_line]}|\n|$)} + #ital_line=%{^/_\s.+?(?:#{Mx[:br_line]}|\n|$)} #not implemented + @line_scan_ital=if defined? @md.italics_match_list[:str] + /#{@http_m}|#{bold_line}|#{@manmkp_ital}#{tail_m_ital}|#{@md.italics_match_list[:str]}#{tail_m_ital}|\S+|\n/i + elsif defined? @vz.markup_make_italic[:str] + /#{@http_m}|#{bold_line}|#{@manmkp_ital}#{tail_m_ital}|#{@vz.markup_make_italic[:str]}#{tail_m_ital}|\S+|\n/i + end + @manmkp_bold=emph_italics \ + ? '^!_\s.+?(?:\n|$)|[!b]\\{.+?\\}[*!b]|[*!][a-zA-Z0-9\-_]+[!]' + : '^!_\s.+?(?:\n|$)|[*!b]\\{.+?\\}[*!b]|[*!][a-zA-Z0-9\-_]+[*!]' + @line_scan_bold=if (defined? @md.bold_match_list[:str] \ + and @md.bold_match_list[:str]) \ + and (defined? @vz.markup_make_bold[:str] \ + and @vz.markup_make_bold[:str]) + /#{@http_m}|#{bold_line}|(?:#{@manmkp_bold}|#{@md.bold_match_list[:str]}|#{@vz.markup_make_bold[:str]})#{tail_m_bold}|\S+|\n/i + elsif defined? @md.bold_match_list[:str] \ + and @md.bold_match_list[:str] + /#{@http_m}|#{bold_line}|(?:#{@manmkp_bold}|#{@md.bold_match_list[:str]})#{tail_m_bold}|\S+|\n/i + elsif defined? @vz.markup_make_bold[:str] \ + and @vz.markup_make_bold[:str] + /#{@http_m}|#{bold_line}|(?:#{@manmkp_bold}|#{@vz.markup_make_bold[:str]})#{tail_m_bold}|\S+|\n/i + end + end + def songsheet + @data=@data.compact + @data.each do |dob| + dob=breaks(dob) + dob=if @md.sem_tag then sem(dob) else dob end #revisit + dob=line_actions(dob) + dob=paragraph_set(dob) + dob=substitutions(dob) + dob=wordlist_italics(dob) + dob=wordlist_bold(dob) + dob=bodymarkup(dob) + @data_new << dob unless dob.nil? + end + @data_new + end + def sem(dob) #revisit + dob=SiSU_Sem::Tags.new(dob,@md).rm.all + end + def breaks(dob) + if dob.is !=:meta \ + && dob.is !=:comment \ + && dob.is !=:code \ + && dob.is !=:table + dob.obj=dob.obj.gsub(/^-\\\\-\s*$/,"#{Mx[:br_page]}"). + gsub(/^=\\\\=\s*$/,"#{Mx[:br_page_new]}"). + gsub(/ \\\\(?: |$)/,"#{Mx[:br_line]}"). + gsub(/(?:<:?pb>)/,"#{Mx[:br_page]}"). # depreciated + gsub(/(?:<:?pn>)/,"#{Mx[:br_page_new]}"). # depreciated + gsub(/(?:<:?br>|
)/,"#{Mx[:br_line]}"). # depreciated + gsub(/(?:^-\.\.-\s*$)/,"#{Mx[:br_page_line]}") + end + dob + end + def wordlist_italics(dob) + dob=dob.dup + if (defined? @md.italics_match_list[:str] \ + and @md.italics_match_list[:str]) \ + or (defined? @vz.markup_make_italic[:str] \ + and @vz.markup_make_italic[:str]) + dob.obj=if dob.is !=:meta \ + && dob.is !=:heading \ + && dob.is !=:heading_insert \ + && dob.is !=:code \ + && dob.is !=:comment + word=dob.obj.scan(@line_scan_ital) + word=word.flatten.compact + line_array=[] + word.each do |w| + unless /#{@manmkp_ital}|#{@http_m}/.match(w) + if defined? @md.italics_match_list[:regx] \ + and @md.italics_match_list[:regx] + w=w.gsub(@md.italics_match_list[:regx], + "#{Mx[:fa_italics_o]}\\1#{Mx[:fa_italics_c]}") + elsif defined? @vz.markup_make_italic \ + and @vz.markup_make_italic + w=w.gsub(@vz.markup_make_italic, + "#{Mx[:fa_italics_o]}\\1#{Mx[:fa_italics_c]}") + else w + end + end + line_array << w + end + line_array.join(' ') + else dob.obj + end + end + dob + end + def embolden(given) + given=given.gsub(/^!_\s+((?:\{|#{Mx[:lnk_o]})(?:~^ )?.+?(?:\}|#{Mx[:lnk_o]})https?:\/\/\S+.*?)([#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:br_nl]}])/, + "#{Mx[:fa_bold_o]} \\1 #{Mx[:fa_bold_c]}\\2"). + gsub(/^!_\s+((?:\{|#{Mx[:lnk_o]})(?:~^ )?.+?(?:\}|#{Mx[:lnk_o]})https?:\/\/\S+.*)/, + "#{Mx[:fa_bold_o]} \\1 #{Mx[:fa_bold_c]}"). + gsub(/(?:^!_|^#{Mx[:lv_o]}[7-9]:\S*?#{Mx[:lv_c]})\s*(.+?)([#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:br_nl]}])/, + "#{Mx[:fa_bold_o]}\\1#{Mx[:fa_bold_c]}\\2"). + gsub(/(?:^!_|^#{Mx[:lv_o]}[7-9]:\S*?#{Mx[:lv_c]})\s*(.+?)\s+((?:[*]~\S+\s*)+)/, + "#{Mx[:fa_bold_o]}\\1#{Mx[:fa_bold_c]}\\2"). + gsub(/(?:^!_|^#{Mx[:lv_o]}[7-9]:\S*?#{Mx[:lv_c]})\s*(.+?)\s*([~-]#)$/, + "#{Mx[:fa_bold_o]}\\1#{Mx[:fa_bold_c]}\\2"). + gsub(/(?:^!_\s+|^#{Mx[:lv_o]}[7-9]:\S*?#{Mx[:lv_c]}\s*)(.*)?\s*$/, + "#{Mx[:fa_bold_o]}\\1#{Mx[:fa_bold_c]}") + end + def italicise(given) + given=given.gsub(/^\/_\s*(.+?)([#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:br_nl]}])/, + "#{Mx[:fa_italics_o]}\\1#{Mx[:fa_italics_c]}\\2"). + gsub(/^\/_\s*(.+?)\s+((?:[*]~\S+\s*)+)/, + "#{Mx[:fa_italics_o]}\\1#{Mx[:fa_italics_c]}\\2"). + gsub(/^\/_\s*(.+?)\s*([~-]#)$/, + "#{Mx[:fa_italics_o]}\\1#{Mx[:fa_italics_c]}\\2"). + gsub(/^\/_\s+(.*)?\s*$/, + "#{Mx[:fa_italics_o]}\\1#{Mx[:fa_italics_c]}") + end + def line_actions(dob) + dob.obj=if (dob.is !=:heading \ + && dob.is !=:heading_insert \ + && dob.is !=:comment \ + && dob.is !=:meta) \ + and dob.obj =~ /^!_\s+/ + embolden(dob.obj) + elsif dob.obj =~ /^\/_\s+/ + italicise(dob.obj) + else dob.obj + end + dob + end + def paragraph_set(dob) + dob.obj=if dob.is !=:meta \ + && dob.is !=:heading \ + && dob.is !=:heading_insert \ + && dob.is !=:code \ + && dob.is !=:comment \ + && dob.is !=:table + dob.obj.gsub(/\n/m,' '). + gsub(/ \s+/m,' ') + else dob.obj + end + dob + end + def substitutions(dob) + dob=dob.dup + dob=if defined? @md.substitution_match_list[:match_and_replace] \ + and @md.substitution_match_list[:match_and_replace].is_a?(Array) + dob=if dob.is !=:meta \ + && dob.is !=:heading_insert \ + && dob.is !=:code \ + && dob.is !=:comment \ + && dob.is !=:table + if dob.obj =~/#{@md.substitution_match_list[:matches]}/ + @md.substitution_match_list[:match_and_replace].each do |x| + dob.obj=if x[:case_s]==:i + dob.obj.gsub(/#{x[:match]}/mi,x[:replace]) + else + dob.obj.gsub(/#{x[:match]}/m,x[:replace]) + end + end + end + dob + else dob + end + dob + else dob + end + end + def wordlist_bold(dob) + dob=dob.dup + if (defined? @md.bold_match_list[:str] \ + and @md.bold_match_list[:str]) \ + or (defined? @vz.markup_make_bold[:str] \ + and @vz.markup_make_bold[:str]) + dob.obj=if dob.is !=:meta \ + && dob.is !=:heading \ + && dob.is !=:heading_insert \ + && dob.is !=:code \ + && dob.is !=:comment \ + && dob.is !=:table + line_array=[] + word=dob.obj.scan(@line_scan_bold) + word=word.flatten.compact + word.each do |w| + unless /#{@manmkp_bold}|#{@http_m}/.match(w) + if defined? @md.bold_match_list[:regx] \ + and @md.bold_match_list[:regx] #document header: @bold: [bold word list] + w=w.gsub(@md.bold_match_list[:regx],"#{Mx[:fa_bold_o]}\\1#{Mx[:fa_bold_c]}") + elsif defined? @vz.markup_make_bold \ + and @vz.markup_make_bold #defaults adjusted bold word list + w=w.gsub(@vz.markup_make_bold,"#{Mx[:fa_bold_o]}\\1#{Mx[:fa_bold_c]}") + end + else + w=if w =~ /(?:^!_|^#{Mx[:lv_o]}[7-9]:\S*?#{Mx[:lv_c]})\s+/ + embolden(w) #bold paragraph/emphasize #may wish to remove think about 7{ 8{ conversion not satisfactory, as information is lost! + elsif w =~/^\/_\s+/ + italicise(w) + else w + end + end + line_array << w + end + line_array.join(' ') + else dob.obj + end + else + dob.obj=if dob.is==:heading \ + and dob.ln.to_s =~/[7-9]/ + embolden(dob.obj) + else dob.obj + end + end + dob + end + def fontface_lines(dob,leader) + while (dob.obj =~/#{Mx[:br_nl]}/ \ + and dob.obj =~/(?:#{leader})([*!\/_#])\{(.+?)\}\1/m) \ + and $2 =~/#{Mx[:br_nl]}/ + dob=if dob.obj =~/#{Mx[:br_nl]}/ \ + and dob.obj =~/(#{leader})([*!\/_#])\{(.+?)\}\2/m + lead,fce,txt=$1,$2,$3 + dob=if txt =~/#{Mx[:br_nl]}/ + lead_break=if dob.obj =~/^#{Mx[:br_nl]}/ + dob.obj=dob.obj.sub(/^#{Mx[:br_nl]}/,'') + Mx[:br_nl] + else '' + end + txt="#{lead_break}#{fce}\{" + txt.split(Mx[:br_nl]).join("\}#{fce}#{Mx[:br_nl]}#{fce}\{") + "\}#{fce}" + dob.obj=dob.obj.sub(/(?:^|#{Mx[:gl_c]}|\s+|['"]|[#{Mx[:nbsp]}#{Mx[:fa_o_c]}#{Mx[:fa_c]}#{Mx[:lnk_o]}#{Mx[:br_nl]}#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:tc_c]}#{Mx[:tc_p]}]|[\(\[\{]|\>)([*!\/_#])\{.+?\}\1/m,"#{lead}#{txt}") + dob + else dob + end + end + dob + end + dob + end + def fontface(dob) + leader=/^|#{Mx[:gl_c]}|\s+|['"]|[#{Mx[:nbsp]}#{Mx[:fa_o_c]}#{Mx[:fa_c]}#{Mx[:lnk_o]}#{Mx[:br_nl]}#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:tc_c]}#{Mx[:tc_p]}]|[\(\[\{]|[、。]|\>/ + dob=fontface_lines(dob,leader) + dob.obj=dob.obj.gsub(/(#{leader})\*\{(.+?)\}\*/m, + "\\1#{@emph[:o]}\\2#{@emph[:c]}"). #emphasis + gsub(/(#{leader})!\{(.+?)\}!/m, + "\\1#{Mx[:fa_bold_o]}\\2#{Mx[:fa_bold_c]}"). #bold + gsub(/(#{leader})\/\{(.+?)\}\//m, + "\\1#{Mx[:fa_italics_o]}\\2#{Mx[:fa_italics_c]}"). #italics + gsub(/(#{leader})_\{(.+?)\}_/m, + "\\1#{Mx[:fa_underscore_o]}\\2#{Mx[:fa_underscore_c]}"). #underscore + gsub(/(#{leader})#\{(.+?)\}#/m, + "\\1#{Mx[:fa_monospace_o]}\\2#{Mx[:fa_monospace_c]}"). #monospace + gsub(/(^|#{Mx[:gl_c]}|\s+|['"]|[#{Mx[:nbsp]}#{Mx[:fa_o_c]}#{Mx[:fa_c]}]|\(|\>)\"\{(.+?)\}\"/m, + "\\1#{Mx[:fa_cite_o]}\\2#{Mx[:fa_c_o]}cite#{Mx[:fa_c]}"). #cite /blockquote? + gsub(/(^|[^\\])\^\{(.+?)\}\^/m, + "\\1#{Mx[:fa_superscript_o]}\\2#{Mx[:fa_superscript_c]}"). #superscript + gsub(/(^|[^\\]),\{(.+?)\},/m, + "\\1#{Mx[:fa_subscript_o]}\\2#{Mx[:fa_subscript_c]}"). #subscript + gsub(/(^|#{Mx[:gl_c]}|\s+|['"]|#{Mx[:nbsp]}|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)\+\{(.+?)\}\+/m, + "\\1#{Mx[:fa_insert_o]}\\2#{Mx[:fa_insert_c]}"). #inserted text + gsub(/(^|#{Mx[:gl_c]}|\s+|['"]|#{Mx[:nbsp]}|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)-\{(.+?)\}-/m, + "\\1#{Mx[:fa_strike_o]}\\2#{Mx[:fa_strike_c]}"). #strikethrough - deleted text + gsub(/(^|#{Mx[:gl_c]}|\s+|['"]|#{Mx[:nbsp]}|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>|\d+)\^(\S+?)\^/, + "\\1#{Mx[:fa_superscript_o]}\\2#{Mx[:fa_superscript_c]}") #superscript single word, watch digit added + dob + end + def bodymarkup(dob) + # << http://www.jus.uio.no/sisu/sisu_markup_table/markup >> + # See: data/sisu/sample/document_samples_sisu_markup/ + ## fontface + # *{emphasis}* e{emphasis}e emphasis + # !{bold text}! b{bold}b bold text + # _{underline}_ u{underline}u underline + # /{italics}/ i{italics}i italics + # "{citation}" c{citation}c citation #blockquote? + # ^{superscript}^ superscript + # ,{subscript}, subscript + # +{inserted text}+ inserted text + # -{deleted text}- deleted text + # #{monospace text}# + # + # {url address}:url + # {image.png}imageurl + # {image.png}png + # ~{endnote}~ + # !_ #bold/emphasise paragraph + # _" #blockquote paragraph + # _1 <:i1> #indent paragraph 1 step + # _2 <:i2> #indent paragraph 2 steps + # _3 <:i3> #indent paragraph 3 steps + # _4 <:i4> #indent paragraph 4 steps + # _* #bullet (list) ● + # _1* #bullet (list) indented + # _1* #bullet (list) indented + # # #numbered (list) level 1 + # _# #numbered (list) level 2 + dob=dob.dup + if dob.is !=:meta \ + && dob.is !=:comment \ + && dob.is !=:code \ + && dob.is !=:table + line_array=[] + word=dob.obj.scan(/\S+|\n/) #unless line =~/^(?:#{Mx[:meta_o]}|%+\s)/ #visit + if word + word.each do |w| # _ - / # | : ! ^ ~ + unless w =~/~\{|\}~|~\[|\]~|^\^~|~\^|\*~\S+|~#|\{t?~|\{table|https?:\/\/\S+/ # do something earlier about table!! + w=w.gsub(/\\?~/,"#{Mx[:gl_o]}#126#{Mx[:gl_c]}") #escaped special character + end + w=w.gsub(/^\<$/,"#{Mx[:gl_o]}#lt#{Mx[:gl_c]}").gsub(/^\>$/,"#{Mx[:gl_o]}#gt#{Mx[:gl_c]}") #escaped special character + line_array << w + end + dob.obj=line_array.join(' ') + dob.obj=dob.obj.strip + end + dob.obj=dob.obj.gsub(/^([*#-.]{1,12})$/,'\1 ~#'). #ocn off for these paragraph separators + gsub(/~\{(.+?)\}~/m,Mx[:en_a_o] + '\1' + Mx[:en_a_c]). + gsub(/~\[([^*+].+?)\]~/m,Mx[:en_b_o] + '* \1' + Mx[:en_b_c]). #default if markup does not specify + gsub(/~\[(.+?)\]~/m,Mx[:en_b_o] + '\1' + Mx[:en_b_c]) + if dob.is ==:heading \ + and dob.ln ==1 + dob.obj=dob.obj.gsub(/\s*@title\b/," #{@md.title.full}") + dob.obj=if defined? @md.creator.author \ + and @md.creator.author + dob.obj.gsub(/\s+(?:@creator|@author)/,",#{Mx[:br_line]}#{@md.creator.author}") + else dob.obj.gsub(/\s+(?:@creator|@author)/,'') + end + end + if defined? @md.title \ + and @md.title \ + and defined? @md.title.full \ + and defined? @md.creator \ + and @md.creator + if dob.is ==:heading + dob.obj=dob.obj.gsub(/^\s*@title\s*$/,@md.title.full) if dob.lv =~/1/ + dob.obj=if dob.lv =~/[23]/ \ + and defined? @md.creator.author \ + and @md.creator.author + dob.obj.gsub(/^\s*(?:(by\s+)?(?:@creator|@author))\s*$/,"\\1#{@md.creator.author}") + else dob.obj.gsub(/^\s*(?:(by\s+)?(?:@creator|@author))\s*$/,'\1') + end + end + end + dob.obj=dob.obj.gsub(/<(https?:\/\/\S+?)>/,'< \1 >'). #catch problem markup + gsub(/<:=(\S+?)>/,'{ c_\1.png 14x14 }image'). + gsub(//,'<:\1>'). #escaped special character + gsub(/ /,"#{Mx[:nbsp]}"). #escaped special character + gsub(/\\~/,"#{Mx[:gl_o]}#126#{Mx[:gl_c]}"). #escaped special character + gsub(/\\\{/,"#{Mx[:gl_o]}#123#{Mx[:gl_c]}"). #escaped special character + gsub(/\\\}/,"#{Mx[:gl_o]}#125#{Mx[:gl_c]}"). #escaped special character + gsub(/\\\<>/,"#{Mx[:gl_o]}#gt#{Mx[:gl_c]}#{Mx[:gl_o]}#gt#{Mx[:gl_c]}"). #escaped special character + gsub(/\\\/,"#{Mx[:gl_o]}#gt#{Mx[:gl_c]}"). #escaped special character + gsub(/\\\_/,"#{Mx[:gl_o]}#095#{Mx[:gl_c]}"). #escaped special character + gsub(/\\\-/,"#{Mx[:gl_o]}#045#{Mx[:gl_c]}"). #escaped special character + gsub(/\\\+/,"#{Mx[:gl_o]}#043#{Mx[:gl_c]}"). #escaped special character + gsub(/\\\//,"#{Mx[:gl_o]}#047#{Mx[:gl_c]}"). #escaped special character + gsub(/\\\#/,"#{Mx[:gl_o]}#035#{Mx[:gl_c]}"). #escaped special character + gsub(/\\\&/,"#{Mx[:gl_o]}#038#{Mx[:gl_c]}"). #& #escaped special character + gsub(/\\\|/,"#{Mx[:gl_o]}#124#{Mx[:gl_c]}"). #not really a sisu special character but made available as possibility + gsub(/\\\:/,"#{Mx[:gl_o]}#058#{Mx[:gl_c]}"). #not really a sisu special character but made available as possibility + gsub(/\\\!/,"#{Mx[:gl_o]}#033#{Mx[:gl_c]}"). #not really a sisu special character but made available as possibility + gsub(/\\\^/,"#{Mx[:gl_o]}#094#{Mx[:gl_c]}"). #not really a sisu special character but made available as possibility + gsub(/\\\,/,"#{Mx[:gl_o]}#044#{Mx[:gl_c]}"). #not really a sisu special character but made available as possibility + gsub(/\\\\/,"#{Mx[:gl_o]}#092#{Mx[:gl_c]}"). #escaped special character + gsub(/\\\*/,"#{Mx[:gl_o]}#042#{Mx[:gl_c]}"). #escaped special character + gsub(/\\\!/,"#{Mx[:gl_o]}#033#{Mx[:gl_c]}") #escaped special character + if dob.obj=~/(?:https?:|ftp:|\{([^{}]+?)\}(?:#|:|[.]{1,2}\/))\S+/m + if dob.obj=~/(?:^|[#{Mx[:gl_c]}#{Mx[:nbsp]} ])\{~\^ (?:.+?)\s*\}(?:(?:https?:|ftp:|:|[.]{1,2}\/)\S+?)\s*#{Mx[:en_a_o]}(.+?)#{Mx[:en_a_c]}/m + dob.obj=dob.obj.gsub(/(^|[#{Mx[:gl_c]}#{Mx[:nbsp]} ])\{~\^ ([^}]+?)\s*\}((?:https?:|ftp:|:|[.]{1,2}\/)\S+?)\s*#{Mx[:en_a_o]}(.+?)#{Mx[:en_a_c]}/m, + "\\1#{Mx[:lnk_o]}\\2#{Mx[:lnk_c]}\\3 #{Mx[:en_a_o]}\\3 \\4#{Mx[:en_a_c]}") # watch + end + if dob.obj=~/(?:^|[#{Mx[:gl_c]}#{Mx[:nbsp]} ])\{~\^ (?:.+?)\s*\}(?:(?:https?:|ftp:|:|[.]{1,2}\/)\S+?)([;,.]?)(?=\s|[#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:br_nl]}]|$)/m + dob.obj=dob.obj.gsub(/(^|[#{Mx[:gl_c]}#{Mx[:nbsp]} ])\{~\^ (.+?)\s*\}((?:https?:|ftp:|:|[.]{1,2}\/)\S+?)([;,.]?)(?=\s|[#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:br_nl]}]|$)/m, + "\\1#{Mx[:lnk_o]}\\2#{Mx[:lnk_c]}\\3\\4 #{Mx[:en_a_o]}\\3#{Mx[:en_a_c]} ") + end + dob.obj=dob.obj.gsub(/(^|[^#])\{\s*([^{}]+?)\s*\}((?:https?:|:|[.]{2}\/|#)\S+?)(?=\s|[#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:br_nl]}#{Mx[:en_a_o]}#{Mx[:en_b_o]}]|$)/, + "\\1#{Mx[:lnk_o]}\\2#{Mx[:lnk_c]}\\3"). #linked (text or image, however text cannot include modified face, e.g. bold, ital, underline) + gsub(/(^|[#{Mx[:gl_c]}#{Mx[:lnk_c]}#{Mx[:en_a_o]}#{Mx[:en_b_o]}(\s])((?:https?|ftp):\/\/\S+?\.[^>< ]+?)([,.;'"]?)(?=[\s#{Mx[:en_a_c]}#{Mx[:en_b_c]}#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:br_nl]}]|$)/m, + %{\\1#{Mx[:url_o]}\\2#{Mx[:url_c]}\\3}). + gsub(/#{Mx[:lnk_c]}#(\S+?[^>< ]+?)([()\[\]]*[,.;:!?'"]{0,2})(?=[\s#{Mx[:en_a_c]}#{Mx[:en_b_c]}#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:br_nl]}]|$)/m, + %{#{Mx[:lnk_c]}#{Mx[:rel_o]}\\1#{Mx[:rel_c]}\\2}). + gsub(/#{Mx[:lnk_c]}:(\S+?[^>< ]+?)([()\[\]]*[,.;:!?'"]{0,2})(?=[\s#{Mx[:en_a_c]}#{Mx[:en_b_c]}#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:br_nl]}]|$)/m, + %{#{Mx[:lnk_c]}#{Mx[:rel_o]}:\\1#{Mx[:rel_c]}\\2}). + gsub(/#{Mx[:lnk_c]}[.]{2}\/(\S+?[^>< ]+?)([()\[\]]*[,.;:!?'"]{0,2})(?=[\s#{Mx[:en_a_c]}#{Mx[:en_b_c]}#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:br_nl]}]|$)/m, + %{#{Mx[:lnk_c]}#{Mx[:rel_o]}:\\1#{Mx[:rel_c]}\\2}) + end + if dob.obj=~/_(?:https?|ftp):\S+/m # _http://url #CHECK + dob.obj=dob.obj.gsub(/(^|[#{Mx[:gl_c]}#{Mx[:lnk_c]}#{Mx[:en_a_o]}#{Mx[:en_b_o]}(\s])(_(?:https?|ftp):\/\/\S+?\.[^>< ]+?)([,.;'"]?)(?=[\s#{Mx[:en_a_c]}#{Mx[:en_b_c]}#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:br_nl]}]|$)/m, + %{\\1#{Mx[:url_o]}\\2#{Mx[:url_c]}\\3}) + end + dob=fontface(dob) + dob.obj=dob.obj.gsub(/<[:e]\s+(.+?)!?>/, + "#{Mx[:en_a_o]}\\1#{Mx[:en_a_c]}"). #not tested + gsub(/(^|#{Mx[:br_nl]})\s*_\*\s*/, + "\\1#{Mx[:gl_bullet]}"). #bullets, shortcut + gsub(/=\{(.+?)\}/, + "#{Mx[:idx_o]}\\1#{Mx[:idx_c]}"). + gsub(/^\s*_([1-9])\*\s*/, + "#{Mx[:pa_o]}:i\\1:\\1#{Mx[:pa_c]}#{Mx[:gl_bullet]}"). #bullets, shortcut + gsub(/^\s*_([1-9])\s+/, + "#{Mx[:pa_o]}:i\\1:\\1#{Mx[:pa_c]}"). #indent + gsub(/^\s*_([1-9])!\s+(.+?)\s*$/, + "#{Mx[:pa_o]}:i\\1:\\1#{Mx[:pa_c]}#{Mx[:fa_bold_o]}\\2#{Mx[:fa_bold_c]} "). #indent bold + gsub(/^\s*__([1-9])\s+/, + "#{Mx[:pa_o]}:i0:\\1#{Mx[:pa_c]}"). #hang + gsub(/^\s*__([1-9])!\s+(.+?)\s*$/, + "#{Mx[:pa_o]}:i0:\\1#{Mx[:pa_c]}#{Mx[:fa_bold_o]}\\2#{Mx[:fa_bold_c]} "). #hangdef + gsub(/^\s*_([0-9])_([0-9])\s+/, + "#{Mx[:pa_o]}:i\\1:\\2#{Mx[:pa_c]}"). #hang + gsub(/^\s*_([0-9])_([0-9])!\s+(.+?)\s*$/, + "#{Mx[:pa_o]}:i\\1:\\2#{Mx[:pa_c]}#{Mx[:fa_bold_o]}\\3#{Mx[:fa_bold_c]} "). #hangdef + gsub(/<:hi>/,"#{Mx[:fa_hilite_o]}"). #''). # bright yellow rgb(255,255,0) pale yellow rgb(255,255,200) + gsub(/<:\/hi>/,"#{Mx[:fa_hilite_c]}"). #''). + gsub(/(#{Mx[:gr_o]}verse#{Mx[:gr_c]}.+)/m,"\\1\n"). + gsub(/[ ]+($)/,'\1'). + gsub(/\{\s*(.+?)\s*\}(https?:\S+?)([;,.]?)(?=\s|[#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:br_nl]}#{Mx[:en_a_o]}#{Mx[:en_b_o]}]|$)/, + "#{Mx[:lnk_o]}\\1#{Mx[:lnk_c]}#{Mx[:url_o]}\\2#{Mx[:url_c]}\\3"). #any remaining linked text or image + gsub(/\{\s*(.+?)\s*\}(#{Mx[:url_o]}\S+?#{Mx[:url_c]})/, + "#{Mx[:lnk_o]}\\1#{Mx[:lnk_c]}\\2"). #any remaining linked text or image + gsub(/(^|\s)([a-zA-Z0-9._-]+\@\S+?\.[a-zA-Z0-9._-]+)/,"\\1#{Mx[:url_o]}\\2#{Mx[:url_c]}"). + gsub(/(^|[ ])\{\s*(.+?)\s*\}(\S+?)([;,.]?)(?=\s|[#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:br_nl]}#{Mx[:en_a_o]}#{Mx[:en_b_o]}]|$)/, + "\\1#{Mx[:lnk_o]}\\2#{Mx[:lnk_c]}\\3\\4"). #any remaining linked text or image + gsub(/\{\s*(.+?)\s*\}#([a-zA-Z0-9][a-zA-Z0-9_-]*)([;,.]?)(?=\s|[#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:br_nl]}#{Mx[:en_a_o]}#{Mx[:en_b_o]}]|$)/, + "#{Mx[:lnk_o]}\\1#{Mx[:lnk_c]}#{Mx[:rel_o]}\\2#{Mx[:rel_c]}\\3"). #any remaining linked text or image, check need + gsub(/\{\s*(.+?)\s*\}(#{Mx[:rel_o]}\S+?#{Mx[:rel_c]})/, + "#{Mx[:lnk_o]}\\1#{Mx[:lnk_c]}\\2"). #any remaining linked text or image, check need + gsub(/\{\s*(.+?)\s*\}(image)/, + "#{Mx[:lnk_o]}\\1#{Mx[:lnk_c]}\\2") #linked image + elsif dob.is==:table + dob=fontface(dob) + elsif dob.is ==:code + dob.obj=dob.obj.gsub(/#{Mx[:meta_o]}(\S+?)#{Mx[:meta_c]}\s*/,'@\1: '). + gsub(/(^|#{Mx[:gl_c]}|\s)<(br(?: \/)?)>([\s,.]|$)/,'\1<\2>\3') #convert

back, clumsy + if dob.number_ + codeline=[] + ln=1 + dob.obj.split(/#{Mx[:gr_o]}codeline#{Mx[:gr_c]}||\n/).each_with_index do |cl,i| + unless i == 0 + cl=cl.gsub(Mx[:br_nl],'') + w=3-ln.to_s.length + cl = "#{ln}#{Mx[:nbsp]*w}#{Mx[:vline]}#{cl}#{Mx[:br_nl]}" + ln +=1 + end + codeline << cl + end + codeline= codeline.join("") + dob.obj=codeline + else + dob.obj=dob.obj.gsub(/#{Mx[:gr_o]}codeline#{Mx[:gr_c]}/,"\n") + end + dob + else # @\S+?: + end + dob + end + def tech #script markup planned to be more strict for technical documents + # *{emphasis}* e{emphasis}e emphasis + # !{bold text}! b{bold}b bold text + # _{underline}_ u{underline}u underline + # /{italics}/ i{italics}i italics + # "{citation}" c{citation}c citation + # ^{superscript}^ superscript + # ,{subscript}, subscript + # +{inserted text}+ inserted text + # -{deleted text}- deleted text + # #{monospace text}# + # {url address}:url + # {image.png}imageurl + # {image.png}png + # ~{endnote}~ + # +1 + # +2 + puts 'tech' + @data.each do |line| + line=line.gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|[\(\[]|\>)e\{(.+?)\}e/, + "\\1#{@emph[:o]}\\2#{@emph[:c]}"). #emphasis + gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|[\(\[]|\>)b\{(.+?)\}b/, + "\\1#{Mx[:fa_bold_o]}\\2#{Mx[:fa_bold_c]}"). #bold + gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|[\(\[]|\>)u\{(.+?)\}u/, + "\\1#{Mx[:fa_underscore_o]}\\2#{Mx[:fa_underscore_c]}"). #underscore + gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|[\(\[]|\>)c\{(.+?)\}c/, + "\\1#{Mx[:fa_cite_o]}\\2#{Mx[:fa_c_o]}cite#{Mx[:fa_c]}"). #cite + gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|[\(\[]|\>)i\{(.+?)\}i/, + "\\1#{Mx[:fa_italics_o]}\\2#{Mx[:fa_italics_c]}"). #italics + gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|[\(\[]|\>)!\{(.+?)\}!/, + "\\1#{Mx[:fa_bold_o]}\\2#{Mx[:fa_bold_c]}"). #bold + gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|[\(\[]|\>)\*\{(.+?)\}\*/, + "\\1#{@emph[:o]}\\2#{@emph[:c]}"). #emphasis + gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|[\(\[]|\>)_\{(.+?)\}_/, + "\\1#{Mx[:fa_underscore_o]}\\2#{Mx[:fa_underscore_c]}"). #underscore + gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|[\(\[]|\(|\>)\/\{(.+?)\}\//, + "\\1#{Mx[:fa_italics_o]}\\2#{Mx[:fa_italics_c]}"). #italics + gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)\"\{(.+?)\}\"/, + "\\1#{Mx[:fa_cite_o]}\\2#{Mx[:fa_c_o]}cite#{Mx[:fa_c]}"). + gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)\^\{(.+?)\}\^/, + "\\1#{Mx[:fa_superscript_o]}\\2#{Mx[:fa_superscript_c]}"). + gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)9\{(.+?)\}9/, + "\\1#{Mx[:fa_superscript_o]}\\2#{Mx[:fa_superscript_c]}"). + gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>),\{(.+?)\},/, + "\\1#{Mx[:fa_subscript_o]}\\2#{Mx[:fa_subscript_c]}"). + gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)6\{(.+?)\}6/, + "\\1#{Mx[:fa_subscript_o]}\\2#{Mx[:fa_subscript_c]}"). + gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)\+\{(.+?)\}\+/, + "\\1#{Mx[:fa_insert_o]}\\2#{Mx[:fa_insert_c]}"). + gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)v\{(.+?)\}v/, + "\\1#{Mx[:fa_insert_o]}\\2#{Mx[:fa_insert_c]}"). + gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)-\{(.+?)\}-/, + "\\1#{Mx[:fa_strike_o]}\\2#{Mx[:fa_strike_c]}"). + gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)x\{(.+?)\}x/, + "\\1#{Mx[:fa_strike_o]}\\2#{Mx[:fa_strike_c]}"). + gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)\*(\S+?)\*/, + "\\1#{@emph[:o]}\\2#{@emph[:c]}"). #emphasise single word, watch + gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)\!(\S+?)\!/, + "\\1#{Mx[:fa_bold_o]}\\2#{Mx[:fa_bold_c]}"). #bold single word, watch + gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)\/([\(\)a-zA-Z0-9']+?)\/([ ,.;:'"~$]|[^a-zA-Z0-9])/, + "\\1#{Mx[:fa_italics_o]}\\2#{Mx[:fa_italics_c]}\\3"). #italics single word, watch + gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)_(\S+?)_/, + "\\1#{Mx[:fa_underscore_o]}\\2#{Mx[:fa_underscore_c]}"). #underscore single word, watch + gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)\^(\S+?)\^/, + "\\1#{Mx[:fa_superscript_o]}\\2#{Mx[:fa_superscript_c]}"). #check #superscript single word, watch digit added + gsub(/^\s*_\([1-9]\)\(\*\+\)\s*/, + "#{Mx[:pa_o]}:i\\1#{Mx[:pa_c]}#{Mx[:fa_o]}\\2#{Mx[:fa_c_o]}"). #bullets, shortcut + gsub(/^\s*_\([1-9]\)\s+/, + "#{Mx[:pa_o]}:i\\1#{Mx[:pa_c]}"). #watch + gsub(/^\s*__\([1-9]\)\s+/, + "#{Mx[:pa_o]}:h\\1#{Mx[:pa_c]}"). #watch + #line.gsub(/^\s*__\([1-9]\)!\s+/, + # "#{Mx[:pa_o]}:hd\\1#{Mx[:pa_c]}"). #watch + gsub(/#{Mx[:br_line]}\s*_[12]\s+/, + "#{Mx[:br_line]} ") #indent used in endnotes, not implemented, replace when ready with: line.gsub(/(?:
|
)\s*_([12])\s+/,'
<:i\1> ') + end + @data + end + end +end +__END__ diff --git a/lib/sisu/v5/dal.rb b/lib/sisu/v5/dal.rb deleted file mode 100644 index fb8a19ae..00000000 --- a/lib/sisu/v5/dal.rb +++ /dev/null @@ -1,537 +0,0 @@ -# encoding: utf-8 -=begin - - * Name: SiSU - - * Description: a framework for document structuring, publishing and search - - * 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. - - * 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 . - - If you have Internet connection, the latest version of the GPL should be - available at these locations: - - - - - - * SiSU uses: - * Standard SiSU markup syntax, - * Standard SiSU meta-markup syntax, and the - * Standard SiSU object citation numbering and system - - * Hompages: - - - - * Download: - - - * Git - - - - * Ralph Amissah - - - - ** Description: preprocessing, (document abstraction), data abstraction used - in subsequent processing - -=end -module SiSU_DAL - require_relative 'defaults' # defaults.rb - include SiSU_Viz - require_relative 'sysenv' # sysenv.rb - include SiSU_Env - require_relative 'param' # param.rb - include SiSU_Param - require_relative 'dal_doc_objects' # dal_doc_objects.rb - require_relative 'dal_syntax' # dal_syntax.rb - include SiSU_DAL_Syntax - require_relative 'dal_doc_str' # dal_doc_str.rb - require_relative 'dal_idx' # dal_idx.rb - require_relative 'dal_numbering' # dal_numbering.rb - require_relative 'dal_hash_digest' # dal_hash_digest.rb - require_relative 'dal_endnotes' # dal_endnotes.rb - require_relative 'dal_images' # dal_images.rb - require_relative 'dal_metadata' # dal_metadata.rb - require_relative 'dal_character_check' # dal_character_check.rb - require_relative 'dal_misc_arrange' # dal_misc_arrange.rb - require_relative 'dal_expand_insertions' # dal_expand_insertions.rb - require_relative 'prog_text_translation' # prog_text_translation.rb - require_relative 'shared_sem' # shared_sem.rb - class Instantiate < SiSU_Param::Parameters::Instructions - def initialize - @@flag_vocab=0 - @@line_mode='' - end - end - class Source #{cf.meta}").txt_grey - end - end - dal.each {|s| dal_array << s} - if @opt.act[:maintenance][:set]==:on - dal_array.each do |obj| - if defined? obj.parent - if defined? obj.ln - if defined? obj.node - puts %{#{obj.ln}: #{obj.ocn} : #{obj.parent} : #{obj.node} - #{obj.lc}} - else - puts %{#{obj.ln}: #{obj.ocn} : #{obj.parent}} - end - else - if defined? obj.node - puts %{ #{obj.ocn} : #{obj.parent} : #{obj.node} - #{obj.lc}} - else - puts %{ #{obj.ocn} : #{obj.parent}} - end - end - end - end - end - dal_array - end - def read_fnm - dal=[] - dal=(FileTest.file?(@fnm)) \ - ? (File.open(@fnm,'r:utf-8'){ |f| dal=Marshal.load(f)}) - : SiSU_DAL::Source.new(@opt).create_dal - end - def read_fnc - dal=[] - dal=(FileTest.file?(@fnc)) \ - ? (File.open(@fnc,'r:utf-8'){ |f| dal=Marshal.load(f)}) - : SiSU_DAL::Source.new(@opt).create_dal - end - def read_idx_sst - m=[] - m=(FileTest.file?(@idx_sst)) \ - ? (File.open(@idx_sst,'r:utf-8'){ |f| m=Marshal.load(f)}) - : nil - end - def read_idx_raw - m=[] - m=(FileTest.file?(@idx_raw)) \ - ? (File.open(@idx_raw,'r:utf-8'){ |f| m=Marshal.load(f)}) - : nil - end - def read_idx_html - m=[] - m=(FileTest.file?(@idx_html)) \ - ? (File.open(@idx_html,'r:utf-8'){ |f| m=Marshal.load(f)}) - : nil - end - def read_idx_xhtml - m=[] - m=(FileTest.file?(@idx_xhtml)) \ - ? (File.open(@idx_xhtml,'r:utf-8'){ |f| m=Marshal.load(f)}) - : nil - end - def read_map_nametags - m=[] - m=(FileTest.file?(@map_nametags)) \ - ? (File.open(@map_nametags,'r:utf-8'){ |f| m=Marshal.load(f)}) - : nil - end - def read_map_ocn_htmlseg - m=[] - m=(FileTest.file?(@map_ocn_htmlseg)) \ - ? (File.open(@map_ocn_htmlseg,'r:utf-8'){ |f| m=Marshal.load(f)}) - : nil - end - end - class Output - def initialize(fn,md,data) - @fn,@md,@data=fn,md,data - @cf=SiSU_Env::CreateFile.new(@fn) - @make=SiSU_Env::InfoFile.new(@fn) - @dir=SiSU_Env::InfoEnv.new(@fn) - end - def screen_dump(o) - if defined? o.of - print %{OF: #{o.of}; } - end - if defined? o.is - print %{IS: #{o.is.to_s}; } - end - if defined? o.ocn - print %{OCN: #{o.ocn}; } - end - if defined? o.node - print %{NODE: #{o.node}; } - end - if defined? o.parent - print %{Parent: #{o.parent}; } - end - if defined? o.obj and not o.obj.empty? - puts %{\n#{o.obj}; } - else "\n" - end - end - def screen_print(t_o) - if defined? t_o - print ' ' + t_o.to_s - end - end - def screen_output(data) - data.each do |o| - print o.class - screen_print(o.ocn) - screen_print(o.obj) - puts "\n" - end - end - def hard_output - if @md.opt.act[:maintenance][:set]==:on - filename_meta=@cf.metaverse.file_meta - @data.each {|o| filename_meta.puts o.inspect.sub(/:0x[0-9a-f]{8}\s/,': ')} #to make diffing easier - filename_txt=@cf.metaverse.file_txt - @data.each do |o| - if defined? o.ocn - filename_txt.puts case o.is - when :heading - "[#{o.is.to_s} #{o.lv}~#{o.name} [#{o.ocn}]] #{o.obj}" - else "[#{o.is.to_s} [#{o.ocn}]] #{o.obj}" - end - else - filename_txt.puts case o.is - when :meta - "[m~#{o.tag}] #{o.obj}" - else "[#{o.is.to_s}] #{o.obj}" - end - end - end - filename_debug=@cf.file_debug - @data.each do |o| - if defined? o.ocn - case o.is - when :heading - filename_debug.puts "#{o.is.to_s} #{o.lv}~#{o.name} odv=#{o.odv} osp=#{o.osp} [#{o.ocn}] -->\n\t#{o.obj}" - end - end - end - else - hard="#{@dir.processing_path.dal}/#{@md.fns}.meta" - File.unlink(hard) if FileTest.file?(hard) - hard="#{@dir.processing_path.dal}/#{@md.fns}.txt" - File.unlink(hard) if FileTest.file?(hard) - hard="#{@dir.processing_path.dal}/#{@md.fns}.debug.txt" - File.unlink(hard) if FileTest.file?(hard) - end - end - def make_marshal_content - marshal_dal=@make.marshal.dal_content - File.open(marshal_dal,'w'){|f| Marshal.dump(@data,f)} if @data.is_a?(Array) - end - def make_marshal_metadata - marshal_dal=@make.marshal.dal_metadata - File.open(marshal_dal,'w'){|f| Marshal.dump(@data,f)} if @data.is_a?(Array) - end - def idx_html_hard_output - if @md.book_idx \ - and @md.opt.act[:maintenance][:set]==:on - filename_meta=@cf.file_meta_idx_html - if @data.is_a?(Array) - @data.each {|s| p s.inspect + "\n" unless s.is_a?(String)} - @data.each {|s| filename_meta.puts s.strip + "\n" unless s.strip.empty?} - end - else - hard_idx_html="#{@dir.processing_path.dal}/#{@md.fns}.idx.html" - File.unlink(hard_idx_html) if FileTest.file?(hard_idx_html) - end - end - def make_marshal_idx_sst_html_seg - marshal_dal=@make.marshal.dal_idx_sst_rel_html_seg - File.open(marshal_dal,'w'){|f| Marshal.dump(@data,f)} if @data.is_a?(Array) - end - def make_marshal_idx_sst_rel - marshal_dal=@make.marshal.dal_idx_sst_rel - File.open(marshal_dal,'w'){|f| Marshal.dump(@data,f)} if @data.is_a?(Array) - end - def make_marshal_idx_html - marshal_dal=@make.marshal.dal_idx_html - File.open(marshal_dal,'w'){|f| Marshal.dump(@data,f)} if @data.is_a?(Array) - end - def make_marshal_idx_xhtml - marshal_dal=@make.marshal.dal_idx_xhtml - File.open(marshal_dal,'w'){|f| Marshal.dump(@data,f)} if @data.is_a?(Array) - end - def make_marshal_map_nametags - marshal_dal=@make.marshal.dal_map_nametags - File.open(marshal_dal,'w'){|f| Marshal.dump(@data,f)} if @data.is_a?(Hash) - end - def make_marshal_map_name_ocn_htmlseg - marshal_dal=@make.marshal.dal_map_ocn_htmlseg - File.open(marshal_dal,'w'){|f| Marshal.dump(@data,f)} if @data.is_a?(Hash) - end - end - class Make - def initialize(fn,md,data) - @fn,@md,@data=fn,md,data - @env=SiSU_Env::InfoEnv.new(@md.fns) - end - def reset - @@flag_vocab=0 - @@line_mode='' - end - def song - reset - data=@data - data=SiSU_DAL_Insertions::Insertions.new(@md,data).expand_insertions? # dal_expand_insertions.rb - data=SiSU_DAL_MiscArrangeText::SI.new(@md,data).prepare_text # dal_misc_arrange.rb - data,metadata=SiSU_DAL_DocumentStructureExtract::Build.new(@md,data).identify_parts # dal_doc_str.rb - data=SiSU_DAL_Syntax::Markup.new(@md,data).songsheet # dal_syntax.rb - data,endnote_array=SiSU_DAL_CharacterCheck::Check.new(data).character_check_and_oldstyle_endnote_array # dal_character_check.rb - data=SiSU_DAL_Images::Images.new(@md,data).images # dal_images.rb - data,tags_map,ocn_html_seg_map=SiSU_DAL_Numbering::Numbering.new(@md,data).numbering_song # dal_numbering.rb - data,book_index_rel,book_index_rel_html_seg,html_idx,xhtml_idx=SiSU_DAL_BookIndex::BookIndex.new(@md,data,@env).indexing_song if @md.book_idx # dal_idx.rb - data=SiSU_DAL_Endnotes::Endnotes.new(@md,data,endnote_array).endnotes # dal_endnotes.rb - outputdata=data - if (@md.opt.act[:dal][:set]==:on \ - || @md.opt.act[:maintenance][:set]==:on) - SiSU_DAL::Output.new(@fn,@md,outputdata).hard_output - SiSU_DAL::Output.new(@fn,@md,outputdata).make_marshal_content - SiSU_DAL::Output.new(@fn,@md,metadata).make_marshal_metadata - SiSU_DAL::Output.new(@fn,@md,html_idx).idx_html_hard_output - SiSU_DAL::Output.new(@fn,@md,book_index_rel_html_seg).make_marshal_idx_sst_html_seg - SiSU_DAL::Output.new(@fn,@md,book_index_rel).make_marshal_idx_sst_rel - SiSU_DAL::Output.new(@fn,@md,html_idx).make_marshal_idx_html - SiSU_DAL::Output.new(@fn,@md,xhtml_idx).make_marshal_idx_xhtml - SiSU_DAL::Output.new(@fn,@md,tags_map).make_marshal_map_nametags - SiSU_DAL::Output.new(@fn,@md,ocn_html_seg_map).make_marshal_map_name_ocn_htmlseg - end - reset - outputdata - end - protected - end -end -__END__ diff --git a/lib/sisu/v5/dal_character_check.rb b/lib/sisu/v5/dal_character_check.rb deleted file mode 100644 index 62aa60c1..00000000 --- a/lib/sisu/v5/dal_character_check.rb +++ /dev/null @@ -1,107 +0,0 @@ -# encoding: utf-8 -=begin - - * Name: SiSU - - * Description: a framework for document structuring, publishing and search - - * 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. - - * 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 . - - If you have Internet connection, the latest version of the GPL should be - available at these locations: - - - - - - * SiSU uses: - * Standard SiSU markup syntax, - * Standard SiSU meta-markup syntax, and the - * Standard SiSU object citation numbering and system - - * Hompages: - - - - * Download: - - - * Git - - - - * Ralph Amissah - - - - ** Description: system environment, resource control and configuration details - -=end -module SiSU_DAL_CharacterCheck - class Check - def initialize(data) - @data=data - @comment='%' - @endnote_array=[] - end - def character_check_and_oldstyle_endnote_array - data=@data - @tuned_file,@endnote_array=[],[] - endnote_no=1 - data.each do |dob| - unless dob.is ==:table - dob.obj=dob.obj.strip. - gsub(/^[{~}]\s*$/,''). - gsub(/~#\s*/,"#{Mx[:pa_non_object_no_heading]}"). - gsub(/-#\s*/,"#{Mx[:pa_non_object_dummy_heading]}"). - gsub(/(#{Mx[:en_a_o]})\s*\s+/,'\1 '). - gsub(/(~\{\s*)\s+/,'\1 '). - gsub(/ \/\//,"#{Mx[:br_line]}"). - gsub(/
/,"#{Mx[:br_line]}"). #needed by xml, xhtml etc. - gsub(/\t/,' '). - gsub(/\342\200\231/u,"'"). #if dob =~/’/ #Avoid #‘ ’ #“ ” - gsub(/\\copy(?:right)?\b/,'©'). - gsub(/\\trademark\b|\\tm\b/,'®') - dob.obj=dob.obj + "\n" - unless dob.is ==:code - case dob.obj - when /\^~/ #% Note must do this first (earlier loop) and then enter gathered data into ~^\d+ - sub_dob=dob.obj.dup - @endnote_array << sub_dob.gsub(/\n/,''). - gsub(/\^~\s+(.+)\s*/,%{#{Mx[:en_a_o]}#{endnote_no} \\1 #{Mx[:en_a_c]}}). - strip - endnote_no+=1 - dob=nil if dob.obj =~/\^~ .+/ #watch, removes 'binary' endnote now in endnote array for later insertion - end - end - end - @tuned_file << dob if dob.is_a?(Object) - end - @tuned_file=@tuned_file.flatten.compact - [@tuned_file,@endnote_array] - end - end -end -__END__ diff --git a/lib/sisu/v5/dal_doc_objects.rb b/lib/sisu/v5/dal_doc_objects.rb deleted file mode 100644 index 518535b0..00000000 --- a/lib/sisu/v5/dal_doc_objects.rb +++ /dev/null @@ -1,481 +0,0 @@ -# encoding: utf-8 -=begin - - * Name: SiSU - - * Description: a framework for document structuring, publishing and search - - * 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. - - * 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 . - - If you have Internet connection, the latest version of the GPL should be - available at these locations: - - - - - - * SiSU uses: - * Standard SiSU markup syntax, - * Standard SiSU meta-markup syntax, and the - * Standard SiSU object citation numbering and system - - * Hompages: - - - - * Download: - - - * Git - - - - * Ralph Amissah - - - - ** Description: document abstraction - -=end -module SiSU_DAL_DocumentStructure - class Extract - def extract(h,o) - h ? h : o - end - end - class ObjectMetadata - attr_accessor :is,:of,:tags,:obj,:digest - def initialize - @tags={} - @is=@tmp=@digest=nil - @of=:meta - end - def metadata(tags) - of= @of #String, classification - group - is= :meta #String, classification - specific type - tags= tags || ((defined? o.tags) ? o.tags : {}) #String, metadata type/tag - obj= nil - @of,@is,@tags,@obj=of,is,tags,obj - self - end - end - class ObjectMeta - attr_accessor :obj,:is,:of,:tag,:digest,:tmp - def initialize - @is=@obj=@tag=@digest=@digest=@tmp=nil - @of=:meta - end - def metadata(h,o=nil) - of= @of #String, classification - group - is= :meta #String, classification - specific type - tag= h[:tag] || ((defined? o.tag) ? o.tag : nil) #String, metadata type/tag - obj= h[:obj] || ((defined? o.obj) ? o.obj : nil) #String, text content - tmp= h[:tmp] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use - digest= h[:digest] || ((defined? o.digest) ? o.digest : nil) #hash digests, either sha256 or md5 - @of,@is,@tag,@obj,@digest,@tmp=of,is,tag,obj,digest,tmp - self - end - end - class ObjectHeading - attr_accessor :obj,:is,:tags,:of,:lv,:ln,:lc,:toc_,:name,:idx,:ocn,:odv,:osp,:node,:parent,:ocn_,:note_,:autonum_,:digest,:tmp - def initialize - @of=:para - @is=@obj=@lv=@ln=@lc=@toc_=@name=@idx=@size=@ocn=@odv=@osp=@node=@parent=@ocn_=@note_=@autonum_=@digest=@tmp=nil - @tags=[] - end - def heading_ln(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 - end - end - def heading_lv(ln) - case ln.to_s - when /1/; 'A' - when /2/; 'B' - when /3/; 'C' - when /4/; '1' - when /5/; '2' - when /6/; '3' - when /7/; '4' - when /8/; '5' - when /9/; '6' - end - end - def heading(h,o=nil) - if not h[:ln] \ - and (h[:lv] and h[:lv]=~/[1-6A-C]/) - h[:ln]=heading_ln(h[:lv]) - elsif not h[:lv] \ - and (h[:ln] and h[:ln].to_s=~/[1-9]/) - h[:lv]=heading_lv(h[:ln]) - end - of= @of #String, classification - group - is= :heading #String, classification - specific type - name= h[:name] || ((defined? o.name) ? o.name : nil) #String, named object? - tags= h[:tags] || ((defined? o.tags) ? o.tags : []) #Array, associated object tags, names if any - obj= h[:obj] || ((defined? o.obj) ? o.obj : nil) #String, text content - idx= h[:idx] || ((defined? o.idx) ? o.idx : nil) #String, book index provided? - ocn= h[:ocn] || ((defined? o.ocn) ? o.ocn : nil) #Integer, sequential on substantive-content objects - odv= h[:odv] || ((defined? o.odv) ? o.odv : nil) - 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 - 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) - ocn_=if h[:ocn_].nil? then ((defined? o.ocn_) ? o.ocn_ : true) #Bool? no ocn, non-substantive content, do not include in toc #consider - else h[:ocn_] - end - autonum_= if h[:autonum_].nil? then ((defined? o.autonum_) ? o.autonum_ : true) #Bool? auto-numbering if requested default on, false suppresses - else h[:autonum_] - end - note_= h[:note_] || ((defined? o.note_) ? o.note_ : false) #Bool, endnotes/footnotes? (processing optimization) - digest= h[:digest] || ((defined? o.digest) ? o.digest : nil) #hash digests, either sha256 or md5 - tmp= h[:tmp] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use - @of,@is,@lv,@ln,@lc,@name,@tags,@obj,@idx,@ocn,@odv,@osp,@node,@parent,@toc_,@ocn_,@note_,@autonum_,@digest,@tmp=of,is,lv,ln,lc,name,tags,obj,idx,ocn,odv,osp,node,parent,toc_,ocn_,note_,autonum_,digest,tmp - self - end - def heading_insert(h,o=nil) - heading(h,o=nil) - @is= :heading_insert #String, classification - specific type - self - end - end - class ObjectPara - attr_accessor :obj,:is,:tags,:of,:name,:idx,:bullet_,:indent,:hang,:ocn,:odv,:osp,:parent,:note_,:image_,:ocn_,:digest,:tmp - def initialize - @of=:para - @is=@obj=@name=@idx=@bullet_=@indent=@hang=@size=@ocn=@odv=@osp=@parent=@note_=@image_=@ocn_=@digest=@tmp=nil - @tags=[] - end - def paragraph(h,o=nil) - of= @of #String, classification - group - is= :para #String, classification - specific type - name= h[:name] || ((defined? o.name) ? o.name : nil) #String, named object? - tags= h[:tags] || ((defined? o.tags) ? o.tags : []) #Array, associated object tags, names if any - obj= h[:obj] || ((defined? o.obj) ? o.obj : nil) #String, text content - idx= h[:idx] || ((defined? o.idx) ? o.idx : nil) #String, book index provided? - ocn= h[:ocn] || ((defined? o.ocn) ? o.ocn : nil) #Integer, sequential on substantive-content objects - odv= h[:odv] || ((defined? o.odv) ? o.odv : nil) - osp= h[:osp] || ((defined? o.osp) ? o.osp : nil) - parent= h[:parent] || ((defined? o.parent) ? o.parent : nil) #[Node parent] - indent= h[:indent].to_s || ((defined? o.indent) ? o.indent.to_s : nil) #Integer, indent level - hang= h[:hang].to_s || ((defined? o.hang) ? o.hang.to_s : nil) #Integer, hanging indent level - bullet_=h[:bullet_] || ((defined? o.bullet_) ? o.bullet_ : false) #Bool, bulleted? - note_= h[:note_] || ((defined? o.note_) ? o.note_ : false) #Bool, endnotes/footnotes? (processing optimization) - image_= h[:image_] || ((defined? o.image_) ? o.image_ : false) #Bool, images? (processing optimization) - ocn_=if h[:ocn_].nil? then ((defined? o.ocn_) ? o.ocn_ : true) #Bool? no ocn, non-substantive content, do not include in toc #consider - else h[:ocn_] - end - digest= h[:digest] || ((defined? o.digest) ? o.digest : nil) #hash digests, either sha256 or md5 - tmp= h[:tmp] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use - @of,@is,@name,@tags,@obj,@indent,@hang,@bullet_,@idx,@ocn,@odv,@osp,@parent,@image_,@note_,@ocn_,@digest,@tmp=of,is,name,tags,obj,indent,hang,bullet_,idx,ocn,odv,osp,parent,image_,note_,ocn_,digest,tmp - self - end - def docinfo(h,o=nil) - of= @of #String, classification - group - is= :docinfo #String, classification - specific type - name= h[:name] || ((defined? o.name) ? o.name : nil) #String, named object? - tags= h[:tags] || ((defined? o.tags) ? o.tags : nil) #Array, associated object tags, names if any - obj= h[:obj] || ((defined? o.obj) ? o.obj : nil) #String, text content - idx= nil #String, book index provided? - ocn= nil #Integer, sequential on substantive-content objects - odv= h[:odv] || ((defined? o.odv) ? o.odv : nil) - osp= h[:osp] || ((defined? o.osp) ? o.osp : nil) - parent= h[:parent] || ((defined? o.parent) ? o.parent : nil) #[Node parent] - indent= nil #Integer, indent level - hang= nil #Integer, indent level - bullet_=false #Bool, bulleted? - note_= false #Bool, endnotes/footnotes? (processing optimization) - image_= h[:image_] || ((defined? o.image_) ? o.image_ : false) #Bool, images? (processing optimization) - ocn_=if h[:ocn_].nil? then ((defined? o.ocn_) ? o.ocn_ : true) #Bool? no ocn, non-substantive content, do not include in toc #consider - else h[:ocn_] - end - digest= h[:digest] || ((defined? o.digest) ? o.digest : nil) #hash digests, either sha256 or md5 - tmp= h[:tmp] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use - @of,@is,@name,@tags,@obj,@indent,@hang,@bullet_,@idx,@ocn,@odv,@osp,@parent,@image_,@note_,@ocn_,@digest,@tmp=of,is,name,tags,obj,indent,hang,bullet_,idx,ocn,odv,osp,parent,image_,note_,ocn_,digest,tmp - self - end - end - class ObjectBlockTxt - attr_accessor :obj,:is,:of,:tags,:idx,:ocn,:odv,:osp,:parent,:note_,:number_,:ocn_,:digest,:tmp - def initialize - @of=:block - @is=@obj=@idx=@ocn=@odv=@osp=@parent=@note_=@number_=@ocn_=@digest=@tmp=nil - @tags=[] - end - def code(h,o=nil) - of= @of #String, classification - group #alt 'code' - is= :code #String, classification - specific type - tags= h[:tags] || ((defined? o.tags) ? o.tags : []) #Array, associated object tags, names if any - obj= h[:obj] || ((defined? o.obj) ? o.obj : nil) #String, text content - idx= h[:idx] || ((defined? o.idx) ? o.idx : nil) #String, book index provided? - ocn= h[:ocn] || ((defined? o.ocn) ? o.ocn : nil) #Integer, sequential on substantive-content objects - odv= h[:odv] || ((defined? o.odv) ? o.odv : nil) - osp= h[:osp] || ((defined? o.osp) ? o.osp : nil) - parent= h[:parent] || ((defined? o.parent) ? o.parent : nil) #[Node parent] - number_= h[:number_] || ((defined? o.number_) ? o.number_ : false) #Bool, numbered or not? - note_= h[:note_] || ((defined? o.note_) ? o.note_ : false) #Bool, endnotes/footnotes? (processing optimization) - ocn_= if h[:ocn_].nil? then ((defined? o.ocn_) ? o.ocn_ : true) #Bool? no ocn, non-substantive content, do not include in toc #consider - else h[:ocn_] - end - digest= h[:digest] || ((defined? o.digest) ? o.digest : nil) #hash digests, either sha256 or md5 - tmp= h[:tmp] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use - @of,@is,@tags,@obj,@idx,@ocn,@odv,@osp,@parent,@number_,@note_,@ocn_,@digest,@tmp=of,is,tags,obj,idx,ocn,odv,osp,parent,number_,note_,ocn_,digest,tmp - self - end - def block(h,o=nil) - of= @of #String, classification - group - is= :block #String, classification - specific type - tags= h[:tags] || ((defined? o.tags) ? o.tags : []) #Array, associated object tags, names if any - obj= h[:obj] || ((defined? o.obj) ? o.obj : nil) #String, text content - idx= h[:idx] || ((defined? o.idx) ? o.idx : nil) #String, book index provided? - ocn= h[:ocn] || ((defined? o.ocn) ? o.ocn : nil) #Integer, sequential on substantive-content objects - odv= h[:odv] || ((defined? o.odv) ? o.odv : nil) - osp= h[:osp] || ((defined? o.osp) ? o.osp : nil) - parent= h[:parent] || ((defined? o.parent) ? o.parent : nil) #[Node parent] - note_= h[:note_] || ((defined? o.note_) ? o.note_ : false) #Bool, endnotes/footnotes? (processing optimization) - ocn_= if h[:ocn_].nil? then ((defined? o.ocn_) ? o.ocn_ : true) #Bool? no ocn, non-substantive content, do not include in toc #consider - else h[:ocn_] - end - digest= h[:digest] || ((defined? o.digest) ? o.digest : nil) #hash digests, either sha256 or md5 - tmp= h[:tmp] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use - @of,@is,@tags,@obj,@idx,@ocn,@odv,@osp,@parent,@note_,@ocn_,@digest,@tmp=of,is,tags,obj,idx,ocn,odv,osp,parent,note_,ocn_,digest,tmp - self - end - def group(h,o=nil) - of= @of #String, classification - group - is= :group #String, classification - specific type - tags= h[:tags] || ((defined? o.tags) ? o.tags : []) #Array, associated object tags, names if any - obj= h[:obj] || ((defined? o.obj) ? o.obj : nil) #String, text content - idx= h[:idx] || ((defined? o.idx) ? o.idx : nil) #String, book index provided? - ocn= h[:ocn] || ((defined? o.ocn) ? o.ocn : nil) #Integer, sequential on substantive-content objects - odv= h[:odv] || ((defined? o.odv) ? o.odv : nil) - osp= h[:osp] || ((defined? o.osp) ? o.osp : nil) - parent= h[:parent] || ((defined? o.parent) ? o.parent : nil) #[Node parent] - note_= h[:note_] || ((defined? o.note_) ? o.note_ : false) #Bool, endnotes/footnotes? (processing optimization) - ocn_= if h[:ocn_].nil? then ((defined? o.ocn_) ? o.ocn_ : true) #Bool? no ocn, non-substantive content, do not include in toc #consider - else h[:ocn_] - end - digest= h[:digest] || ((defined? o.digest) ? o.digest : nil) #hash digests, either sha256 or md5 - tmp= h[:tmp] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use - @of,@is,@tags,@obj,@idx,@ocn,@odv,@osp,@parent,@note_,@ocn_,@digest,@tmp=of,is,tags,obj,idx,ocn,odv,osp,parent,note_,ocn_,digest,tmp - self - end - def alt(h,o=nil) #see block - of= @of #String, classification - group - is= :alt #String, classification - specific type - tags= h[:tags] || ((defined? o.tags) ? o.tags : []) #Array, associated object tags, names if any - obj= h[:obj] || ((defined? o.obj) ? o.obj : nil) #String, text content - idx= h[:idx] || ((defined? o.idx) ? o.idx : nil) #String, book index provided? - ocn= h[:ocn] || ((defined? o.ocn) ? o.ocn : nil) #Integer, sequential on substantive-content objects - odv= h[:odv] || ((defined? o.odv) ? o.odv : nil) - osp= h[:osp] || ((defined? o.osp) ? o.osp : nil) - parent= h[:parent] || ((defined? o.parent) ? o.parent : nil) #[Node parent] - note_= h[:note_] || ((defined? o.note_) ? o.note_ : false) #Bool, endnotes/footnotes? (processing optimization) - ocn_= if h[:ocn_].nil? then ((defined? o.ocn_) ? o.ocn_ : true) #Bool? no ocn, non-substantive content, do not include in toc #consider - else h[:ocn_] - end - digest= h[:digest] || ((defined? o.digest) ? o.digest : nil) #hash digests, either sha256 or md5 - tmp= h[:tmp] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use - @of,@is,@tags,@obj,@idx,@ocn,@odv,@osp,@parent,@note_,@ocn_,@digest,@tmp=of,is,tags,obj,idx,ocn,odv,osp,parent,note_,ocn_,digest,tmp - self - end - def verse(h,o=nil) #part of poem decide how you deal with this - of= @of #String, classification - group - is= :verse #String, classification - specific type - tags= h[:tags] || ((defined? o.tags) ? o.tags : []) #Array, associated object tags, names if any - obj= h[:obj] || ((defined? o.obj) ? o.obj : nil) #String, text content - idx= h[:idx] || ((defined? o.idx) ? o.idx : nil) #String, book index provided? - ocn= h[:ocn] || ((defined? o.ocn) ? o.ocn : nil) #Integer, sequential on substantive-content objects - odv= h[:odv] || ((defined? o.odv) ? o.odv : nil) - osp= h[:osp] || ((defined? o.osp) ? o.osp : nil) - parent= h[:parent] || ((defined? o.parent) ? o.parent : nil) #[Node parent] - ocn_= if h[:ocn_].nil? then ((defined? o.ocn_) ? o.ocn_ : true) #Bool? no ocn, non-substantive content, do not include in toc #consider - else h[:ocn_] - end - digest= h[:digest] || ((defined? o.digest) ? o.digest : nil) #hash digests, either sha256 or md5 - tmp= h[:tmp] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use - @of,@is,@tags,@obj,@idx,@ocn,@odv,@osp,@parent,@note_,@ocn_,@digest,@tmp=of,is,tags,obj,idx,ocn,odv,osp,parent,note_,ocn_,digest,tmp - @h=nil - self - end - end - class ObjectTable - attr_accessor :obj,:is,:of,:lv,:tags,:name,:idx,:indent,:hang,:size,:ocn,:number,:head_,:cols,:widths,:odv,:osp,:parent,:note_,:ocn_,:digest,:tmp - def initialize - @of=:block - @is=@obj=@lv=@name=@idx=@indent=@hang=@size=@ocn,@number,@head_,@cols,@widths=@odv=@osp=@parent=@note_=@ocn_=@digest=@tmp=nil - @tags=[] - end - def table(h,o=nil) - of= @of #String, classification - group - is= :table #String, classification - specific type - tags= h[:tags] || ((defined? o.tags) ? o.tags : []) #Array, associated object tags, names if any - cols= h[:cols] || ((defined? o.cols) ? o.cols : nil) - widths= h[:widths] || ((defined? o.widths) ? o.widths : nil) - obj= h[:obj] || ((defined? o.obj) ? o.obj : nil) #String, text content - idx= h[:idx] || ((defined? o.idx) ? o.idx : nil) #String, book index provided? - ocn= h[:ocn] || ((defined? o.ocn) ? o.ocn : nil) #Integer, sequential on substantive-content objects - odv= h[:odv] || ((defined? o.odv) ? o.odv : nil) - osp= h[:osp] || ((defined? o.osp) ? o.osp : nil) - parent= h[:parent] || ((defined? o.parent) ? o.parent : nil) #[Node parent] - head_= h[:head_] || ((defined? o.head_) ? o.head_ : false) - note_= h[:note_] || ((defined? o.note_) ? o.note_ : false) #Bool, endnotes/footnotes? (processing optimization) - ocn_=if h[:ocn_].nil? then ((defined? o.ocn_) ? o.ocn_ : true) #Bool? no ocn, non-substantive content, do not include in toc #consider - else h[:ocn_] - end - digest= h[:digest] || ((defined? o.digest) ? o.digest : nil) #hash digests, either sha256 or md5 - tmp= h[:tmp] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use - @of,@is,@tags,@cols,@widths,@obj,@idx,@ocn,@odv,@osp,@parent,@head_,@note_,@ocn_,@digest,@tmp=of,is,tags,cols,widths,obj,idx,ocn,odv,osp,parent,head_,note_,ocn_,digest,tmp - self - end - end - class ObjectImage - attr_accessor :obj,:is,:of,:lv,:idx,:size,:ocn,:parent,:note_,:ocn_,:digest,:tmp - def initialize - @of=:image - @is=@obj=@lv=@idx=@size=@ocn=@parent=@note_=@ocn_=@tmp=@digest=nil - @tags=[] - end - def image(h,o=nil) #not yet used, and what of a paragraph containing several images, consider - of= @of #String, classification - group - is= :image #String, classification - specific type - tags= h[:tags] || ((defined? o.tags) ? o.tags : []) #Array, associated object tags, names if any - obj= h[:obj] || ((defined? o.obj) ? o.obj : nil) #String, text content - size= h[:size] || ((defined? o.size) ? o.size : nil) - idx= h[:idx] || ((defined? o.idx) ? o.idx : nil) #String, book index provided? - ocn= h[:ocn] || ((defined? o.ocn) ? o.ocn : nil) #Integer, sequential on substantive-content objects - odv= h[:odv] || ((defined? o.odv) ? o.odv : nil) - osp= h[:osp] || ((defined? o.osp) ? o.osp : nil) - parent= h[:parent] || ((defined? o.parent) ? o.parent : nil) #[Node parent] - note_= h[:note_] || ((defined? o.note_) ? o.note_ : false) #Bool, endnotes/footnotes? (processing optimization) - ocn_=if h[:ocn_].nil? then ((defined? o.ocn_) ? o.ocn_ : true) #Bool? no ocn, non-substantive content, do not include in toc #consider - else h[:ocn_] - end - digest= h[:digest] || ((defined? o.digest) ? o.digest : nil) #hash digests, either sha256 or md5 - tmp= h[:tmp] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use - @of,@is,@tags,@obj,@size,@idx,@ocn,@odv,@osp,@parent,@note_,@ocn_,@digest,@tmp=of,is,tags,obj,size,idx,ocn,odv,osp,parent,note_,ocn_,digest,tmp - self - end - end - class ObjectStructure - attr_accessor :obj,:tag,:node,:lv,:ln,:lc,:status,:is,:of,:tmp - def initialize - @of=:structure - @is=@obj=@node=@lv=@ln=@lc=@status=@tmp=nil - end - def xml_dom(h,o=nil) - 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 - 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] - status= h[:status] || ((defined? o.status) ? o.status : nil) #tag status open or close - tmp= h[:tmp] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use - @of,@is,@obj,@status,@node,@lv,@ln,@lc,@tmp=of,is,obj,status,node,lv,ln,lc,tmp - self - end - end - class ObjectComment - attr_accessor :obj,:is,:of,:tmp - def initialize - @of=:comment - @is=@obj=@tmp=nil - end - def comment(h,o=nil) - of= @of #String, classification - group - is= :comment #String, classification - specific type - obj= h[:obj] || ((defined? o.obj) ? o.obj : nil) #String, text content - tmp= h[:tmp] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use - @of,@is,@obj,@tmp=of,is,obj,tmp - self - end - end - class ObjectFlag - attr_accessor :obj,:is,:of,:flag,:mod,:tmp - def initialize - @of=:flag - @is=@obj=@flag=@mod=@tmp=nil - end - def flag(h,o=nil) - of= @of #String, classification - group - is= :flag #String, classification - specific type - obj= nil #String, text content - flag= h[:flag] || ((defined? o.flag) ? o.flag : nil) #String, text content - mod= h[:mod] || ((defined? o.mod) ? o.mod : nil) #String, text content - tmp= h[:flag] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use - @of,@is,@obj,@flag,@mod,@tmp=of,is,obj,flag,mod,tmp - self - end - def flag_ocn(h,o=nil) - of= @of #String, classification - group - is= :flag_ocn #String, classification - specific type - obj= nil #String, text content - flag= h[:flag] || ((defined? o.flag) ? o.flag : nil) #String, text content - mod= h[:mod] || ((defined? o.mod) ? o.mod : nil) #String, text content - tmp= h[:flag] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use - @of,@is,@obj,@flag,@mod,@tmp=of,is,obj,flag,mod,tmp - self - end - end - class ObjectLayout - attr_accessor :obj,:is,:of,:from,:tmp - def initialize - @of=:layout - @is=@obj=@from=@tmp=nil - end - def break(h,f=nil) #decide how to deal with - of= @of #String, classification - group - is= :break #String, classification - specific type - obj= h[:obj] #String, text content - from= f - tmp= h[:tmp] #available for processing, empty after use - @of,@is,@obj,@from,@tmp=of,is,obj,from,tmp - self - end - def insert(h,o=nil) #decide how to deal with, could mimic paragraph? - of= @of #String, classification - group - is= :insert #String, classification - specific type - obj= h[:obj] || ((defined? o.obj) ? o.obj : nil) #String, text content - tmp= h[:tmp] || ((defined? o.tmp) ? o.tmp : nil) #available for processing, empty after use - @of,@is,@obj,@tmp=of,is,obj,tmp - self - end - end -end -__END__ -# ~# |-# no paragraph number # -# not included in toc diff --git a/lib/sisu/v5/dal_doc_str.rb b/lib/sisu/v5/dal_doc_str.rb deleted file mode 100644 index 7a89dfb1..00000000 --- a/lib/sisu/v5/dal_doc_str.rb +++ /dev/null @@ -1,1427 +0,0 @@ -# encoding: utf-8 -=begin - - * Name: SiSU - - * Description: a framework for document structuring, publishing and search - - * 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. - - * 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 . - - If you have Internet connection, the latest version of the GPL should be - available at these locations: - - - - - - * SiSU uses: - * Standard SiSU markup syntax, - * Standard SiSU meta-markup syntax, and the - * Standard SiSU object citation numbering and system - - * Hompages: - - - - * Download: - - - * Git - - - - * Ralph Amissah - - - - ** Description: document abstraction - -=end -module SiSU_DAL_DocumentStructureExtract - class Instantiate < SiSU_Param::Parameters::Instructions - @@flag={ - ocn: :on, - code: :off, - poem: :off, - block: :off, - group: :off, - alt: :off, - table: :off, - table_to: :off, - } - def initialize - @@counter=@@column=@@columns=0 - @@line_mode='' - end - end - class Build - @@flag={ - ocn: :on, - code: :off, - poem: :off, - block: :off, - group: :off, - alt: :off, - table: :off, - table_to: :off, - } - def initialize(md,data) - @md,@data=md,data - SiSU_DAL_DocumentStructureExtract::Instantiate.new - @pb=SiSU_DAL_DocumentStructure::ObjectLayout.new.break(Hx[:br_page]) - @pbn=SiSU_DAL_DocumentStructure::ObjectLayout.new.break(Hx[:br_page_new]) - @pbl=SiSU_DAL_DocumentStructure::ObjectLayout.new.break(Hx[:br_page_line]) - 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 - end - end - def image_test(str) - str=~/\{\s*\S+?\.png.+?\}https?:\/\/\S+/ \ - ? true - : false - end - def bullet_test(str) - (str=~/\*/) \ - ? true - : false - end - def hang_and_indent_test(str) - hang_indent=if str=~/^_([1-9])[^_]/ - [$1,$1] - elsif str=~/^__([1-9])/ - [0,$1] - elsif str=~/^_([0-9])_([0-9])/ - [$1,$2] - else - [0,0] - end - hang,indent=hang_indent[0],hang_indent[1] - [hang,indent] - end - def hang_and_indent_def_test(str1,str2) - hang_indent=if str1=~/^_([1-9])[^_]/ - [$1,$1] - elsif str1=~/^__([1-9])/ - [0,$1] - elsif str1=~/^_([0-9])_([0-9])/ - [$1,$2] - else - [0,0] - end - obj=if str2 =~/^(.+?)\s+\\\\(?:\s+|\n)/ - str2.gsub(/^(.+?)(\s+\\\\(?:\s+|\n))/,"#{Mx[:fa_bold_o]}\\1#{Mx[:fa_bold_c]}\\2") - else - str2.gsub(/^(.+?)\n/,"#{Mx[:fa_bold_o]}\\1#{Mx[:fa_bold_c]}\n") - end - hang,indent=hang_indent[0],hang_indent[1] - [hang,indent,obj] - end - def endnote_test?(str) - (str=~/~\{.+?\}~|~\[.+?\]~/) \ - ? true - : false - end - def extract_tags(str,nametag=nil) - tags=[] - if str.nil? - else - if str =~/(?:^|[ ])\*~([a-z0-9._-]+)(?=[ #{Mx[:br_nl]}]|$)/ - str=str.gsub(/(^|[ ])\*~([a-z0-9._-]+)(?=[ #{Mx[:br_nl]}]|$)/i, - "\\1#{Mx[:tag_o]}\\2#{Mx[:tag_c]}"). - gsub(/ [ ]+/i,' ') - tags=str.scan(/#{Mx[:tag_o]}(\S+?)#{Mx[:tag_c]}/).flatten - str=str.gsub(/[ ]?#{Mx[:tag_o]}\S+?#{Mx[:tag_c]}[ ]?/,' ') #may be issues with spaces would leave one, but "code" blocks? - end - tags=nametag ? (tags << nametag) : tags - end - [str,tags] - end - def rgx_idx_ocn_seg - @rgx_idx_ocn_seg=/(.+?)\s*[+](\d+)/ - end - def construct_idx_array_and_hash(idxraw) - idx_array_raw=idxraw.scan(/[^;]+/) - idx_hash,idx_array,idx_lst={},[],[] - idx_array_raw.each do |idx| - idx_lst=case idx - when /\S+?\s*:/ - idx_couplet_tmp=[] - idx_couplet=idx.scan(/\s*[^:]+\s*/) - if idx_couplet[1] =~/[|]/ - idx_couplet_tmp << idx_couplet[0] << idx_couplet[1].scan(/\s*[^|]+\s*/) - else - idx_couplet_tmp << idx_couplet[0] << [idx_couplet[1]] - end - idx_couplet=idx_couplet_tmp - else [idx] - end - term_nodes=[] - idx_lst.each do |term_node| - case term_node - when String - term_node=term_node[0].chr.capitalize + term_node[1,term_node.length] - term_node=(term_node =~/.+?[+]\d+/) \ - ? term_node - : (term_node + '+0') - term_nodes << term_node - use,plus=rgx_idx_ocn_seg.match(term_node)[1,2] - @use=use.strip - idx_hash[@use]={ sub: [], plus: plus } unless idx_hash[@use] and defined? idx_hash[@use] - when Array - subterm_nodes=[] - term_node.each do |subterm_node| - subterm_node=(subterm_node =~/.+?[+]\d+/) \ - ? subterm_node - : (subterm_node + '+0') - subterm_nodes << subterm_node - sub,sub_plus=rgx_idx_ocn_seg.match(subterm_node)[1,2] - idx_hash[@use]={ sub: [], plus: 0 } unless idx_hash[@use] and defined? idx_hash[@use] - idx_hash[@use][:sub] << {sub.strip => { plus: sub_plus }} - end - term_nodes << subterm_nodes - end - end - idx_array << term_nodes - end - { hash: idx_hash, array: idx_array } - end - def identify_parts - tuned_file=[] - @tuned_block,@tuned_code=[],[] - @@counter,@verse_count=0,0 - @metadata={} - @data.each do |t_o| - if t_o =~/^--([+~-])[#]$/ - h=case $1 - when /[+]/ - @@flag[:ocn]=:on - {flag: :ocn_on} - when /[~]/ - @@flag[:ocn]=:off_headings_substantive - {flag: :ocn_off, mod: :headings_substantive} - when /[-]/ - @@flag[:ocn]=:off_headings_exclude - {flag: :ocn_off, mod: :headings_exclude} - else - @@flag[:ocn]=:on - {flag: :ocn_on} - end - t_o=SiSU_DAL_DocumentStructure::ObjectFlag.new.flag_ocn(h) - next - end - t_o=t_o.gsub(/(?:\n\s*\n)+/m,"\n") if @@flag[:code]==:off - if t_o !~/^(?:code|poem|alt|group|block)\{|^\}(?:code|poem|alt|group|block)|^(?:table\{|\{table)[ ~]/ \ - and t_o !~/^[`]{3}\s+(?:code|poem|alt|group|block|table)|^[`]{3}(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/ \ - and @@flag[:code]==:off \ - and @@flag[:poem]==:off \ - and @@flag[:group]==:off \ - and @@flag[:block]==:off \ - and @@flag[:alt]==:off \ - and @@flag[:table]==:off - unless t_o =~/^(?:@\S+?:|%+)\s/ # extract book index for paragraph if any - idx=if t_o=~/^=\{(.+)\}\s*$\Z/m; m=$1 - m=m.split(/\n/).join(' '). - gsub(/\s+([|:;])\s+/,'\1'). - gsub(/\s+([+]\d+)\s+/,'\1') - t_o=t_o.gsub(/\n=\{.+\}\s*$\Z/m,'') - idx_array_and_hash=construct_idx_array_and_hash(m) - idx_array_and_hash[:hash] - else nil - end - end - 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 - tag,obj=$1,$2 - @metadata[tag]=obj - end - t_o=nil - when /^%+\s/ #comment - t_o=if t_o=~/^%+\s+(.+)/ - h={obj: $1} - SiSU_DAL_DocumentStructure::ObjectComment.new.comment(h) - else nil - end - when /^:?([A-C1-6])\~/ #heading / lv - lv=$1 - ln=ln_get(lv) - t_o=if t_o=~/^:?[A-C1-6]\~\s+(.+)/m - obj=$1 - note=endnote_test?(obj) - obj,tags=extract_tags(obj) - if @@flag[:ocn]==:off_headings_exclude \ - or @@flag[:ocn]==:off_headings_substantive - unless obj =~ /[~-][#]\s*$/ - if @@flag[:ocn]==:off_headings_exclude - obj << ' -#' - elsif @@flag[:ocn]==:off_headings_substantive - obj << ' ~#' - end - end - end - h={ lv: lv, ln: ln, obj: obj, idx: idx, tags: tags } - SiSU_DAL_DocumentStructure::ObjectHeading.new.heading(h) - elsif t_o=~/^:?[A-C1-6]\~(\S+?)-\s+(.+)/m - name,obj=$1,$2 - note=endnote_test?(obj) - obj,tags=extract_tags(obj) - if @@flag[:ocn]==:off_headings_exclude \ - or @@flag[:ocn]==:off_headings_substantive - unless obj =~ /[~-][#]\s*$/ - if @@flag[:ocn]==:off_headings_exclude - obj << ' -#' - elsif @@flag[:ocn]==:off_headings_substantive - obj << ' ~#' - end - end - end - h={ lv: lv, name: name, obj: obj, idx: idx, autonum_: false, tags: tags} - SiSU_DAL_DocumentStructure::ObjectHeading.new.heading(h) - elsif t_o=~/^:?[A-C1-6]\~(\S+)\s+(.+)/m - name,obj=$1,$2 - note=endnote_test?(obj) - obj,tags=extract_tags(obj,name) - if @@flag[:ocn]==:off_headings_exclude \ - or @@flag[:ocn]==:off_headings_substantive - unless obj =~ /[~-][#]\s*$/ - if @@flag[:ocn]==:off_headings_exclude - obj << ' -#' - elsif @@flag[:ocn]==:off_headings_substantive - obj << ' ~#' - end - end - end - h={ lv: lv, name: name, obj: obj, idx: idx, tags: tags } - SiSU_DAL_DocumentStructure::ObjectHeading.new.heading(h) - else nil - end - when /^_(?:[1-9]!?|[1-9]?\*)\s+/ #indented and/or bullet paragraph - t_o=if t_o=~/^(_(?:[1-9]?\*|[1-9]!?)\s+)(.+)/m - tst,obj=$1,$2 - if t_o=~/^_[1-9]!\s+.+/m - hang,indent,obj=hang_and_indent_def_test(tst,obj) - else - hang,indent=hang_and_indent_test(tst) - end - bullet=bullet_test(tst) - image=image_test(obj) - note=endnote_test?(obj) - obj,tags=extract_tags(obj) - unless obj=~/\A\s*\Z/m - if @@flag[:ocn]==:off_headings_exclude \ - or @@flag[:ocn]==:off_headings_substantive - unless obj =~ /[~-][#]\s*$/ - obj << ' ~#' - end - end - h={ bullet_: bullet, hang: hang, indent: indent, obj: obj, idx: idx, note_: note, image_: image, tags: tags } - SiSU_DAL_DocumentStructure::ObjectPara.new.paragraph(h) - end - else nil - end - when /^_[0-9]?_[0-9]!?\s+/ #hanging indent paragraph - t_o=if t_o=~/^(_[0-9]?_[0-9]!?\s+)(.+)/m - tst,obj=$1,$2 - if t_o=~/^_[0-9]?_[0-9]!\s+.+/m - hang,indent,obj=hang_and_indent_def_test(tst,obj) - else - hang,indent=hang_and_indent_test(tst) - end - image=image_test(obj) - note=endnote_test?(obj) - obj,tags=extract_tags(obj) - unless obj=~/\A\s*\Z/m - if @@flag[:ocn]==:off_headings_exclude \ - or @@flag[:ocn]==:off_headings_substantive - unless obj =~ /[~-][#]\s*$/ - obj << ' ~#' - end - end - h={ hang: hang, indent: indent, obj: obj, idx: idx, note_: note, image_: image, tags: tags } - SiSU_DAL_DocumentStructure::ObjectPara.new.paragraph(h) - end - else nil - end - when /^<(?:br)?:(?:pa?r|o(?:bj|---)?)>\s*$/ #[br:par] #[br:obj] - SiSU_DAL_DocumentStructure::ObjectLayout.new.break(Hx[:br_obj]) - when /^(?:-\\\\-|<:pb>)\s*$/ #[br:pg] - SiSU_DAL_DocumentStructure::ObjectLayout.new.break(Hx[:br_page],:markup) - when /^(?:=\\\\=|<:pn>)\s*$/ #[br:pgn] - SiSU_DAL_DocumentStructure::ObjectLayout.new.break(Hx[:br_page_new],:markup) - when /^-\.\.-\s*$/ #[br:pgl] - SiSU_DAL_DocumentStructure::ObjectLayout.new.break(Hx[:br_page_line],:markup) - else #paragraph - image=image_test(t_o) - note=endnote_test?(t_o) - obj,tags=extract_tags(t_o) - if @@flag[:ocn]==:off_headings_exclude \ - or @@flag[:ocn]==:off_headings_substantive - unless obj =~ /[~-][#]\s*$/ - obj << ' ~#' - end - end - unless obj=~/\A\s*\Z/m - h={ bullet_: false, indent: 0, hang: 0, obj: obj, idx: idx, note_: note, image_: image, tags: tags } - SiSU_DAL_DocumentStructure::ObjectPara.new.paragraph(h) - end - end - elsif @@flag[:code]==:off - if t_o =~/^(?:code\{|[`]{3}\s+code)/ - @@flag[:code]=case t_o - when /^code\{/; :curls - when /^[`]{3}\s+code/; :tics - else @@flag[:code] #error - end - @@counter=1 - @codeblock_numbered=(t_o =~/^(?:code\{#|[`]{3}\s+code\s[#])/) ? true : false - h={ obj: 'code block start' } #introduce a counter - t_o=SiSU_DAL_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 - else @@flag[:poem] #error - end - h={ obj: 'poem start' } #introduce a counter - t_o=SiSU_DAL_DocumentStructure::ObjectComment.new.comment(h) - tuned_file << t_o - elsif t_o =~/^(?:group\{|[`]{3}\s+group)/ - @@flag[:group]=case t_o - when /^group\{/; :curls - when /^[`]{3}\s+group/; :tics - else @@flag[:group] #error - end - h={ obj: 'group text start' } #introduce a counter - t_o=SiSU_DAL_DocumentStructure::ObjectComment.new.comment(h) - tuned_file << t_o - elsif t_o =~/^(?:block\{|[`]{3}\s+block)/ - @@flag[:block]=case t_o - when /^block\{/; :curls - when /^[`]{3}\s+block/; :tics - else @@flag[:block] #error - end - h={ obj: 'block text start' } #introduce a counter - t_o=SiSU_DAL_DocumentStructure::ObjectComment.new.comment(h) - tuned_file << t_o - elsif t_o =~/^(?:alt\{|[`]{3}\s+alt)/ - @@flag[:alt]=case t_o - when /^alt\{/; :curls - when /^[`]{3}\s+alt/; :tics - else @@flag[:alt] #error - end - h={ obj: 'alt text start' } #introduce a counter - t_o=SiSU_DAL_DocumentStructure::ObjectComment.new.comment(h) - tuned_file << t_o - elsif t_o =~/^(?:table\{|[`]{3}\s+table|\{table)[ ~]/ - h={ obj: 'table start' } #introduce a counter - ins=SiSU_DAL_DocumentStructure::ObjectComment.new.comment(h) - tuned_file << ins - if t_o=~/^table\{(?:~h)?\s+/ - @@flag[: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=~/^[`]{3}\s+table(?:~h)?\s+c\d+/ - @@flag[:table]=:tics - @rows='' - case t_o - when /^[`]{3}\s+table~h\s+c(\d+);\s+(.+)/ - cols=$1 - col=$2.scan(/\d+/) - heading=true - when /^[`]{3}\s+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 } - t_o=SiSU_DAL_DocumentStructure::ObjectTable.new.table(h) unless h.nil? - tuned_file << t_o - h={ obj: 'table end' } #introduce a counter - t_o=SiSU_DAL_DocumentStructure::ObjectComment.new.comment(h) - t_o - elsif t_o=~/^[`]{3}\s+table(?:~h)?\s+/ - m1,m2,hd=nil,nil,nil - h=case t_o - when /^[`]{3}\s+table~h\s+(.+?)\n(.+)\Z/m #two table representations should be consolidated as one - m1,tbl,hd=$1,$2,true - when /^[`]{3}\s+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 } - t_o=SiSU_DAL_DocumentStructure::ObjectTable.new.table(h) unless h.nil? - tuned_file << t_o - h={ obj: 'table end' } #introduce a counter - t_o=SiSU_DAL_DocumentStructure::ObjectComment.new.comment(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 } - t_o=SiSU_DAL_DocumentStructure::ObjectTable.new.table(h) unless h.nil? - tuned_file << t_o - h={ obj: 'table end' } #introduce a counter - t_o=SiSU_DAL_DocumentStructure::ObjectComment.new.comment(h) - t_o - end - end - t_o - end - if @@flag[:table]==:curls or @@flag[:table]==:tics - if (@@flag[:table]==:curls \ - and t_o =~/^\}table/) \ - or (@@flag[:table]==:tics \ - and t_o =~/^[`]{3}(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/) - @@flag[:table]=:off - headings,columns,widths,idx=@h[:head_],@h[:cols],@h[:widths],@h[:idx] - @h={ head_: headings, cols: columns, widths: widths, idx: idx, obj: @rows } - t_o=SiSU_DAL_DocumentStructure::ObjectTable.new.table(@h) - tuned_file << t_o - @h,@rows=nil,'' - h={ obj: 'table end' } #introduce a counter - t_o=SiSU_DAL_DocumentStructure::ObjectComment.new.comment(h) - t_o - else - if t_o.is_a?(String) \ - and t_o !~/^(?:table\{|[`]{3}\s+table)/ - t_o=t_o.gsub(/^\n+/m,''). #check added for ruby 1.9.2 not needed in 1.8 series (tested in v2) - gsub(/\n+/m,"#{Mx[:tc_p]}") - @rows += t_o + Mx[:tc_c] - end - t_o=nil - end - end - if @@flag[:code]==:curls or @@flag[:code]==:tics - if (@@flag[:code]==:curls and t_o =~/^\}code/) \ - or (@@flag[:code]==:tics and t_o =~/^[`]{3}(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/) - @@flag[:code]=:off - obj=@tuned_code.join("\n") - tags=[] - h={ obj: obj, tags: tags, number_: @codeblock_numbered } - t_o=SiSU_DAL_DocumentStructure::ObjectBlockTxt.new.code(h) - @tuned_code=[] - tuned_file << t_o - h={ obj: 'code block end' } #introduce a counter - t_o=SiSU_DAL_DocumentStructure::ObjectComment.new.comment(h) - end - if (@@flag[:code]==:curls or @@flag[:code]==:tics) \ - and t_o.is_a?(String) - sub_array=t_o.dup + "#{Mx[:br_nl]}" - @line_mode=[] - sub_array.scan(/.+/) {|w| @line_mode << w if w =~/[\S]+/} - t_o=SiSU_DAL_DocumentStructureExtract::Build.new(@md,@line_mode).build_lines(:code).join - @tuned_code << t_o - t_o=nil - end - elsif (@@flag[:poem]==:curls or @@flag[:poem]==:tics) \ - or (@@flag[:group]==:curls or @@flag[:group]==:tics) \ - or (@@flag[:block]==:curls or @@flag[:block]==:tics) \ - or (@@flag[:alt]==:curls or @@flag[:alt]==:tics) - if (@@flag[:poem]==:curls and t_o =~/^\}poem/) \ - or (@@flag[:poem]==:tics and t_o =~/^[`]{3}(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/) - @@flag[:poem]=:off - h={ obj: 'poem end' } #introduce a counter - t_o=SiSU_DAL_DocumentStructure::ObjectComment.new.comment(h) - elsif (@@flag[:group]==:curls and t_o =~/^\}group/) \ - or (@@flag[:group]==:tics and t_o =~/^[`]{3}(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/) - @@flag[:group]=:off - obj,tags=extract_tags(@tuned_block.join("\n")) - h={ obj: obj, tags: tags } - @tuned_block=[] - t_o=SiSU_DAL_DocumentStructure::ObjectBlockTxt.new.group(h) - tuned_file << t_o - h={ obj: 'group text end' } #introduce a counter - t_o=SiSU_DAL_DocumentStructure::ObjectComment.new.comment(h) - elsif (@@flag[:block]==:curls and t_o =~/^\}block/) \ - or (@@flag[:block]==:tics and t_o =~/^[`]{3}(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/) - @@flag[:block]=:off - obj,tags=extract_tags(@tuned_block.join("\n")) - h={ obj: obj, tags: tags } - @tuned_block=[] - t_o=SiSU_DAL_DocumentStructure::ObjectBlockTxt.new.block(h) - tuned_file << t_o - h={ obj: 'block text end' } #introduce a counter - t_o=SiSU_DAL_DocumentStructure::ObjectComment.new.comment(h) - elsif (@@flag[:alt]==:curls and t_o =~/^\}alt/) \ - or (@@flag[:alt]==:tics and t_o =~/^[`]{3}(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/) - @@flag[:alt]=:off - obj,tags=extract_tags(@tuned_block.join("\n")) - h={ obj: obj, tags: tags } - t_o=SiSU_DAL_DocumentStructure::ObjectBlockTxt.new.alt(h) - @tuned_block=[] - tuned_file << t_o - h={ obj: 'alt text end' } #introduce a counter - t_o=SiSU_DAL_DocumentStructure::ObjectComment.new.comment(h) - end - if (@@flag[:poem]==:curls or @@flag[:poem]==:tics \ - or @@flag[:group]==:curls or @@flag[:group]==:tics \ - or @@flag[:alt]==:curls or @@flag[:alt]==:tics) \ - and t_o =~/\S/ \ - and t_o !~/^(?:\}(?:verse|code|alt|group|block)|(?:verse|code|alt|group|block)\{)/ \ - and t_o !~/^[`]{3}\s+(?:code|poem|alt|group|block)|^[`]{3}(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$/ # fix logic - sub_array=t_o.dup - @line_mode=sub_array.scan(/.+/) - type=if @@flag[:poem]==:curls or @@flag[:poem]==:tics - t_o=SiSU_DAL_DocumentStructureExtract::Build.new(@md,@line_mode).build_lines(type).join - poem=t_o.split(/\n\n/) - poem.each do |v| - v=v.gsub(/\n/m,"#{Mx[:br_nl]}\n") - obj,tags=extract_tags(v) - h={ obj: obj, tags: tags } - t_o=SiSU_DAL_DocumentStructure::ObjectBlockTxt.new.verse(h) - tuned_file << t_o - end - :poem - else :group - end - end - @verse_count+=1 if @@flag[:poem]==:curls or @@flag[:poem]==:tics - end - if @@flag[:code]==:off - if @@flag[:poem]==:curls or @@flag[:poem]==:tics \ - or @@flag[:group]==:curls or @@flag[:group]==:tics \ - or @@flag[:alt]==:curls or @@flag[:alt]==:tics - if t_o.is_a?(String) - t_o=t_o.gsub(/\n/m,"#{Mx[:br_nl]}"). - gsub(/[ ][ ]/m,"#{Mx[:nbsp]*2}"). - gsub(/#{Mx[:nbsp]}\s/,"#{Mx[:nbsp]*2}") - t_o=t_o + Mx[:br_nl] if t_o =~/\S+/ - elsif t_o.is==:group \ - || t_o.is==:block \ - || t_o.is==:alt \ - || t_o.is==:verse - t_o.obj=t_o.obj.gsub(/\n/m,"#{Mx[:br_nl]}"). - gsub(/[ ][ ]/m,"#{Mx[:nbsp]*2}"). - gsub(/#{Mx[:nbsp]}\s/,"#{Mx[:nbsp]*2}") - end - @tuned_block << t_o if t_o =~/\S+/ - else tuned_file << t_o - end - else tuned_file << t_o - end - end - if @md.flag_endnotes - tuned_file << @pb - h={ ln: 2, lc: 2, obj: 'Endnotes', autonum_: false } - tuned_file << SiSU_DAL_DocumentStructure::ObjectHeading.new.heading_insert(h) - h={ ln: 4, lc: 3, obj: 'Endnotes', name: 'endnotes', autonum_: false } - tuned_file << SiSU_DAL_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 } - tuned_file << SiSU_DAL_DocumentStructure::ObjectHeading.new.heading_insert(h) - h={ ln: 4, lc: 3, obj: 'Index', name: 'book_index', autonum_: false } - tuned_file << SiSU_DAL_DocumentStructure::ObjectHeading.new.heading_insert(h) - h={ obj: 'Index' } - end - tuned_file << @pb - h={ ln: 2, lc: 2, obj: 'Metadata', autonum_: false, ocn_: false } - tuned_file << SiSU_DAL_DocumentStructure::ObjectHeading.new.heading_insert(h) - h={ ln: 4, lc: 3, obj: 'SiSU Metadata, document information', name: 'metadata', autonum_: false, ocn_: false } - tuned_file << SiSU_DAL_DocumentStructure::ObjectHeading.new.heading_insert(h) - h={ obj: 'eof' } - meta=SiSU_DAL_DocumentStructure::ObjectMetadata.new.metadata(@metadata) - [tuned_file,meta] - end - def table_rows_and_columns_array(table_str) - table=[] - table_str.split(/#{Mx[:tc_c]}/).each do |table_row| - table_row_with_columns=table_row.split(/#{Mx[:tc_p]}/) - table << table_row_with_columns - end - table - end - def meta_heading(h) - h={ lv: h[:lv], ln: h[:ln], name: h[:name], obj: h[:obj], ocn: '0' } - SiSU_DAL_DocumentStructure::ObjectHeading.new.heading(h) - end - def meta_para(str) - h={ obj: str, ocn_: false } - SiSU_DAL_DocumentStructure::ObjectPara.new.paragraph(h) - end - def build_lines(type=:none) - lines,lines_new=@data,[] - lines.each do |line| - line=if line =~/\S/ \ - and line !~/^(?:code\{|\}code)/ \ - and line !~/^(?:[`]{3}\s+code|[`]{3}(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*$)/ \ - and not line.is_a?(Hash) #watch - @@counter+=1 if @@flag[:code]==:curls or @@flag[: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 - line=if line =~/(?:https?|file|ftp):\/\/\S+$/ - line.gsub(/\s*$/," #{Mx[:br_nl]}") - else line.gsub(/\s*$/,"#{Mx[:br_nl]}") #unless type=='code' - end - elsif line =~/^\s*$/ - line.gsub(/\s*$/,"#{Mx[:br_nl]}") - else line - end - lines_new << line - end - lines_new - end - end - class Structure # this must happen early - def initialize(md,dob) - @md,@dob=md,dob - end - def structure - structure_markup - @dob - end - def structure_markup #build structure where structure provided only in meta header - @dob=if @dob.is==:para \ - && (((@dob.hang !~/[1-9]/) && (@dob.indent !~/[1-9]/)) \ - || (@dob.hang != @dob.indent)) \ - and not @dob.bullet_ - @dob=case @dob.obj - when /^#{@md.lv1}/ - h={ lv: 'A', ln: 1 } - SiSU_DAL_DocumentStructure::ObjectHeading.new.heading(h,@dob) - when /^#{@md.lv2}/ - h={ lv: 'B', ln: 2 } - SiSU_DAL_DocumentStructure::ObjectHeading.new.heading(h,@dob) - when /^#{@md.lv3}/ - h={ lv: 'C', ln: 3 } - SiSU_DAL_DocumentStructure::ObjectHeading.new.heading(h,@dob) - when /^#{@md.lv4}/ - h={ lv: '1', ln: 4 } - SiSU_DAL_DocumentStructure::ObjectHeading.new.heading(h,@dob) - when /^#{@md.lv5}/ - h={ lv: '2', ln: 5 } - SiSU_DAL_DocumentStructure::ObjectHeading.new.heading(h,@dob) - when /^#{@md.lv6}/ - h={ lv: '3', ln: 6 } - SiSU_DAL_DocumentStructure::ObjectHeading.new.heading(h,@dob) - else @dob - end - else @dob - end - @dob - end - end - class OCN - def initialize(md,data) - @md,@data=md,data - end - def structure_info - def lv - %w[0 A~ B~ C~ 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' - 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' - end - end - self - end - def document_structure_check_info(node,node_parent,status=:ok) - node_ln=/^([0-6])/.match(node)[1].to_i - node_parent_ln=/^([0-6])/.match(node_parent)[1].to_i - if status==:error \ - or @md.opt.act[:maintenance][:set]==:on - puts %{node: #{node}, parent node: #{node_parent} #{status.upcase}} - if status==:error - node_ln=/^([0-6])/.match(node)[1].to_i - node_parent_ln=/^([0-6])/.match(node_parent)[1].to_i - puts %{current level: #{structure_info.lv[node_ln]} (possible parent levels: #{structure_info.possible_parents(structure_info.lv[node_ln])}) -parent level: #{structure_info.lv[node_parent_ln]} (possible child levels: #{structure_info.possible_children(structure_info.lv[node_parent_ln])}) --- } - end - end - end - def warning_incorrect_parent_level_or_level(txt) - puts %{warning, -#{txt} -has incorrect level and/or parent level} - end - 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 - regex_exclude_ocn_and_node = /#{Rx[:meta]}|^@\S+?:\s|^4~endnotes|^#{Mx[:lv_o]}4:endnotes#{Mx[:lv_c]}|^\^~ |<:e[:_]\d+?>|^<:\#|<:- |<[:!]!4|
- 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 - end - end - if not dob.obj =~/~#|-#/ - ocn+=1 - end - if dob.is==:heading \ - and (ln.to_s =~/^[1-9]/ \ - or ln.to_s =~@md.lv1 \ - or ln.to_s =~@md.lv2 \ - or ln.to_s =~@md.lv3 \ - or ln.to_s =~@md.lv4 \ - or ln.to_s =~@md.lv5 \ - or ln.to_s =~@md.lv6) - if not dob.obj =~/~#|-#/ - ocnh+=1 - end - if ln==1 \ - or ln=~@md.lv1 - if not dob.obj =~/~#|-#/ - ocn_flag=true - ocnh1+=1 #heading - node1="1:#{ocnh1};#{ocn}" - else - ocn_flag=false - node1="1:0;0" - end - document_structure_check_info(node1,node0) - @collapsed_lv1=1 - collapsed_level=@collapsed_lv1 - node,ocn_sp,parent=node1,"h#{ocnh}",node0 #FIX - elsif ln==2 \ - or ln=~@md.lv2 - if not dob.obj =~/~#|-#/ - ocn_flag=true - ocnh2+=1 - node2="2:#{ocnh2};#{ocn}" - else - ocn_flag=false - node2="2:0;0" - end - parent=if node1 - document_structure_check_info(node2,node1) - @collapsed_lv2=@collapsed_lv1+1 - node1 - else - document_structure_check_info(node2,node0,:error) - node0 - end - collapsed_level=@collapsed_lv2 - node,ocn_sp=node2,"h#{ocnh}" - elsif ln==3 \ - or ln=~@md.lv3 - if not dob.obj =~/~#|-#/ - ocn_flag=true - ocnh3+=1 - node3="3:#{ocnh3};#{ocn}" - else - ocn_flag=false - node3="3:0;0" - end - parent=if node2 - document_structure_check_info(node3,node2) - @collapsed_lv3=@collapsed_lv2+1 - node2 - elsif node1 - warning_incorrect_parent_level_or_level(dob.obj) - puts %{parent is :A~ & this level #{dob.lv} -either parent should be level :B~ -or this level should be level :B~ rather than #{dob.lv}} - document_structure_check_info(node3,node1,:error) - @collapsed_lv3=@collapsed_lv1+1 - node1 - else - document_structure_check_info(node3,node0,:error) - warning_incorrect_parent_level_or_level(dob.obj) - node0 - end - collapsed_level=@collapsed_lv3 - node,ocn_sp=node3,"h#{ocnh}" - elsif ln==4 \ - or ln=~@md.lv4 - if not dob.obj =~/~#|-#/ - ocn_flag=true - ocnh4+=1 - node4="4:#{ocnh4};#{ocn}" - else - ocn_flag=false - node4="4:0;0" - end - parent=if node3 - document_structure_check_info(node4,node3) - @collapsed_lv4=@collapsed_lv3+1 - node3 - elsif node2 - document_structure_check_info(node4,node2) - @collapsed_lv4=@collapsed_lv2+1 - node2 - elsif node1 - document_structure_check_info(node4,node1) - @collapsed_lv4=@collapsed_lv1+1 - node1 - else - warning_incorrect_parent_level_or_level(dob.obj) - document_structure_check_info(node4,node0,:error) - node0 - end - collapsed_level=@collapsed_lv4 - node,ocn_sp=node4,"h#{ocnh}" - elsif ln==5 \ - or ln=~@md.lv5 - if not dob.obj =~/~#|-#/ - ocn_flag=true - ocnh5+=1 - node5="5:#{ocnh5};#{ocn}" - else - ocn_flag=false - node5="5:0;0" - end - parent=if node4 - document_structure_check_info(node5,node4) - @collapsed_lv5=@collapsed_lv4+1 - node4 - elsif node3 - warning_incorrect_parent_level_or_level(dob.obj) - document_structure_check_info(node5,node3,:error) - @collapsed_lv5=@collapsed_lv3+1 - node3 - elsif node2 - warning_incorrect_parent_level_or_level(dob.obj) - document_structure_check_info(node5,node2,:error) - @collapsed_lv5=@collapsed_lv2+1 - node2 - elsif node1 - warning_incorrect_parent_level_or_level(dob.obj) - document_structure_check_info(node5,node1,:error) - @collapsed_lv5=@collapsed_lv1+1 - node1 - else - document_structure_check_info(node5,node0,:error) - node0 - end - collapsed_level=@collapsed_lv5 - node,ocn_sp=node5,"h#{ocnh}" - elsif ln==6 \ - or ln=~@md.lv6 - if not dob.obj =~/~#|-#/ - ocn_flag=true - ocnh6+=1 - node6="6:#{ocnh6};#{ocn}" - else - ocn_flag=false - node6="6:0;0" - end - parent=if node5 - document_structure_check_info(node6,node5) - @collapsed_lv6=@collapsed_lv5+1 - node5 - elsif node4 - warning_incorrect_parent_level_or_level(dob.obj) - puts "parent is level 4~ & this level #{dob.lv} -either parent should be level 5~ -or this level should be 5~ rather #{dob.lv}" #level 6 - document_structure_check_info(node6,node4,:error) - @collapsed_lv6=@collapsed_lv4+1 - node4 - elsif node3 - warning_incorrect_parent_level_or_level(dob.obj) - document_structure_check_info(node6,node3,:error) - @collapsed_lv6=@collapsed_lv3+1 - node3 - elsif node2 - warning_incorrect_parent_level_or_level(dob.obj) - document_structure_check_info(node6,node2,:error) - @collapsed_lv6=@collapsed_lv2+1 - node2 - elsif node1 - warning_incorrect_parent_level_or_level(dob.obj) - document_structure_check_info(node6,node1,:error) - @collapsed_lv6=@collapsed_lv1+1 - node1 - else - document_structure_check_info(node6,node0,:error) - node0 - end - collapsed_level=@collapsed_lv6 - node,ocn_sp=node6,"h#{ocnh}" - end - else - if not dob.obj =~/~#|-#/ - ocn_flag=true - else - ocn_flag=false - end - ocno+=1 - if dob.is==:table - ocnt+=1 - ocn_sp,parent="t#{ocnt}",node - elsif dob.is==:code - ocnc+=1 - ocn_sp,parent="c#{ocnc}",node - elsif dob.is==:group \ - || dob.is==:block \ - || dob.is==:alt \ - || dob.is==:verse - ocng+=1 #group, poem - ocn_sp,parent="g#{ocng}",node - elsif dob.is==:image #check - ocni+=1 - ocn_sp,parent="i#{ocni}",node - else ocnp+=1 #paragraph - ocn_sp,parent="p#{ocnp}",node - end - end - if dob.is==:heading - if ocn_flag==true - dob.ln,dob.node,dob.ocn,dob.ocn_,dob.odv,dob.osp,dob.parent,dob.lc=ln,node,ocn,ocn_flag,ocn_dv,ocn_sp,parent,collapsed_level - else - ocnu+=1 - dob.obj=dob.obj.gsub(/#{Mx[:fa_o]}[~-]##{Mx[:fa_c]}/,'') if dob.obj - ocn_dv,ocn_sp="u#{ocnu}","u#{ocnu}" - dob.ln,dob.node,dob.ocn,dob.ocn_,dob.odv,dob.osp,dob.parent,dob.lc=ln,node,nil,ocn_flag,ocn_dv,ocn_sp,parent,collapsed_level - end - else - if dob.of !=:meta \ - && dob.of !=:comment \ - && dob.of !=:layout - if ocn_flag == true - dob.ocn,dob.ocn_,dob.odv,dob.osp,dob.parent=ocn,ocn_flag,ocn_dv,ocn_sp,parent - else - ocnu+=1 - dob.obj=dob.obj.gsub(/#{Mx[:fa_o]}[~-]##{Mx[:fa_c]}/,'') if dob.obj - ocn_dv,ocn_sp="u#{ocnu}","u#{ocnu}" - dob.ocn,dob.ocn_,dob.odv,dob.osp,dob.parent=nil,ocn_flag,ocn_dv,ocn_sp,parent - end - end - end - h - elsif dob.obj=~/#{Mx[:pa_non_object_no_heading]}/ - dob.obj=dob.obj.gsub(/#{Mx[:pa_non_object_no_heading]}/,'') - if dob.is==:para - h={ obj: dob.obj, ocn_: false, ocn: nil, hang: dob.hang, indent: dob.indent, bullet_: dob.bullet_, tags: dob.tags, parent: dob.parent } - dob=SiSU_DAL_DocumentStructure::ObjectPara.new.paragraph(h,dob) - elsif dob.is==:heading - h={ obj: dob.obj, ocn_: false, ocn: nil, toc_: true, parent: dob.parent } - dob=SiSU_DAL_DocumentStructure::ObjectHeading.new.heading(h,dob) - end - elsif dob.obj=~/#{Mx[:pa_non_object_dummy_heading]}/ - dob.obj=dob.obj.gsub(/#{Mx[:pa_non_object_dummy_heading]}/,'') - if dob.is==:para - h={ obj: dob.obj, ocn_: false, ocn: nil, hang: dob.hang, indent: dob.indent, bullet_: dob.bullet_, tags: dob.tags, parent: dob.parent } - dob=SiSU_DAL_DocumentStructure::ObjectPara.new.paragraph(h,dob) - elsif dob.is==:heading - h={ obj: dob.obj, ocn_: false, ocn: nil, toc_: false, parent: dob.parent } - dob=SiSU_DAL_DocumentStructure::ObjectHeading.new.heading(h,dob) - end - else dob - end - if dob.is==:code \ - || dob.is==:verse \ - || dob.is==:alt \ - || dob.is==:group \ - || dob.is==:block - dob.obj=dob.obj.gsub(/\n\n/,"\n") #newlines taken out - end - @o_array << dob - end - @o_array - end - end - class XML - def initialize(md,data) - @data,@md=data,md - end - def dom - @s=['0', - 'A', - 'B', - 'C', - '1', - '2', - '3' - ] - @sp=' ' - tuned_file=structure_build - tuned_file - end - def structure_build - data=@data - tuned_file=[] - hs=[0,false,false,false] - t={ lv: @s[0], status: 'open' } - tuned_file << tags(t) - if @md.opt.act[:verbose_plus][:set]==:on - puts "\nXML sisu structure outline --->\n" - puts "<#{@s[0]}>" - end - data.each_with_index do |o,i| - if o.is==:heading \ - || o.is==:heading_insert - case o.ln - when 1 - 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=[1,true,false,false] - when 2 - 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=[2,true,true,false] - when 3 - 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=[3,true,true,true] - when 4 - 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]=4 - when 5 - 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]=5 - when 6 - 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]=6 - end - end - tuned_file << o - end - if @md.opt.act[:verbose_plus][:set]==:on - puts_tag_close(0,hs) - end - tuned_file << tag_close(0,hs) - tuned_file=tuned_file.flatten - end - def tags(o) - tag=(o[:status]=='open') \ - ? %{<#{o[:lv]} id="#{o[:node]}">} - : "" - 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 - end - h={ tag: tag, node: o[:node], lv: o[:lv], ln: ln, status: o[:status] } - SiSU_DAL_DocumentStructure::ObjectStructure.new.xml_dom(h) #downstream code utilise else ignore like comments - end - def tag_open(o,tag) - t={ lv: tag[o.ln], node: o.node, status: 'open' } - t_o=tags(t) - t_o - end - def tag_close(lev,hs) - ary=[] - case hs[0] - when 1 - if (lev <= 1) and hs[1] - t={ lv: @s[1], status: 'close' } - ary << tags(t) - end - if (lev==0) - t={ lv: @s[0], status: 'close' } - ary << tags(t) - end - when 2 - if (lev <= 2) and hs[2] - t={ lv: @s[2], status: 'close' } - ary << tags(t) - end - if (lev <= 1) and hs[1] - t={ lv: @s[1], status: 'close' } - ary << tags(t) - end - if (lev==0) - t={ lv: @s[0], status: 'close' } - ary << tags(t) - end - when 3 - if (lev <= 3) and hs[3] - t={ lv: @s[3], status: 'close' } - ary << tags(t) - end - if (lev <= 2) and hs[2] - t={ lv: @s[2], status: 'close' } - ary << tags(t) - end - if (lev <= 1) and hs[1] - t={ lv: @s[1], status: 'close' } - ary << tags(t) - end - if (lev==0) - t={ lv: @s[0], status: 'close' } - ary << tags(t) - end - when 4 - if (lev <= 4) - t={ lv: @s[4], status: 'close' } - ary << tags(t) - end - if (lev <= 3) and hs[3] - t={ lv: @s[3], status: 'close' } - ary << tags(t) - end - if (lev <= 2) and hs[2] - t={ lv: @s[2], status: 'close' } - ary << tags(t) - end - if (lev <= 1) and hs[1] - t={ lv: @s[1], status: 'close' } - ary << tags(t) - end - if (lev==0) - t={ lv: @s[0], status: 'close' } - ary << tags(t) - end - when 5 - if (lev <= 5) - t={ lv: @s[5], status: 'close' } - ary << tags(t) - end - if (lev <= 4) - t={ lv: @s[4], status: 'close' } - ary << tags(t) - end - if (lev <= 3) and hs[3] - t={ lv: @s[3], status: 'close' } - ary << tags(t) - end - if (lev <= 2) and hs[2] - t={ lv: @s[2], status: 'close' } - ary << tags(t) - end - if (lev <= 1) and hs[1] - t={ lv: @s[1], status: 'close' } - ary << tags(t) - end - if (lev==0) - t={ lv: @s[0], status: 'close' } - ary << tags(t) - end - when 6 - if (lev <= 6) - t={ lv: @s[6], status: 'close' } - ary << tags(t) - end - if (lev <= 5) - t={ lv: @s[5], status: 'close' } - ary << tags(t) - end - if (lev <= 4) - t={ lv: @s[4], status: 'close' } - ary << tags(t) - end - if (lev <= 3) and hs[3] - t={ lv: @s[3], status: 'close' } - ary << tags(t) - end - if (lev <= 2) and hs[2] - t={ lv: @s[2], status: 'close' } - ary << tags(t) - end - if (lev <= 1) and hs[1] - t={ lv: @s[1], status: 'close' } - ary << tags(t) - end - if (lev==0) - t={ lv: @s[0], status: 'close' } - ary << tags(t) - end - end - ary - end - def puts_tag_open(o,tag) - puts %{#{@sp*o.ln}<#{tag[o.ln]} id="#{o.node}">} - end - def puts_tag_close(lev,hs) - case hs[0] - when 1 - puts "#{@sp*1}" if (lev <= 1) and hs[1] - puts "" if (lev==0) - when 2 - puts "#{@sp*2}" if (lev <= 2) and hs[2] - puts "#{@sp*1}" if (lev <= 1) and hs[1] - puts "" if (lev==0) - when 3 - puts "#{@sp*3}" if (lev <= 3) and hs[3] - puts "#{@sp*2}" if (lev <= 2) and hs[2] - puts "#{@sp*1}" if (lev <= 1) and hs[1] - puts "" if (lev==0) - when 4 - puts "#{@sp*4}" if (lev <= 4) - puts "#{@sp*3}" if (lev <= 3) and hs[3] - puts "#{@sp*2}" if (lev <= 2) and hs[2] - puts "#{@sp*1}" if (lev <= 1) and hs[1] - puts "" if (lev==0) - when 5 - puts "#{@sp*5}" if (lev <= 5) - puts "#{@sp*4}" if (lev <= 4) - puts "#{@sp*3}" if (lev <= 3) and hs[3] - puts "#{@sp*2}" if (lev <= 2) and hs[2] - puts "#{@sp*1}" if (lev <= 1) and hs[1] - puts "" if (lev==0) - when 6 - puts "#{@sp*6}" if (lev <= 6) - puts "#{@sp*5}" if (lev <= 5) - puts "#{@sp*4}" if (lev <= 4) - puts "#{@sp*3}" if (lev <= 3) and hs[3] - puts "#{@sp*2}" if (lev <= 2) and hs[2] - puts "#{@sp*1}" if (lev <= 1) and hs[1] - puts "" if (lev==0) - end - end - end -end -__END__ diff --git a/lib/sisu/v5/dal_endnotes.rb b/lib/sisu/v5/dal_endnotes.rb deleted file mode 100644 index 839691da..00000000 --- a/lib/sisu/v5/dal_endnotes.rb +++ /dev/null @@ -1,128 +0,0 @@ -# encoding: utf-8 -=begin - - * Name: SiSU - - * Description: a framework for document structuring, publishing and search - - * 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. - - * 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 . - - If you have Internet connection, the latest version of the GPL should be - available at these locations: - - - - - - * SiSU uses: - * Standard SiSU markup syntax, - * Standard SiSU meta-markup syntax, and the - * Standard SiSU object citation numbering and system - - * Hompages: - - - - * Download: - - - * Git - - - - * Ralph Amissah - - - - ** Description: system environment, resource control and configuration details - -=end -module SiSU_DAL_Endnotes - class Endnotes - def initialize(md,data,endnote_array=nil) - @md,@data,@endnote_array=md,data,endnote_array - @endnote_counter,@endnote_counter_asterisk,@endnote_counter_dag=1,1,1 - end - def endnotes - data=@data - @tuned_file=[] - endnote_ref=1 - data.each do |dob| - # manually numbered endnotes --> - if @md.opt.mod.inspect =~/--no-asterisk|--no-annotate/ - dob.obj=dob.obj.gsub(/#{Mx[:en_b_o]}\s.+?#{Mx[:en_b_c]}/,'') - end - if @md.opt.mod.inspect =~/--no-dagger|--no-annotate/ - dob.obj=dob.obj.gsub(/#{Mx[:en_b_o]}[+]\s.+?#{Mx[:en_b_c]}/,'') - end - if (defined? dob.obj) \ - && (defined? dob.is) \ - && dob.is !=:code - case dob.obj # auto-numbered endnotes --> - when /#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}[*+]\s+.+?#{Mx[:en_b_c]}/ - dob.obj=dob.obj.gsub(/\s*(#{Mx[:en_a_c]}|#{Mx[:en_b_c]})/,'\1') - word_mode=dob.obj.scan(/\S+/m) - word_mode=endnote_call_number(word_mode) - dob.obj=word_mode.join(' ') - endnote_ref+=1 - when /~\^(?:\s|$)|<:e>/ #%note inserts endnotes previously gathered from /^(|[-~]\{{3})/ (in earlier loop) - word_mode=dob.obj.scan(/\S+/m) - word_mode=endnote_call_number(word_mode) - dob.obj=word_mode.join(' ') - endnote_ref+=1 - end - end - @tuned_file << dob - end - @endnote_counter,@endnote_counter_asterisk,@endnote_counter_dag=1,1,1 - @tuned_file=@tuned_file.flatten - end - def endnote_call_number(words) - words.each do |word| - case word - when /#{Mx[:en_a_o]}/ - unless word =~/#{Mx[:en_a_o]}[*+]+/ - word.gsub!(/#{Mx[:en_a_o]}/,"#{Mx[:en_a_o]}#{@endnote_counter} ") - @endnote_counter+=1 - end - when /#{Mx[:en_b_o]}/ - if word =~/#{Mx[:en_b_o]}[+]/ - word.gsub!(/#{Mx[:en_b_o]}[+]/,"#{Mx[:en_b_o]}\+#{@endnote_counter_dag} ") - @endnote_counter_dag+=1 - else - word.gsub!(/#{Mx[:en_b_o]}[*]?/,"#{Mx[:en_b_o]}\*#{@endnote_counter_asterisk} ") - @endnote_counter_asterisk+=1 - end - when /~\^|<:e>/ - if @endnote_array - word.gsub!(/~\^|<:e>/,"#{@endnote_array[@endnote_counter-1]}") - @endnote_counter+=1 - end - end - end - end - end -end -__END__ diff --git a/lib/sisu/v5/dal_expand_insertions.rb b/lib/sisu/v5/dal_expand_insertions.rb deleted file mode 100644 index e43dd3af..00000000 --- a/lib/sisu/v5/dal_expand_insertions.rb +++ /dev/null @@ -1,450 +0,0 @@ -# encoding: utf-8 -=begin - - * Name: SiSU - - * Description: a framework for document structuring, publishing and search - - * 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. - - * 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 . - - If you have Internet connection, the latest version of the GPL should be - available at these locations: - - - - - - * SiSU uses: - * Standard SiSU markup syntax, - * Standard SiSU meta-markup syntax, and the - * Standard SiSU object citation numbering and system - - * Hompages: - - - - * Download: - - - * Git - - - - * Ralph Amissah - - - - ** Description: system environment, resource control and configuration details - -=end -module SiSU_DAL_Insertions - class Insertions - def initialize(md,data) - @md,@data=md,data - end - def output_filetypes_in_cmd(cmd_shortcut,lnk=nil) #make list of file types in shortcut command (as configured), e.g. when sisu -3 is used - cf_defaults=SiSU_Env::InfoProcessingFlag.new - cmd_list=case cmd_shortcut.inspect - when /0/; cf_defaults.cf_0 - when /1/; cf_defaults.cf_1 - when /2/; cf_defaults.cf_2 - when /3/; cf_defaults.cf_3 - when /4/; cf_defaults.cf_4 - when /5/; cf_defaults.cf_5 - end - file_type_names={} - file_type_names[:gen],file_type_names[:src]=[],[] - file_type_names[:gen] <<= if cmd_list =~ /y/ then "~^ { document manifest }#{lnk[:manifest]}" - end - file_type_names[:gen] <<= if cmd_list =~ /h/ then [" { html, segmented text }#{lnk[:html_toc]}"," { html, scroll, document in one }#{lnk[:html_doc]}"] - end - file_type_names[:gen] <<= if cmd_list =~ /e/ then [" { epub }#{lnk[:epub]}"] - end - file_type_names[:gen] <<= if cmd_list =~ /p/ then [" { pdf, landscape }#{lnk[:pdf_landscape]}"," { pdf, portrait }#{lnk[:pdf_portrait]}"] - end - file_type_names[:gen] <<= if cmd_list =~ /o/ then " { odf:odt, open document text }#{lnk[:odt]}" - end - file_type_names[:gen] <<= if cmd_list =~ /b/ then " { xhtml scroll }#{lnk[:xhtml]}" - end - file_type_names[:gen] <<= if cmd_list =~ /x/ then " { xml, sax }#{lnk[:xml_sax]}" - end - file_type_names[:gen] <<= if cmd_list =~ /X/ then " { xml, dom }#{lnk[:xml_dom]}" - end - file_type_names[:gen] <<= if cmd_list =~ /a/ then " { plain text utf-8 }#{lnk[:txt]}" - end - file_type_names[:gen] <<= if cmd_list =~ /g/ then 'wiki.txt' - end - file_type_names[:gen] <<= if cmd_list =~ /w/ then " { concordance }#{lnk[:html_concordance]}" - end - file_type_names[:gen] <<= if cmd_list =~ /N/ then " { dcc, document content certificate (digests) }#{lnk[:digest]}" - end - file_type_names[:src] <<= if source and cmd_shortcut =~ /s/ then " { markup source text }#{lnk[:source]}" - end - file_type_names[:src] <<= if cmd_shortcut =~ /S/ then " { markup source (zipped) pod }#{lnk[:sisupod]}" - end - file_type_names[:gen]=file_type_names[:gen].flatten - file_type_names[:src]=file_type_names[:src].flatten - file_type_names - end - def by_language(linked_doc,lng,src=nil) - @linked_doc,@lng,@src=linked_doc,lng,src - @base_path="#{@md.file.output_path.base.url}/#{lng}" - def fnh - { - fn: @linked_doc, - } - end - def path_and_file(fn,pth) - "#{@base_path}/#{pth}/#{fn}" - end - def manifest - fn=@md.file.base_filename.manifest(fnh) - path_and_file(fn,'manifest') - end - def html_toc - fn=@md.file.base_filename.html_segtoc(fnh) - "#{@base_path}/html/#{@linked_doc}/#{fn}" - end - def html_doc - fn=@md.file.base_filename.html_scroll(fnh) - path_and_file(fn,'html') - end - def html_concordance - fn=@md.file.base_filename.html_concordance - "#{@base_path}/html/#{@linked_doc}/#{fn}" - end - def epub - fn=@md.file.base_filename.epub(fnh) - path_and_file(fn,'epub') - end - def pdf_landscape - fn=@md.file.base_filename.pdf_l_a4(fnh) - path_and_file(fn,'pdf') - end - def pdf_portrait - fn=@md.file.base_filename.pdf_p_a4(fnh) - path_and_file(fn,'pdf') - end - def odt - fn=@md.file.base_filename.odt(fnh) - path_and_file(fn,'odt') - end - def xhtml - fn=@md.file.base_filename.xhtml(fnh) - path_and_file(fn,'xhtml') - end - def xml_sax - fn=@md.file.base_filename.xml_sax(fnh) - path_and_file(fn,'xml_sax') - end - def xml_dom - fn=@md.file.base_filename.xml_dom(fnh) - path_and_file(fn,'xml_dom') - end - def txt - fn=@md.file.base_filename.txt(fnh) - path_and_file(fn,'txt') - end - def digest - fn=@md.file.base_filename.hash_digest(fnh) - path_and_file(fn,'digest') - end - def source - "#{@base_path}/src/#{@src}" - end - def sisupod - "#{@base_path}/src/#{@src}.zip" - end - self - end - def by_filetype(linked_doc,lng,src=nil) - @linked_doc,@lng,@src=linked_doc,lng,src - @lc=SiSU_Env::FilenameLanguageCodeInsert.new(@md.opt,lng).language_code_insert - @base_path="#{@md.file.output_path.base.url}" - def fnh - { - fn: @linked_doc, - lng: @lc, - } - end - def path_and_file(fn,pth) - "#{@base_path}/#{pth}/#{fn}" - end - def manifest - fn=@md.file.base_filename.manifest(fnh) - path_and_file(fn,'manifest') - end - def html_toc - fn=@md.file.base_filename.html_segtoc(fnh) - path_and_file(fn,'html') - end - def html_doc - fn=@md.file.base_filename.html_scroll(fnh) - path_and_file(fn,'html') - end - def html_concordance - fn=@md.file.base_filename.html_concordance - path_and_file(fn,'html') - end - def epub - fn=@md.file.base_filename.epub(fnh) - path_and_file(fn,'epub') - end - def pdf_landscape - fn=@md.file.base_filename.pdf_l_a4(fnh) - path_and_file(fn,'pdf') - end - def pdf_portrait - fn=@md.file.base_filename.pdf_p_a4(fnh) - path_and_file(fn,'pdf') - end - def odt - fn=@md.file.base_filename.odt(fnh) - path_and_file(fn,'odt') - end - def xhtml - fn=@md.file.base_filename.xhtml(fnh) - path_and_file(fn,'xhtml') - end - def xml_sax - fn=@md.file.base_filename.xml_sax(fnh) - path_and_file(fn,'xml_sax') - end - def xml_dom - fn=@md.file.base_filename.xml_dom(fnh) - path_and_file(fn,'xml_dom') - end - def txt - fn=@md.file.base_filename.txt(fnh) - path_and_file(fn,'txt') - end - def digest - fn=@md.file.base_filename.hash_digest(fnh) - path_and_file(fn,'digest') - end - def source - "#{@base_path}/src/#{@src}" - end - def sisupod - "#{@base_path}/src/#{@src}.zip" - end - self - end - def by_filename(linked_doc,lng,src=nil) - @linked_doc,@lng,@src=linked_doc,lng,src - @lc=SiSU_Env::FilenameLanguageCodeInsert.new(@md.opt,lng).language_code_insert - @base_path="#{@md.file.output_path.base.url}/#{@linked_doc}" - def fnh - { - fn: @linked_doc, - lng: @lc, - } - end - def path_and_file(fn,pth=nil) - (pth.nil?) \ - ? "#{@base_path}/#{fn}" - : "#{@base_path}/#{pth}/#{fn}" - end - def manifest - fn=@md.file.base_filename.manifest(fnh) - path_and_file(fn) - end - def html_toc - fn=@md.file.base_filename.html_segtoc(fnh) - path_and_file(fn) - end - def html_doc - fn=@md.file.base_filename.html_scroll(fnh) - path_and_file(fn) - end - def html_concordance - fn=@md.file.base_filename.html_concordance - path_and_file(fn) - end - def epub - fn=@md.file.base_filename.epub(fnh) - path_and_file(fn,'epub') - end - def pdf_landscape - fn=@md.file.base_filename.pdf_l_a4(fnh) - path_and_file(fn) - end - def pdf_portrait - fn=@md.file.base_filename.pdf_p_a4(fnh) - path_and_file(fn) - end - def odt - fn=@md.file.base_filename.odt(fnh) - path_and_file(fn) - end - def xhtml - fn=@md.file.base_filename.xhtml(fnh) - path_and_file(fn) - end - def xml_sax - fn=@md.file.base_filename.xml_sax(fnh) - path_and_file(fn) - end - def xml_dom - fn=@md.file.base_filename.xml_dom(fnh) - path_and_file(fn) - end - def txt - fn=@md.file.base_filename.txt(fnh) - path_and_file(fn) - end - def digest - fn=@md.file.base_filename.hash_digest(fnh) - path_and_file(fn) - end - def source - "#{@base_path}/#{@src}" - end - def sisupod - "#{@base_path}/#{@src}.zip" - end - self - end - def expand_insertions? - data=@data - tuned_file,tuned_file_tmp=[],[] - codeblock_=false - data.each do |para| - codeblock_=if para =~/^(?:code\{|[`]{3}\s+code)/ - true - elsif para =~/^(?:\}code|[`]{3}(?:\s|$))/m - false - else codeblock_ - end - if para !~/^%+\s/ \ - and not codeblock_ \ - and para =~/\{(?:~\^\s+)?(.+?)\s\[(?:\d(?:[sS]*))\]\}(?:\.\.\/\S+?\/|\S+?\.ss[tm]\b)/ - manifest=nil - @u=SiSU_Env::InfoEnv.new.url - m_cmd='' - if defined? @u.remote - if /(?.+?)\{(?.+?)\s\[(?\d[sS]*)\]\}(?(?\S+?)\.ss[tm]\b)(?.*)/m =~ para - m_pre=m_pre.strip - elsif /\{(?.+?)\s\[(?\d[sS]*)\]\}(?(?\S+?)\.ss[tm]\b)(?.*)/m =~ para - end - if m_linked_doc =~ /(\S+?)\/(\S+)/ - m_linked_doc,m_linked_doc_lang=$1,$2 - else - m_linked_doc,m_linked_doc_lang=m_linked_doc,@md.opt.lng_base - end - else - puts "error, does currently support relative paths (reltive paths were removed, as had problems for citation, and was not suited to all output types should possibly reconsider) #{__FILE__} #{__LINE__}" - if /\{(?:~\^\s+)?(?.+?)\s\[(?\d[sS]*)\]\}\.\.\/(?\S+?)\/(?\s+#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]})?/ =~ para - end - end - lnk=case @md.opt.dir_structure_by - when :language - { - manifest: by_language(m_linked_doc,m_linked_doc_lang).manifest, - html_toc: by_language(m_linked_doc,m_linked_doc_lang).html_toc, - html_doc: by_language(m_linked_doc,m_linked_doc_lang).html_doc, - epub: by_language(m_linked_doc,m_linked_doc_lang).epub, - pdf_landscape: by_language(m_linked_doc,m_linked_doc_lang).pdf_landscape, - pdf_portrait: by_language(m_linked_doc,m_linked_doc_lang).pdf_landscape, - odt: by_language(m_linked_doc,m_linked_doc_lang).odt, - xhtml: by_language(m_linked_doc,m_linked_doc_lang).xhtml, - xml_sax: by_language(m_linked_doc,m_linked_doc_lang).xml_sax, - xml_dom: by_language(m_linked_doc,m_linked_doc_lang).xml_dom, - txt: by_language(m_linked_doc,m_linked_doc_lang).txt, - html_concordance: by_language(m_linked_doc,m_linked_doc_lang).html_concordance, - digest: by_language(m_linked_doc,m_linked_doc_lang).digest, - sisupod: by_language(m_linked_doc,m_linked_doc_lang,m_source).sisupod, - source: by_language(m_linked_doc,m_linked_doc_lang,m_source).source, - } - when :filetype - { - manifest: by_filetype(m_linked_doc,m_linked_doc_lang).manifest, - html_toc: by_filetype(m_linked_doc,m_linked_doc_lang).html_toc, - html_doc: by_filetype(m_linked_doc,m_linked_doc_lang).html_doc, - epub: by_filetype(m_linked_doc,m_linked_doc_lang).epub, - pdf_landscape: by_filetype(m_linked_doc,m_linked_doc_lang).pdf_landscape, - pdf_portrait: by_filetype(m_linked_doc,m_linked_doc_lang).pdf_landscape, - odt: by_filetype(m_linked_doc,m_linked_doc_lang).odt, - xhtml: by_filetype(m_linked_doc,m_linked_doc_lang).xhtml, - xml_sax: by_filetype(m_linked_doc,m_linked_doc_lang).xml_sax, - xml_dom: by_filetype(m_linked_doc,m_linked_doc_lang).xml_dom, - txt: by_filetype(m_linked_doc,m_linked_doc_lang).txt, - html_concordance: by_filetype(m_linked_doc,m_linked_doc_lang).html_concordance, - digest: by_filetype(m_linked_doc,m_linked_doc_lang).digest, - sisupod: by_filetype(m_linked_doc,m_linked_doc_lang,m_source).sisupod, - source: by_filetype(m_linked_doc,m_linked_doc_lang,m_source).source, - } - else - { - manifest: by_filename(m_linked_doc,m_linked_doc_lang).manifest, - html_toc: by_filename(m_linked_doc,m_linked_doc_lang).html_toc, - html_doc: by_filename(m_linked_doc,m_linked_doc_lang).html_doc, - epub: by_filename(m_linked_doc,m_linked_doc_lang).epub, - pdf_landscape: by_filename(m_linked_doc,m_linked_doc_lang).pdf_landscape, - pdf_portrait: by_filename(m_linked_doc,m_linked_doc_lang).pdf_landscape, - odt: by_filename(m_linked_doc,m_linked_doc_lang).odt, - xhtml: by_filename(m_linked_doc,m_linked_doc_lang).xhtml, - xml_sax: by_filename(m_linked_doc,m_linked_doc_lang).xml_sax, - xml_dom: by_filename(m_linked_doc,m_linked_doc_lang).xml_dom, - txt: by_filename(m_linked_doc,m_linked_doc_lang).txt, - html_concordance: by_filename(m_linked_doc,m_linked_doc_lang).html_concordance, - digest: by_filename(m_linked_doc,m_linked_doc_lang).digest, - sisupod: by_filename(m_linked_doc,m_linked_doc_lang,m_source).sisupod, - source: by_filename(m_linked_doc,m_linked_doc_lang,m_source).source, - } - end - linked_title="#{m_pre}{#{m_txt} }#{lnk[:manifest]}#{m_note}\n\n" - tuned_file_tmp << linked_title - output_filetypes=output_filetypes_in_cmd(m_cmd,lnk) - output_filetypes[:gen].each do |o_f| - describe = o_f - if describe - tuned_file_tmp << if @u.remote #to double space <:br> at beginning of entry - "#{Mx[:nbsp]*4} #{describe} " - else # remove ... - "[provide document placement host location]" - end - end - end - output_filetypes[:src].each do |o_f| - describe = o_f - if describe - tuned_file_tmp << if @u.remote - "#{Mx[:nbsp]*4} #{describe} " - else - "[provide document placement host location]" - end - end - end - tuned_file << 'group{' << tuned_file_tmp.join("\n") << '}group' - tuned_file_tmp=[] - else tuned_file << para - end - end - tuned_file - end - end -end -__END__ diff --git a/lib/sisu/v5/dal_hash_digest.rb b/lib/sisu/v5/dal_hash_digest.rb deleted file mode 100644 index 9f620aa2..00000000 --- a/lib/sisu/v5/dal_hash_digest.rb +++ /dev/null @@ -1,157 +0,0 @@ -# encoding: utf-8 -=begin - - * Name: SiSU - - * Description: a framework for document structuring, publishing and search - - * 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. - - * 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 . - - If you have Internet connection, the latest version of the GPL should be - available at these locations: - - - - - - * SiSU uses: - * Standard SiSU markup syntax, - * Standard SiSU meta-markup syntax, and the - * Standard SiSU object citation numbering and system - - * Hompages: - - - - * Download: - - - * Git - - - - * Ralph Amissah - - - - ** Description: system environment, resource control and configuration details - -=end -module SiSU_DAL_Hash - require_relative 'shared_markup_alt.rb' #shared_markup_alt.rb - class ObjectDigest - def initialize(md,data,env=nil) - @md,@data,@env=md,data,env - @env ||=SiSU_Env::InfoEnv.new(@md.fns) - end - def object_digest - # 1. clean/stripped text without any markup, paragraph, headings etc. without endnotes - # 2. endnotes clean/stripped text digest only (there may be several endnotes within a paragraph) - # 3. whole object, text with markup and any endnotes, (question: with or without the endnote digests??? presumption better without, [however may be easier to check with?]) - # [digests should not include other digests] - data=@data.compact - @tuned_file=[] - sha_ =(@env.digest.type=='sha256' ? true : false) - sha_ ? (require 'digest/sha2') : (require 'digest/md5') - data.each do |t_o| - unless t_o.obj.is_a?(Array) - t_o.obj=t_o.obj.strip - end - if (t_o.of !=:structure \ - && t_o.of !=:comment \ - && t_o.of !=:layout) \ - && t_o.ocn.is_a?(Fixnum) - if sha_ - for hash_class in [ Digest::SHA256 ] - @tuned_file << stamped(t_o,hash_class) - end - else - for hash_class in [ Digest::MD5 ] - @tuned_file << stamped(t_o,hash_class) - end - end - else @tuned_file << t_o unless t_o.nil? - end - end - @tuned_file=@tuned_file.flatten - #use md5 or to create hash of each dal object including ocn, & add into to each dal object - end - def endnote_digest(data) - t_o_bit=[] - data.each do |en_plus| - t_o_bit <<= case en_plus - when /#{Mx[:en_a_o]}|#{Mx[:en_b_o]}/ - if en_plus =~/#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]}/ - t_o_txt,en_open,en_txt,en_close=/(.*?)(#{Mx[:en_a_o]}|#{Mx[:en_b_o]})(.+?)(#{Mx[:en_a_c]}|#{Mx[:en_b_c]})/m.match(en_plus)[1..4] - stripped_en=SiSU_TextRepresentation::Alter.new(en_txt).strip_clean_of_markup - digest_en_strip=if @env.digest.type =~/sha256/ - Digest::SHA256.hexdigest(stripped_en) - else - Digest::MD5.hexdigest(stripped_en) - end - t_o_txt + en_open + en_txt + Mx[:id_o] + digest_en_strip + Mx[:id_c] + en_close - else STDERR.puts "Error Exception - problem encountered with:\n#{en_plus}" #arbitrary exception, tidy up - end - else en_plus - end - end - t_o_bit.join - end - def stamped(t_o,hash_class) #decide what hash information is most useful, is compromise necessary? - t_o.obj=SiSU_TextRepresentation::Alter.new(t_o).strip_clean_of_extra_spaces - #SiSU_TextRepresentation::Alter.new(t_o).strip_clean_of_markup #check - #SiSU_TextRepresentation::Alter.new(t_o).semi_revert_markup #check - #SiSU_TextRepresentation::ModifiedTextPlusHashDigest.new(@md,t_o).composite.dgst #check - unless t_o.is==:code - case t_o.obj - when /#{Mx[:en_a_o]}[\d*+]+\s+.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}[*+]\d+\s+.+?#{Mx[:en_b_c]}/m - en_and_t_o_digest=[] - t_o.obj=t_o.obj.gsub(/\s*(#{Mx[:en_a_c]}|#{Mx[:en_b_c]})/m,' \1') #watch - t_o_plus_en=t_o.obj.scan(/.*?#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|.*?#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]}/m) - t_o_tail=if t_o.obj =~/(?:.*?#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|.*?#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]})+([\s\S]+)/m - /(?:.*?#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|.*?#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]})+.*/m.match(t_o.obj)[1] - else '' - end - t_o_plus_en << t_o_tail - en_and_t_o_digest << endnote_digest(t_o_plus_en) - en_and_t_o_digest.join(' ') - else #@tuned << t_o + Mx[:id_o] + digest_strip + ':' + digest_all + Mx[:id_c] unless t_o.nil? - end - else #@tuned << t_o + Mx[:id_o] + digest_strip + ':' + digest_all + Mx[:id_c] unless t_o.nil? - end - t_o #KEEP intact - end - def strip_clean_extra_spaces(s) # dal output tuned - s=s.dup - s=s.gsub(/[ ]+([,.;:?](?:$|\s))/,'\1') unless s =~/#{Mx[:en_a_o]}|#{Mx[:en_b_o]}/ - s=s.gsub(/ [ ]+/,' '). - gsub(/^ [ ]+/,''). - gsub(/ [ ]+$/,''). - gsub(/((?:#{Mx[:fa_bold_c]}|#{Mx[:fa_italics_c]})')[ ]+(s )/,'\1\2'). - gsub(/((?:#{Mx[:fa_bold_c]}|#{Mx[:fa_italics_c]})')[ ]+(s )/,'\1\2') - end - end -end -__END__ diff --git a/lib/sisu/v5/dal_idx.rb b/lib/sisu/v5/dal_idx.rb deleted file mode 100644 index be8a0211..00000000 --- a/lib/sisu/v5/dal_idx.rb +++ /dev/null @@ -1,326 +0,0 @@ -# encoding: utf-8 -=begin - - * Name: SiSU - - * Description: a framework for document structuring, publishing and search - - * 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. - - * 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 . - - If you have Internet connection, the latest version of the GPL should be - available at these locations: - - - - - - * SiSU uses: - * Standard SiSU markup syntax, - * Standard SiSU meta-markup syntax, and the - * Standard SiSU object citation numbering and system - - * Hompages: - - - - * Download: - - - * Git - - - - * Ralph Amissah - - - - ** Description: system environment, resource control and configuration details - -=end -module SiSU_DAL_BookIndex - class BookIndex - def initialize(md,data,env=nil) - @md,@data,@env=md,data,env - @rgx_idx=/#{Mx[:idx_o]}(?:.+?)#{Mx[:idx_c]}\s*/ - @rgx_idx_ocn_seg=/(.+?)~(\d+)~(\S+)/ - @rgx_idx_ocn=/(.+?)~(\d+)/ - @env ||=SiSU_Env::InfoEnv.new(@md.fns) - end - def indexing_song - data=@data - data,sisu_markup_idx_rel,sisu_markup_idx_rel_html_seg,html_idx,xhtml_idx=extract_book_index(data) - data=clean_and_insert_index(data,sisu_markup_idx_rel_html_seg) - [data,sisu_markup_idx_rel,sisu_markup_idx_rel_html_seg,html_idx,xhtml_idx] - end - def extract_book_index(data) - tuned_file=[] - idx_array=[] - data.each do |dob| - if (dob.is ==:heading \ - || dob.is ==:heading_insert) \ - && dob.ln==4 - @seg=dob.name - end - if defined? dob.idx \ - and dob.idx.is_a?(Hash) - idx_array << {idx: dob.idx, ocn: dob.ocn, seg: @seg } - end - tuned_file << dob if dob - end - if idx_array.length > 0 - the_idx=construct_book_index(idx_array) - sisu_markup_idx_rel,sisu_markup_idx_rel_html_seg,html_idx,xhtml_idx=nil,nil,nil,nil - if @md.book_idx - idx=index(the_idx) - sisu_markup_idx_rel,sisu_markup_idx_rel_html_seg,html_idx,xhtml_idx=idx[:sst_rel],idx[:sst_rel_html_seg],idx[:html],idx[:xhtml] - end - end - [tuned_file,sisu_markup_idx_rel,sisu_markup_idx_rel_html_seg,html_idx,xhtml_idx] - end - def construct_book_index(idx_array) - the_idx={} - idx_array.each do |idx| - idx[:idx].each_pair do |term,term_info| - location=(term_info[:plus].to_i > 0) \ - ? (%{#{idx[:ocn]}-#{idx[:ocn].to_i + term_info[:plus].to_i}}) - : idx[:ocn].to_s - the_idx[term]={} unless the_idx[term] and defined? the_idx[term] - the_idx[term]['node_0_terms']=[] unless the_idx[term]['node_0_terms'] and defined? the_idx[term]['node_0_terms'] - the_idx[term]['node_0_terms'] << { ocn: idx[:ocn], range: location, seg: idx[:seg] } - if term_info[:sub].is_a?(Array) \ - and term_info[:sub].length > 0 - term_info[:sub].each do |y| - y.each_pair do |subterm,subterm_info| - location=(subterm_info[:plus].to_i > 0) \ - ? (%{#{idx[:ocn]}-#{idx[:ocn].to_i + subterm_info[:plus].to_i}}) - : idx[:ocn].to_s - the_idx[term]={} unless the_idx[term] and defined? the_idx[term] - the_idx[term]['node_0_terms']=[] unless the_idx[term]['node_0_terms'] and defined? the_idx[term]['node_0_terms'] - the_idx[term]['node_1_subterms']={} unless the_idx[term]['node_1_subterms'] and defined? the_idx[term]['node_1_subterms'] - the_idx[term]['node_1_subterms'][subterm]=[] unless the_idx[term]['node_1_subterms'][subterm] and defined? the_idx[term]['node_1_subterms'][subterm] - the_idx[term]['node_1_subterms'][subterm] << { ocn: idx[:ocn], range: location, seg: idx[:seg] } - end - end - end - end - end - the_idx=the_idx.sort - the_idx - end - def clean_xml(str) - str=str.gsub(/&/,'&') - str - end - def index(the_idx) - @x=1 - idx={} - idx[:sst_rel_html_seg],idx[:sst_rel],idx[:html],idx[:xhtml]=[],[],[],[] - h={obj: Mx[:br_page]} - o=SiSU_DAL_DocumentStructure::ObjectLayout.new.break(h) - idx[:sst_rel_html_seg] << o - idx[:sst_rel] << o - h={lv: '2', name: 'index', obj: "Index"} - o=SiSU_DAL_DocumentStructure::ObjectHeading.new.heading(h) - idx[:sst_rel_html_seg] << o - idx[:sst_rel] << o - h={lv: '4', name: 'idx', obj: " [Index] #{Mx[:pa_non_object_dummy_heading]}"} - o=SiSU_DAL_DocumentStructure::ObjectHeading.new.heading(h) - idx[:sst_rel_html_seg] << o - idx[:sst_rel] << o - alph=%W[9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z] - idx[:html] << '

' - idx[:xhtml] << '

' - alph.each do |x| - if x =~/[0-9]/ - idx[:html] << '' - idx[:xhtml] << '' - else - idx[:html] << %{#{x},#{$ep[:hsp]}} - idx[:xhtml] << %{#{x},#{$ep[:hsp]}} - end - end - idx[:html] << '

' - idx[:xhtml] << '

' - letter=alph.shift - idx[:html] << %{\n

} - idx[:xhtml] << %{\n

0 - 9

} - the_idx.each do |i| - i.each do |x| - if x.is_a?(String) - f=/^(\S)/.match(x)[1] - if letter < f - while letter < f - if alph.length > 0 - letter=alph.shift - idx[:html] << %{\n

#{letter}

} - idx[:xhtml] << %{\n

#{letter}

} - else break - end - end - end - idx[:sst_rel_html_seg] << %{\n\n#{Mx[:fa_bold_o]}#{x},#{Mx[:fa_bold_c]} } - idx[:sst_rel] << %{\n\n#{Mx[:fa_bold_o]}#{x},#{Mx[:fa_bold_c]} } - aname=x.gsub(/\s+/,'_') - idx[:html] << %{\n

#{x}, } - c=clean_xml(x.dup) - idx[:xhtml] << %{\n

#{c}, } - @o=idx[:sst_rel_html_seg].index(idx[:sst_rel_html_seg].last) - @t=idx[:sst_rel].index(idx[:sst_rel].last) - @q=idx[:html].index(idx[:html].last) - @r=idx[:xhtml].index(idx[:xhtml].last) - print "\n" + x + ', ' if @md.opt.act[:verbose_plus][:set]==:on - elsif x.is_a?(Array) - p 'array error? -->' - print x - elsif x.is_a?(Hash) - if x['node_0_terms'].is_a?(Array) - x['node_0_terms'].each do |a| - if a[:range] - idx[:sst_rel_html_seg][@o]=idx[:sst_rel_html_seg][@o] + %{#{Mx[:lnk_o]}#{a[:range]}#{Mx[:lnk_c]}#{Mx[:rel_o]}/#{a[:seg]}.html##{a[:ocn]}#{Mx[:rel_c]}, } - idx[:sst_rel][@t]=idx[:sst_rel][@t] + %{#{Mx[:lnk_o]}#{a[:range]}#{Mx[:lnk_c]}#{Mx[:rel_o]}#{a[:ocn]}#{Mx[:rel_c]}, } - idx[:html][@q]=idx[:html][@q] + %{#{a[:range]}, } - idx[:xhtml][@q]=idx[:xhtml][@q] + %{#{a[:range]}, } - print a[:range] + ', ' if @md.opt.act[:verbose_plus][:set]==:on - elsif a[:ocn] - idx[:sst_rel_html_seg][@o]=idx[:sst_rel_html_seg][@o] + %{#{Mx[:lnk_o]}#{a[:ocn]}#{Mx[:lnk_c]}#{Mx[:rel_o]}#{a[:seg]}.html##{a[:ocn]}#{Mx[:rel_c]}, } - idx[:sst_rel][@t]=idx[:sst_rel][@t] + %{#{Mx[:lnk_o]}#{a[:ocn]}#{Mx[:lnk_c]}#{Mx[:rel_o]}#{a[:ocn]}#{Mx[:rel_c]}, } - idx[:html][@q]=idx[:html][@q] + %{#{a[:ocn]}, } - idx[:xhtml][@q]=idx[:xhtml][@q] + %{#{a[:ocn]}, } - print a[:ocn] + ', ' if @md.opt.act[:verbose_plus][:set]==:on - else p 'error' - end - end - idx[:html][@q]=idx[:html][@q] + '

' - idx[:xhtml][@r]=idx[:xhtml][@r] + '

' - end - if x['node_1_subterms'] - x['node_1_subterms'].sort.each do |k,y| - if k !~/node_0_terms/ - idx[:sst_rel_html_seg][@o]=idx[:sst_rel_html_seg][@o] + %{#{k}, } - idx[:sst_rel][@t]=idx[:sst_rel][@t] + %{#{k}, } - idx[:html][@q]=idx[:html][@q] + %{\n

#{k}, } - c=clean_xml(k.dup) - idx[:xhtml][@r]=idx[:xhtml][@r] + %{\n

#{c}, } - print "\n\t" + k + ', ' if @md.opt.act[:verbose_plus][:set]==:on - y.each do |z| - if z[:range] - idx[:sst_rel_html_seg][@o]=idx[:sst_rel_html_seg][@o] + %{#{Mx[:lnk_o]}#{z[:range]}#{Mx[:lnk_c]}#{Mx[:rel_o]}#{z[:seg]}.html##{z[:ocn]}#{Mx[:rel_c]}, } - idx[:sst_rel][@t]=idx[:sst_rel][@t] + %{#{Mx[:lnk_o]}#{z[:range]}#{Mx[:lnk_c]}#{Mx[:rel_o]}#{z[:ocn]}#{Mx[:rel_c]}, } - idx[:html][@q]=idx[:html][@q] + %{#{z[:range]}, } - idx[:xhtml][@q]=idx[:xhtml][@q] + %{#{z[:range]}, } - print z[:range] + ', ' if @md.opt.act[:verbose_plus][:set]==:on - elsif z[:ocn] - idx[:sst_rel_html_seg][@o]=idx[:sst_rel_html_seg][@o] + %{#{Mx[:lnk_o]}#{z[:ocn]}#{Mx[:lnk_c]}#{Mx[:rel_o]}#{z[:seg]}.html##{z[:ocn]}#{Mx[:rel_c]}, } - idx[:sst_rel][@t]=idx[:sst_rel][@t] + %{#{Mx[:lnk_o]}#{z[:ocn]}#{Mx[:lnk_c]}#{Mx[:rel_o]}#{z[:ocn]}#{Mx[:rel_c]}, } - idx[:html][@q]=idx[:html][@q] + %{#{z[:ocn]}, } - idx[:xhtml][@q]=idx[:xhtml][@q] + %{#{z[:ocn]}, } - print z[:ocn] + ', ' if @md.opt.act[:verbose_plus][:set]==:on - else p 'error' - end - end - idx[:html][@q]=idx[:html][@q] + '

' - idx[:xhtml][@r]=idx[:xhtml][@r] + '

' - end - end - end - @x +=1 - end - end - end - print "\n" if @md.opt.act[:verbose_plus][:set]==:on - idx - end - def screen_print(the_idx) - the_idx.each do |i| - i.each do |x| - if x.is_a?(String) - print "\n" + x + ', ' - elsif x.is_a?(Array) - p 'array error? -->' - print x - elsif x.is_a?(Hash) - if x['node_0_terms'].is_a?(Array) - x['node_0_terms'].each do |a| - if a[:range] - print a[:range] + ', ' - elsif a[:ocn] - print a[:ocn] + ', ' - else p 'error' - end - end - end - if x['node_1_subterms'] - x['node_1_subterms'].sort.each do |k,y| - if k !~/node_0_terms/ - print "\n\t" + k + ', ' - y.each do |z| - if z[:range] - print z[:range] + ', ' - elsif z[:ocn] - print z[:ocn] + ', ' - else p 'error' - end - end - end - end - end - end - end - end - end - def output_idx(idx) - if @md.book_idx - path="#{@env.path.output}/#{@md.fnb}" - Dir.mkdir(path) unless FileTest.directory?(path) - puts "#{path}/#{@md.fn[:book_idx_html]} #{__FILE__}::#{__LINE__}" - html_index_file=File.new("#{path}/#{@md.fn[:book_idx_html]}",'w') - idx[:html].each {|x| html_index_file << x } - html_index_file.close - end - end - def clean_and_insert_index(data,sisu_markup_idx) - tuned_file=[] - data.each do |dob| - tuned_file << dob - if dob.obj =~/#{Mx[:br_endnotes]}/ \ - and sisu_markup_idx - sisu_markup_idx.each do |idx| - tuned_file << idx - end - end - end - tuned_file - end - def clean_index(data) #check on use of dob - tuned_file=[] - data.each do |para| - para=para.gsub(/\n*#{@rgx_idx}/m,'') - tuned_file << para - end - tuned_file - end - end -end -__END__ diff --git a/lib/sisu/v5/dal_images.rb b/lib/sisu/v5/dal_images.rb deleted file mode 100644 index 33a5e627..00000000 --- a/lib/sisu/v5/dal_images.rb +++ /dev/null @@ -1,165 +0,0 @@ -# encoding: utf-8 -=begin - - * Name: SiSU - - * Description: a framework for document structuring, publishing and search - - * 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. - - * 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 . - - If you have Internet connection, the latest version of the GPL should be - available at these locations: - - - - - - * SiSU uses: - * Standard SiSU markup syntax, - * Standard SiSU meta-markup syntax, and the - * Standard SiSU object citation numbering and system - - * Hompages: - - - - * Download: - - - * Git - - - - * Ralph Amissah - - - - ** Description: system environment, resource control and configuration details - -=end -module SiSU_DAL_Images - class Images - #require 'RMagick' - #include Magick - def initialize(md,data) - @md,@data=md,data - end - def images - data=@data - tuned_file=[] - @rmgk=false - imagemagick_=true #imagemagick_=SiSU_Env::InfoSettings.new.program?('rmagick') - if imagemagick_ - begin - @rmgk=SiSU_Env::Load.new('RMagick').prog - rescue - @rmgk=false - end - else - if (@md.opt.act[:verbose][:set]==:on \ - || @md.opt.act[:verbose_plus][:set]==:on \ - || @md.opt.act[:maintenance][:set]==:on) - SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set],'*WARN* use of RMagick is not enabled in sisurc.yml').warn - end - end - data.each do |dob| - unless dob.is ==:table - dob.obj=dob.obj.strip - if dob.obj =~/#{Mx[:lnk_o]}\s*\S+\.(?:png|jpg|gif)(?:\s*|\s+.+)?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|image)/ - if dob.obj !~/#{Mx[:lnk_o]}\s*\S+\.(?:png|jpg|gif)\s+\d+x\d+/ - m=/#{Mx[:lnk_o]}\s*(\S+\.(?:png|jpg|gif))/ - if imagemagick_ - imgs=dob.obj.scan(m).flatten - img_col=img_row=nil - images=imgs.each do |image| - dir=SiSU_Env::InfoEnv.new(@md.fns) - path_image=[dir.path.image_source_include_local,dir.path.image_source_include_remote,dir.path.image_source_include] - image_path=nil - path_image.each do |img_pth| - image_path=img_pth - break if FileTest.exist?("#{img_pth}/#{image}") - end - if FileTest.exist?("#{image_path}/#{image}") - if @rmgk - img=Magick::ImageList.new("#{image_path}/#{image}") - img_col,img_row=img.columns,img.rows - else - if (@md.opt.act[:verbose][:set]==:on \ - || @md.opt.act[:verbose_plus][:set]==:on \ - || @md.opt.act[:maintenance][:set]==:on) - SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set],'*WARN* RMagick not present, will attempt to use imagemagick (identify) directly').warn - end - imgk=SiSU_Env::SystemCall.new.imagemagick - gmgk=SiSU_Env::SystemCall.new.graphicksmagick - if imgk or gmgk - if imgk - imgsys=`identify #{image_path}/#{image}`.strip #system call - elsif gmgk - imgsys=`gm identify #{image_path}/#{image}`.strip #system call - end - img_col,img_row=/(\d+)x(\d+)/m.match(imgsys)[1,2] - img_col,img_row=img_col.to_i,img_row.to_i - end - end - row=((img && defined? img.rows) ? img.rows : img_row) - col=((img && defined? img.columns) ? img.columns : img_col) - if img_col > img_row #landscape - if img_col> 640 - img_col=640 - img_row=((1.00*img_col/col)*row).round - end - else #portrait - if img_col> 640 - img_col=640 - img_row=((1.00*img_col/col)*row).round - end - if img_row > 640 - img_row=640 - img_col=((1.00*img_row/row)*col).round - end - end - dob.obj=dob.obj.gsub(/(#{image})/,"#{image} #{img_col}x#{img_row}") - else dob.obj=dob.obj.gsub(/#{Mx[:lnk_o]}\s*(\S+)\.(png|jpg|gif).+?#{Mx[:lnk_c]}(#{Mx[:url_o]}\S+?#{Mx[:url_c]}|image)/,'[ \1 (\2 missing) ]') - end - end - else - images=dob.obj.scan(m) do |image| - SiSU_Screen::Ansi.new(@md.opt.act[:color_state][:set],'*WARN* where image dimensions have not been provided RMagick or imagemagick is required',image).warn unless @md.opt.act[:quiet][:set]==:on - end - end - end - end - if dob.obj =~/#{Mx[:lnk_o]}\s*\S+\.(?:png|jpg|gif).+?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|image)/ - dob.obj=dob.obj.gsub(/(#{Mx[:lnk_o]})\s*(\S+\.(?:png|jpg|gif))\s+/i,'\1\2 ') - end - end - tuned_file << dob unless dob.nil? - end - tuned_file - end - end -end -__END__ -imgsys=`identify #{image_path}/#{image}`.strip diff --git a/lib/sisu/v5/dal_metadata.rb b/lib/sisu/v5/dal_metadata.rb deleted file mode 100644 index 1fa5619c..00000000 --- a/lib/sisu/v5/dal_metadata.rb +++ /dev/null @@ -1,82 +0,0 @@ -# encoding: utf-8 -=begin - - * Name: SiSU - - * Description: a framework for document structuring, publishing and search - - * 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. - - * 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 . - - If you have Internet connection, the latest version of the GPL should be - available at these locations: - - - - - - * SiSU uses: - * Standard SiSU markup syntax, - * Standard SiSU meta-markup syntax, and the - * Standard SiSU object citation numbering and system - - * Hompages: - - - - * Download: - - - * Git - - - - * Ralph Amissah - - - - ** Description: system environment, resource control and configuration details - -=end -module SiSU_DAL_Metadata - class Metadata - def initialize(md,metad) - @md,@metadata=md,metad - l=SiSU_Env::StandardiseLanguage.new(@md.opt.lng).language - language=l[:n] - @tr=SiSU_Translate::Source.new(md,language) - end - def make_para(obj,ocn) - h={ obj: obj, ocn: 0 } - SiSU_DAL_DocumentStructure::ObjectPara.new.paragraph(h) - end - def make_heading(obj,ocn,name,lv,ln) - h={ lv: lv, ln: ln, name: name, obj: obj, ocn: 0 } - SiSU_DAL_DocumentStructure::ObjectHeading.new.heading(h) - end - def metadata - end - end -end -__END__ diff --git a/lib/sisu/v5/dal_misc_arrange.rb b/lib/sisu/v5/dal_misc_arrange.rb deleted file mode 100644 index e6cc72db..00000000 --- a/lib/sisu/v5/dal_misc_arrange.rb +++ /dev/null @@ -1,157 +0,0 @@ -# encoding: utf-8 -=begin - - * Name: SiSU - - * Description: a framework for document structuring, publishing and search - - * 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. - - * 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 . - - If you have Internet connection, the latest version of the GPL should be - available at these locations: - - - - - - * SiSU uses: - * Standard SiSU markup syntax, - * Standard SiSU meta-markup syntax, and the - * Standard SiSU object citation numbering and system - - * Hompages: - - - - * Download: - - - * Git - - - - * Ralph Amissah - - - - ** Description: system environment, resource control and configuration details - -=end -module SiSU_DAL_MiscArrangeText - class SI - def initialize(md,data) - @md,@data=md,data - 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 - 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") - end - para - end - def code_blocks(para) - def ticks(para) - block_open,block_close,text=nil,nil,nil - if para =~/\A[`]{3}\s+.+?\n.+?\n[`]{3}(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*\Z/m - block_open,text,block_close=/\A([`]{3}\s+.+?)\n(.+?)\n([`]{3}(\s+[~-][#]|\s+\~\{.+?\}\~)?)\s*\Z/m.match(para)[1..3] - ((para=~/^[`]{3}\s+table(?:~h)?\s+/) \ - and (para !~/^[`]{3}\s+table(?:~h)?\s+c\d+/)) \ - ? para - : (para=[]; para << block_open << text << block_close) - elsif para =~/\A[`]{3}\s+.+?\n.*?\Z/m #look at, study - block_open,text=/\A([`]{3}(?:\s+.+?))\n(.*?)\Z/m.match(para)[1,2] - para=[] - if not text.to_s.empty? - para << block_open << text - else - para << block_open - end - elsif para =~/\A.+?\n[`]{3}(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*\Z/m - text,block_close=/\A(.+?)\n([`]{3}(?:\s+[~-][#]|\s+\~\{.+?\}\~)?)\s*\Z/m.match(para)[1,2] - para=[] - if not text.to_s.empty? - para << text.to_s << block_close - else - para << block_close - end - else para - end - para - end - def curly_braces(para) - block_open,block_close,text=nil,nil,nil - para=if para =~/\A(?:code|poem|alt|group|block|table)\{ .+?\n.+?\n\}(?:code|poem|alt|group|block|table)(?: [~-][#])?\s*\Z/m - block_open,text,block_close=/\A((?:code|poem|alt|group|block|table)\{ .+?)\n(.+?)\n(\}(?:code|poem|alt|group|block|table)(?: [~-][#])?)\s*\Z/m.match(para)[1..3] - para=[] - para << block_open << text << block_close - elsif para =~/\A(?:code|poem|alt|group|block|table)\{ .+?\n.+?\Z/m - block_open,text=/\A((?:code|poem|alt|group|block|table)\{ .+?)\n(.+?)\Z/m.match(para)[1,2] - para=[] - if not text.to_s.empty? - para << block_open << text - else - para << block_open - end - elsif para =~/\A.+?\n\}(?:code|poem|alt|group|block|table)(?: [~-][#])?\s*\Z/m - text,block_close=/\A(.+?)\n(\}(?:code|poem|alt|group|block|table)(?: [~-][#])?)\s*\Z/m.match(para)[1,2] - para=[] - if not text.to_s.empty? - para << text.to_s << block_close - else - para << block_close - end - else para - end - para - end - para=para =~/^```/m \ - ? ticks(para) - : para - para=(para =~/^(?:code|poem|alt|group|block|table)\{|^\}(?:code|poem|alt|group|block|table)/m) \ - ? curly_braces(para) - : para - end - def prepare_text - data=@data - data_new=[],[] - if data[0] =~ /^#!\s*(?:\/usr\/bin\/env sisu|\/usr\/bin\/sisu)/ # remove bang from top #! (however file is stripped, so will be removed provided no content precedes it) - data[0]=data[0].gsub(/^#!\s*\/usr\/bin\/sisu/,''). - gsub(/^#!\s*\/usr\/bin\/env sisu/,'') - end - if data[0] =~ /^(SiSU\s+[\d.]*|sisu-[\d.]+)$/ # SiSU identifier - data[0]=data[0].gsub(/^(SiSU\s*[\d.]*)$/,'% \1'). - gsub(/^(sisu-[\d.]+)$/,'% \1') - end - data.each do |para| - para=conditional_headings(para) - data_new << code_blocks(para) - end - data_new=data_new.flatten - end - end -end -__END__ diff --git a/lib/sisu/v5/dal_numbering.rb b/lib/sisu/v5/dal_numbering.rb deleted file mode 100644 index 96f4134b..00000000 --- a/lib/sisu/v5/dal_numbering.rb +++ /dev/null @@ -1,486 +0,0 @@ -# encoding: utf-8 -=begin - - * Name: SiSU - - * Description: a framework for document structuring, publishing and search - - * 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. - - * 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 . - - If you have Internet connection, the latest version of the GPL should be - available at these locations: - - - - - - * SiSU uses: - * Standard SiSU markup syntax, - * Standard SiSU meta-markup syntax, and the - * Standard SiSU object citation numbering and system - - * Hompages: - - - - * Download: - - - * Git - - - - * Ralph Amissah - - - - ** Description: system environment, resource control and configuration details - -=end -module SiSU_DAL_Numbering - class Numbering - attr_accessor :obj,:osp,:ocn,:lv,:name,:index,:comment - def initialize(md,data) - @md,@data=md,data - @obj=@type=@ocn=@lv=@name=@index=@comment=nil - end - def numbering_song - data=@data - data=number_plaintext_para(data) - data=auto_number_heading_ie_title(data.compact) #tr issue - data=ocn(data.compact) #watch - data=xml(data.compact) - data=minor_numbering(data.compact) - data,tags_map,ocn_html_seg_map=name_para_seg_filename(data) - data=set_heading_top(data) unless @md.set_heading_top - [data,tags_map,ocn_html_seg_map] - end - def number_plaintext_para(data) - @tuned_file=[] - data.each do |dob| - if (dob.of !=:block \ - && dob.of !=:comment \ - && dob.of !=:layout) \ - && dob.ocn_ #and dob.obj !~ /#{Mx[:gr_o]}Th|#{Mx[:tc_o]}#{Mx[:tc_p]}#{Mx[:tc_p]}/ #FIX - dob.obj=dob.obj.gsub(/(.+)\n/,'\1 ') #messy, but idea is that tables should retain breaks - end - unless dob.obj.is_a?(Array) - dob.obj=dob.obj.gsub(/^\s+/,''). - gsub(/\s$/,"\n") - end - @tuned_file << dob - end - @tuned_file=@tuned_file.flatten - end - def number_sub_heading(dob,num,title_no) - unless dob.obj =~/\d+\.|(?:chapter|article|section|clause)\s+\d+/i #name selection arbitrary, fix - dob.obj=case dob.name - when /-/; dob.obj.gsub(/^/,"#{title_no} ") - when /^#/; dob.obj.gsub(/^/,"#{title_no} ") - when /^[a-z_\.]+/; dob.obj.gsub(/^/,"#{title_no} ") - else - dob.name=title_no if dob.name=~/^$/ #where title contains title number - dob.obj.gsub(/^/,"#{title_no} ") if title_no =~/\d+/ #main, where title number is to be provided #watch changed placement - end - if @md.toc_lev_limit \ - and @md.toc_lev_limit < num - dob.obj=dob.obj.gsub(/^/,'!_ ') #bold line, watch - end - end - dob - end - def heading_tag_clean(heading_tag) - heading_tag=heading_tag.gsub(/[ ]+/,'_'). - gsub(/["']/,''). - gsub(/[\/]/,'-'). - gsub(/#{Mx[:fa_bold_o]}|#{Mx[:fa_bold_c]}/,''). - gsub(/#{Mx[:fa_italics_o]}|#{Mx[:fa_italics_c]}/,''). - gsub(/#{Mx[:fa_underscore_o]}|#{Mx[:fa_underscore_c]}/,''). - gsub(/#{Mx[:fa_cite_o]}|#{Mx[:fa_cite_c]}/,''). - gsub(/#{Mx[:fa_insert_o]}|#{Mx[:fa_insert_c]}/,''). - gsub(/#{Mx[:fa_strike_o]}|#{Mx[:fa_strike_c]}/,''). - gsub(/#{Mx[:fa_superscript_o]}|#{Mx[:fa_superscript_c]}/,''). - gsub(/#{Mx[:fa_subscript_o]}|#{Mx[:fa_subscript_c]}/,''). - gsub(/#{Mx[:fa_hilite_o]}|#{Mx[:fa_hilite_c]}/,''). - gsub(/#{Mx[:gl_bullet]}/,'') - end - def auto_number_heading_ie_title(data) #also does some segment naming - @tuned_file=[] - if defined? @md.make.num_top \ - and @md.make.num_top \ - and @md.make.num_top !~/^$/ - input||=@md.make.num_top - end - num_top=(input ? input.to_i : nil) - t_no1=t_no2=t_no3=0 - if num_top - no1=num_top; no2=(num_top + 1); no3=(num_top + 2) - end - chapter_number_counter=0 - data=data.compact - data.each do |dob| #@md.seg_names << [additions to segment names] - title_no=nil - dob=SiSU_DAL_DocumentStructureExtract::Structure.new(@md,dob).structure_markup #must happen earlier, node info etc. require - if dob.is ==:heading \ - && dob.autonum_ \ - and defined? @md.make.num_top \ - and @md.make.num_top !~/^$/ - if dob.lv=='1' \ - and dob.obj =~/^#\s|\s#(?:\s|$)/ - chapter_number_counter +=1 - dob.obj=dob.obj.gsub(/^#\s/,"#{chapter_number_counter} "). - gsub(/#([:,]?\s|[.]?$)/,"#{chapter_number_counter}\\1") - end - if dob.ln==no1 - @subnumber=1 - @subnumber=0 if dob.ln==no1 - end - if dob.ln.to_s =~/^[1-6]/ \ - and not dob.toc_ \ - and dob.obj !~/#{Mx[:fa_o]}(?:~#|-#)#{Mx[:fa_c]}/ # <-- fix - if dob.ln==no1 - t_no1+=1; t_no2=0; t_no3=0 - title_no="#{t_no1}" - if @md.seg_names.is_a?(Array) \ - and not @md.seg_names.include?(title_no) - if dob.ln==no1 - dob.name="#{title_no}" if not dob.name - dob.tags=[title_no,dob.tags].flatten if title_no !~/^\d+$/ #check whether will work across file types with stop signs - tag=dob.obj.gsub(/(Article|Clause|Section|Chapter)\s+/,"\\1_#{title_no}").downcase - tag=heading_tag_clean(tag) - dob.tags=[tag,dob.tags].flatten if tag !~/^\d+$/ #check whether will work across file types with stop signs - dob.obj=(dob.obj =~/(Article|Clause|Section)\s+/) \ - ? (dob.obj.gsub(/(Article|Clause|Section)\s+/,"\\1 #{title_no} ")) - : (dob.obj.gsub(/^/,"#{title_no}. ")) #fix stop later - end - if dob.ln !=no1 \ - and dob.obj =~/^[\d.]+\s/ #fix -> if the title starts with a numbering scheme, do not auto-number, review - dob.name ="#{title_no}" if not dob.name - dob.tags=[title_no,dob.tags].flatten if title_no !~/^\d+$/ #check whether will work across file types with stop signs - dob.obj=dob.obj.gsub(/^/,"#{title_no}. ") - end - @md.seg_names << title_no - end - if dob.ln!=no1 \ - and dob.name!~/^[a-z_\.]+$/ \ - and dob.obj !~/[A-Z]\.?\s/ #bug -> tmp fix, excludes A. B. C. lettering, but not roman numerals, is arbitrary, review required # not fixed, work on - dob.tags=[title_no,dob.tags].flatten if title_no !~/^\d+$/ #check whether will work across file types with stop signs - dob.obj=dob.obj.gsub(/^/i,"#{title_no}. ") - end - end - if dob.ln==no1 #watch because here you change dob.name - dob.tags=["h#{title_no}",dob.tags].flatten #check whether will work across file types with stop signs - end - if dob.ln==no2 #watch because here you change dob.name - t_no2+=1; t_no3=0 - title_no="#{t_no1}.#{t_no2}" - dob.tags=["h#{title_no}",dob.tags].flatten #check whether will work across file types with stop signs - dob=number_sub_heading(dob,no2,title_no) - end - if dob.ln==no3 #watch because here you change dob.name - t_no3+=1 - title_no="#{t_no1}.#{t_no2}.#{t_no3}" - 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]/ \ - 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') - end - elsif dob.is ==:heading \ - and dob.autonum_ \ - 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.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 - end - if @md.toc_lev_limit - end - elsif defined? dob.name \ - and dob.name - dob.tags=[dob.name,dob.tags].flatten if dob.name !~/^\d+$/ #check whether will work across file types with stop signs - end - dob.tags=dob.tags.uniq if defined? dob.tags - @tuned_file << dob - end - @tuned_file=@tuned_file.flatten - end - def ocn(data) #and auto segment numbering increment - @tuned_file=SiSU_DAL_DocumentStructureExtract::OCN.new(@md,data).ocn - @tuned_file - end - def xml(data) - @tuned_file=SiSU_DAL_DocumentStructureExtract::XML.new(@md,data).dom - @tuned_file - end - def minor_numbering(data) #and auto segment numbering increment - @tuned_file=[] - number_small,letter_small=0,0 - letter=%w( a b c d e f g h i j k l m n o p q r s t u v w x y z ) - data.each do |dob| - if dob.of ==:heading \ - || dob.of ==:heading_insert \ - || 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) - number_small,letter_small=0,0 - elsif dob.is ==:para - if dob.obj =~/^#[ 1]/ \ - and dob.obj !~/^#\s+(?:~#)?$/ - letter_small=0 - number_small=0 if dob.obj =~ /^#1/ - number_small+=1 - dob.obj=dob.obj.gsub(/^#[ 1]/,"#{number_small}. ") - end - if dob.obj =~/^_# / - dob.obj=dob.obj.gsub(/^_# /,"#{letter[letter_small]}. ") - dob.indent='1' - letter_small+=1 - end - end - end - @tuned_file << dob - end - @tuned_file=@tuned_file.flatten - end - def name_para_seg_filename(data) #segment naming, remaining - # paragraph name/numbering rules - # manual naming overrides, manual naming may be - # alpha-numeric characters mixed, - # numeric only (a number), if - # all segments have been named, - # the numbers used are over 1000 or - # it is not minded that auto-numbering uses a funny scheme for naming segments (not yet implemented) - # [for now a warning is printed for such documents on use of maintenance or very-verbose flag] - # auto-naming takes the form of giving numbers to segments - # the rules for which are as follows - # if the title/heading text starts with a numeric, then that is used (1 3.1 3rd etc.) - # otherwise the level 4 segment number from the embedded document structure info is used - # if there is none a sequential number is designated, preceded by an underscore - @tuned_file,@unique_auto_name=[],[] - tags={} - art_filename_auto=1 - @counter=1 - if not @md.seg_autoname_safe \ - and (@md.opt.act[:verbose_plus][:set]==:on \ - || @md.opt.act[:maintenance][:set]==:on) - puts 'manual segment names, numbers used as names, risk warning (segmented html)' - end - ocn_html_seg=[] - data.each do |dob| - if dob.is==:heading \ - && dob.ln \ - and dob.ln.to_s =~/^[456]/ - if dob.ln==4 \ - and not dob.name \ - and not @md.set_heading_seg - @md.set_heading_seg=true - end - if dob.name !~/^\S+/ \ - and dob.obj =~/^\s*(?:\S+\s+)?([\d.,:-]+)/m #heading starts with a recognised numeric or word followed by a recognised numerical construct, use that as name - possible_seg_name=$1 - possible_seg_name=possible_seg_name.gsub(/(?:[:,-]|\W)/,'.'). - gsub(/\.$/,'') - if @md.seg_names.is_a?(Array) \ - and not @md.seg_names.include?(possible_seg_name) - dob.name=possible_seg_name - dob.tags=[dob.name,dob.tags].flatten if dob.name !~/^\d+$/ - @md.seg_names << possible_seg_name - elsif (@md.opt.act[:verbose_plus][:set]==:on \ - or @md.opt.act[:maintenance][:set]==:on) - puts 'warn, there may be a conflicting numbering scheme' - end - end - if dob.ln==4 \ - and dob.name #extract segment name from embedded document structure info - if @md.seg_names.is_a?(Array) \ - and not @md.seg_names.include?(dob.name) - dob.tags=[dob.name,dob.tags].flatten if dob.name !~/^\d+$/ - @md.seg_names << dob.name - end - end - if dob.ln==4 \ - and not dob.name #if still no segment name, provide a numerical one - pf='_' #pg='' #may use e.g. '' or '~' or '_' - segn_auto="#{pf}#{art_filename_auto.to_s}" - if @md.seg_names.is_a?(Array) \ - and not @md.seg_names.include?(segn_auto) - dob.name=segn_auto - dob.tags=[dob.name,dob.tags].flatten if dob.name !~/^\d+$/ #check whether will work across file types with stop signs - @md.seg_names << segn_auto - else puts 'segment name (numbering) error' - end - art_filename_auto+=1 - end - if dob.ln==4 \ - and not dob.name #should not occur - puts "e r r o r -\t#{__FILE__}::#{__LINE__}\n#{dob.inspect}" - end - end - if (dob.is ==:heading \ - || dob.is ==:heading_insert) \ - && dob.ln==4 - @seg=dob.name - end - @tuned_file << if dob.is==:heading \ - && (@md.pagenew || @md.pagebreak || @md.pageline) - m=dob.ln.to_s - dob_tmp=[] - if @md.pagenew.inspect =~/#{m}/ - dob_tmp << SiSU_DAL_DocumentStructure::ObjectLayout.new.break(Hx[:br_page_new]) << dob - elsif @md.pagebreak.inspect =~/#{m}/ - dob_tmp << SiSU_DAL_DocumentStructure::ObjectLayout.new.break(Hx[:br_page]) << dob - elsif @md.pageline.inspect =~/#{m}/ - dob_tmp << SiSU_DAL_DocumentStructure::ObjectLayout.new.break(Hx[:br_page_line]) << dob - end - unless dob_tmp.length > 0; dob - else dob_tmp - end - else dob - end - if defined? dob.ocn \ - and dob.ocn - @segname=((dob.is==:heading || dob.is==:heading_insert) && dob.ln==4 && (defined? dob.name)) \ - ? (dob.name) - : @segname - tags["#{dob.ocn}"]={ segname: @segname } - ocn_html_seg[dob.ocn]=if (dob.is==:heading || dob.is==:heading_insert) - if dob.ln =~/[1-3]/ - { seg: nil, level: dob.ln } - else #elsif dob.ln =~/[4-6]/ - { seg: @seg, level: dob.ln } - end - else - { seg: @seg, level: nil } - end - end - dob.tags=dob.tags.uniq if defined? dob.tags - if defined? dob.tags \ - and dob.tags.length > 0 - #@segname=((dob.is=='heading'|| dob.is=='heading_insert') && dob.ln==4 && (defined? dob.name)) \ - #? (dob.name) \ - #: @segname - dob.tags.each do |y| - tags[y]={ ocn: dob.ocn.to_s, segname: @segname } - end - end - dob - end - ocn_html_seg.each_with_index do |ocn,i| - if ocn \ - and ocn[:level].to_s=~/[1-3]/ - (1..4).each do |x| - if ocn_html_seg[i+x] and ocn_html_seg[i+x][:level]==4 - ocn[:seg]=ocn_html_seg[i+x][:seg] - end - end - end - end - if @md.seg_names.length > 0 - @md.set_heading_seg=true - end - tuned_file=@tuned_file.flatten - [tuned_file,tags,ocn_html_seg] - end - def set_heading_top(data) #% make sure no false positives - unless @md.set_heading_top - if (@md.opt.act[:verbose_plus][:set]==:on \ - or @md.opt.act[:maintenance][:set]==:on) - puts "\tdocument contains no top level heading, (will have to manufacture one)" - end - @tuned_file=[] - data.each do |t_o| - unless @md.set_heading_top - if t_o !~/^(?:#{Rx[:meta]}|@\S+:)\s/m \ - and t_o !~/\A\s*\Z/m - @md.set_heading_top=true - if defined? @md.title \ - and @md.title \ - and defined? @md.title.full \ - and defined? @md.creator \ - and @md.creator - head=@md.title.main ? ([@lv='1',@obj=@md.title.main]) : ([@lv='1',@obj='[no title provided]']) - @tuned_file << head - end - end - end - @tuned_file << t_o - end - @tuned_file=@tuned_file.flatten - end - end - def set_heading_seg(data) #% make sure no false positives - unless @md.set_heading_seg - if (@md.opt.act[:verbose_plus][:set]==:on \ - or @md.opt.act[:maintenance][:set]==:on) - puts "\tdocument contains no segment level, (will have to manufacture one)" - end - @tuned_file=[] - data.each do |dob| - unless @md.set_heading_seg - if defined? dob.ln and dob.ln.to_s !~/^[123]/m \ - and dob.obj !~/\A\s*\Z/m \ - and dob.is !=:layout - @md.set_heading_seg=true - head=@md.title.main \ - ? (dob.ln,dob.name,dob.obj=4,'seg',@md.title.main) - : (dob.ln,dob.name,dob.obj=4,'seg','[segment]') - @tuned_file << head - end - end - @tuned_file << dob - end - @tuned_file=@tuned_file.flatten - end - end - def set_header_title(data) #% make sure no false positives - unless @md.set_header_title - if (@md.opt.act[:verbose_plus][:set]==:on \ - or @md.opt.act[:maintenance][:set]==:on) - puts "\t no document title provided, (will have to manufacture one)" - end - @tuned_file=[] - data.each do |t_o| - unless @md.set_header_title - if t_o !~/^%{1,2}\s/m \ - and t_o !~/\A\s*\Z/m - @tuned_file << "#{Mx[:meta_o]}title#{Mx[:meta_c]} #{@md.heading_seg_first}" - @md.title.main=@md.heading_seg_first - @md.set_header_title=true - end - end - @tuned_file << t_o - end - @tuned_file=@tuned_file.flatten - end - end - end -end -__END__ diff --git a/lib/sisu/v5/dal_syntax.rb b/lib/sisu/v5/dal_syntax.rb deleted file mode 100644 index 1e1d8542..00000000 --- a/lib/sisu/v5/dal_syntax.rb +++ /dev/null @@ -1,631 +0,0 @@ -# encoding: utf-8 -=begin - - * Name: SiSU - - * Description: a framework for document structuring, publishing and search - - * 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. - - * 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 . - - If you have Internet connection, the latest version of the GPL should be - available at these locations: - - - - - - * SiSU uses: - * Standard SiSU markup syntax, - * Standard SiSU meta-markup syntax, and the - * Standard SiSU object citation numbering and system - - * Hompages: - - - - * Download: - - - * Git - - - - * Ralph Amissah - - - - ** Description: Syntax for markup, input markup syntaxes, determined here - -=end -module SiSU_DAL_Syntax - class Words - def initialize(line,md,mkp) - @line,@md,@mkp=line,md,mkp - end - end - class Markup - def initialize(md='',data='') - @md,@data=md,data - @vz=SiSU_Viz::Defaults.new - @data_new=[] - url_and_stub=SiSU_Env::InfoEnv.new.url - @output_url="#{url_and_stub.remote}" - @env=SiSU_Env::InfoEnv.new - emph_set=if defined? @md.emphasis_set_to \ - and not @md.emphasis_set_to.nil? - @md.emphasis_set_to - else @env.markup_emphasis - end - @emph=case emph_set - when /bold/ - emph_italics=false - { o: Mx[:fa_bold_o], c: Mx[:fa_bold_c] } - when /italics/ - emph_italics=true - { o: Mx[:fa_italics_o], c: Mx[:fa_italics_c] } - when /underscore/ - emph_italics=false - { o: Mx[:fa_underscore_o], c: Mx[:fa_underscore_c] } - else p __LINE__.to_s + '::' + __FILE__ - end - @http_m=%r{\{.+?\}https?://\S+|https?:\S+|:\S+|\.\.\/\S+|#\S+|\S+?\.png\b|[*]~\S+|^#{Mx[:meta_o]}.+|#{Mx[:gr_o]}(?:code|block|group|alt|verse)(?:-end)?#{Mx[:gr_c]}|#{Mx[:fa_o]}:br#{Mx[:fa_c]}} - @manmkp_ital=emph_italics \ - ? '[i/*]\\{.+?\\}[i/*]' - : '[i/]\\{.+?\\}[i/]' - tail_m_ital=%q{(?:\s|[.,;:?!'")]|~\^|~\\\{\s|$)} - tail_m_bold=%{(?:(?:#{Mx[:fa_italics_c]})?(?:\s|[.,;:?!'")]|~\^|~\\\{\s|$))?} - bold_line=%{^!_\s.+?(?:#{Mx[:br_line]}|\n|$)} - #ital_line=%{^/_\s.+?(?:#{Mx[:br_line]}|\n|$)} #not implemented - @line_scan_ital=if defined? @md.italics_match_list[:str] - /#{@http_m}|#{bold_line}|#{@manmkp_ital}#{tail_m_ital}|#{@md.italics_match_list[:str]}#{tail_m_ital}|\S+|\n/i - elsif defined? @vz.markup_make_italic[:str] - /#{@http_m}|#{bold_line}|#{@manmkp_ital}#{tail_m_ital}|#{@vz.markup_make_italic[:str]}#{tail_m_ital}|\S+|\n/i - end - @manmkp_bold=emph_italics \ - ? '^!_\s.+?(?:\n|$)|[!b]\\{.+?\\}[*!b]|[*!][a-zA-Z0-9\-_]+[!]' - : '^!_\s.+?(?:\n|$)|[*!b]\\{.+?\\}[*!b]|[*!][a-zA-Z0-9\-_]+[*!]' - @line_scan_bold=if (defined? @md.bold_match_list[:str] \ - and @md.bold_match_list[:str]) \ - and (defined? @vz.markup_make_bold[:str] \ - and @vz.markup_make_bold[:str]) - /#{@http_m}|#{bold_line}|(?:#{@manmkp_bold}|#{@md.bold_match_list[:str]}|#{@vz.markup_make_bold[:str]})#{tail_m_bold}|\S+|\n/i - elsif defined? @md.bold_match_list[:str] \ - and @md.bold_match_list[:str] - /#{@http_m}|#{bold_line}|(?:#{@manmkp_bold}|#{@md.bold_match_list[:str]})#{tail_m_bold}|\S+|\n/i - elsif defined? @vz.markup_make_bold[:str] \ - and @vz.markup_make_bold[:str] - /#{@http_m}|#{bold_line}|(?:#{@manmkp_bold}|#{@vz.markup_make_bold[:str]})#{tail_m_bold}|\S+|\n/i - end - end - def songsheet - @data=@data.compact - @data.each do |dob| - dob=breaks(dob) - dob=if @md.sem_tag then sem(dob) else dob end #revisit - dob=line_actions(dob) - dob=paragraph_set(dob) - dob=substitutions(dob) - dob=wordlist_italics(dob) - dob=wordlist_bold(dob) - dob=bodymarkup(dob) - @data_new << dob unless dob.nil? - end - @data_new - end - def sem(dob) #revisit - dob=SiSU_Sem::Tags.new(dob,@md).rm.all - end - def breaks(dob) - if dob.is !=:meta \ - && dob.is !=:comment \ - && dob.is !=:code \ - && dob.is !=:table - dob.obj=dob.obj.gsub(/^-\\\\-\s*$/,"#{Mx[:br_page]}"). - gsub(/^=\\\\=\s*$/,"#{Mx[:br_page_new]}"). - gsub(/ \\\\(?: |$)/,"#{Mx[:br_line]}"). - gsub(/(?:<:?pb>)/,"#{Mx[:br_page]}"). # depreciated - gsub(/(?:<:?pn>)/,"#{Mx[:br_page_new]}"). # depreciated - gsub(/(?:<:?br>|
)/,"#{Mx[:br_line]}"). # depreciated - gsub(/(?:^-\.\.-\s*$)/,"#{Mx[:br_page_line]}") - end - dob - end - def wordlist_italics(dob) - dob=dob.dup - if (defined? @md.italics_match_list[:str] \ - and @md.italics_match_list[:str]) \ - or (defined? @vz.markup_make_italic[:str] \ - and @vz.markup_make_italic[:str]) - dob.obj=if dob.is !=:meta \ - && dob.is !=:heading \ - && dob.is !=:heading_insert \ - && dob.is !=:code \ - && dob.is !=:comment - word=dob.obj.scan(@line_scan_ital) - word=word.flatten.compact - line_array=[] - word.each do |w| - unless /#{@manmkp_ital}|#{@http_m}/.match(w) - if defined? @md.italics_match_list[:regx] \ - and @md.italics_match_list[:regx] - w=w.gsub(@md.italics_match_list[:regx], - "#{Mx[:fa_italics_o]}\\1#{Mx[:fa_italics_c]}") - elsif defined? @vz.markup_make_italic \ - and @vz.markup_make_italic - w=w.gsub(@vz.markup_make_italic, - "#{Mx[:fa_italics_o]}\\1#{Mx[:fa_italics_c]}") - else w - end - end - line_array << w - end - line_array.join(' ') - else dob.obj - end - end - dob - end - def embolden(given) - given=given.gsub(/^!_\s+((?:\{|#{Mx[:lnk_o]})(?:~^ )?.+?(?:\}|#{Mx[:lnk_o]})https?:\/\/\S+.*?)([#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:br_nl]}])/, - "#{Mx[:fa_bold_o]} \\1 #{Mx[:fa_bold_c]}\\2"). - gsub(/^!_\s+((?:\{|#{Mx[:lnk_o]})(?:~^ )?.+?(?:\}|#{Mx[:lnk_o]})https?:\/\/\S+.*)/, - "#{Mx[:fa_bold_o]} \\1 #{Mx[:fa_bold_c]}"). - gsub(/(?:^!_|^#{Mx[:lv_o]}[7-9]:\S*?#{Mx[:lv_c]})\s*(.+?)([#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:br_nl]}])/, - "#{Mx[:fa_bold_o]}\\1#{Mx[:fa_bold_c]}\\2"). - gsub(/(?:^!_|^#{Mx[:lv_o]}[7-9]:\S*?#{Mx[:lv_c]})\s*(.+?)\s+((?:[*]~\S+\s*)+)/, - "#{Mx[:fa_bold_o]}\\1#{Mx[:fa_bold_c]}\\2"). - gsub(/(?:^!_|^#{Mx[:lv_o]}[7-9]:\S*?#{Mx[:lv_c]})\s*(.+?)\s*([~-]#)$/, - "#{Mx[:fa_bold_o]}\\1#{Mx[:fa_bold_c]}\\2"). - gsub(/(?:^!_\s+|^#{Mx[:lv_o]}[7-9]:\S*?#{Mx[:lv_c]}\s*)(.*)?\s*$/, - "#{Mx[:fa_bold_o]}\\1#{Mx[:fa_bold_c]}") - end - def italicise(given) - given=given.gsub(/^\/_\s*(.+?)([#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:br_nl]}])/, - "#{Mx[:fa_italics_o]}\\1#{Mx[:fa_italics_c]}\\2"). - gsub(/^\/_\s*(.+?)\s+((?:[*]~\S+\s*)+)/, - "#{Mx[:fa_italics_o]}\\1#{Mx[:fa_italics_c]}\\2"). - gsub(/^\/_\s*(.+?)\s*([~-]#)$/, - "#{Mx[:fa_italics_o]}\\1#{Mx[:fa_italics_c]}\\2"). - gsub(/^\/_\s+(.*)?\s*$/, - "#{Mx[:fa_italics_o]}\\1#{Mx[:fa_italics_c]}") - end - def line_actions(dob) - dob.obj=if (dob.is !=:heading \ - && dob.is !=:heading_insert \ - && dob.is !=:comment \ - && dob.is !=:meta) \ - and dob.obj =~ /^!_\s+/ - embolden(dob.obj) - elsif dob.obj =~ /^\/_\s+/ - italicise(dob.obj) - else dob.obj - end - dob - end - def paragraph_set(dob) - dob.obj=if dob.is !=:meta \ - && dob.is !=:heading \ - && dob.is !=:heading_insert \ - && dob.is !=:code \ - && dob.is !=:comment \ - && dob.is !=:table - dob.obj.gsub(/\n/m,' '). - gsub(/ \s+/m,' ') - else dob.obj - end - dob - end - def substitutions(dob) - dob=dob.dup - dob=if defined? @md.substitution_match_list[:match_and_replace] \ - and @md.substitution_match_list[:match_and_replace].is_a?(Array) - dob=if dob.is !=:meta \ - && dob.is !=:heading_insert \ - && dob.is !=:code \ - && dob.is !=:comment \ - && dob.is !=:table - if dob.obj =~/#{@md.substitution_match_list[:matches]}/ - @md.substitution_match_list[:match_and_replace].each do |x| - dob.obj=if x[:case_s]==:i - dob.obj.gsub(/#{x[:match]}/mi,x[:replace]) - else - dob.obj.gsub(/#{x[:match]}/m,x[:replace]) - end - end - end - dob - else dob - end - dob - else dob - end - end - def wordlist_bold(dob) - dob=dob.dup - if (defined? @md.bold_match_list[:str] \ - and @md.bold_match_list[:str]) \ - or (defined? @vz.markup_make_bold[:str] \ - and @vz.markup_make_bold[:str]) - dob.obj=if dob.is !=:meta \ - && dob.is !=:heading \ - && dob.is !=:heading_insert \ - && dob.is !=:code \ - && dob.is !=:comment \ - && dob.is !=:table - line_array=[] - word=dob.obj.scan(@line_scan_bold) - word=word.flatten.compact - word.each do |w| - unless /#{@manmkp_bold}|#{@http_m}/.match(w) - if defined? @md.bold_match_list[:regx] \ - and @md.bold_match_list[:regx] #document header: @bold: [bold word list] - w=w.gsub(@md.bold_match_list[:regx],"#{Mx[:fa_bold_o]}\\1#{Mx[:fa_bold_c]}") - elsif defined? @vz.markup_make_bold \ - and @vz.markup_make_bold #defaults adjusted bold word list - w=w.gsub(@vz.markup_make_bold,"#{Mx[:fa_bold_o]}\\1#{Mx[:fa_bold_c]}") - end - else - w=if w =~ /(?:^!_|^#{Mx[:lv_o]}[7-9]:\S*?#{Mx[:lv_c]})\s+/ - embolden(w) #bold paragraph/emphasize #may wish to remove think about 7{ 8{ conversion not satisfactory, as information is lost! - elsif w =~/^\/_\s+/ - italicise(w) - else w - end - end - line_array << w - end - line_array.join(' ') - else dob.obj - end - else - dob.obj=if dob.is==:heading \ - and dob.ln.to_s =~/[7-9]/ - embolden(dob.obj) - else dob.obj - end - end - dob - end - def fontface_lines(dob,leader) - while (dob.obj =~/#{Mx[:br_nl]}/ \ - and dob.obj =~/(?:#{leader})([*!\/_#])\{(.+?)\}\1/m) \ - and $2 =~/#{Mx[:br_nl]}/ - dob=if dob.obj =~/#{Mx[:br_nl]}/ \ - and dob.obj =~/(#{leader})([*!\/_#])\{(.+?)\}\2/m - lead,fce,txt=$1,$2,$3 - dob=if txt =~/#{Mx[:br_nl]}/ - lead_break=if dob.obj =~/^#{Mx[:br_nl]}/ - dob.obj=dob.obj.sub(/^#{Mx[:br_nl]}/,'') - Mx[:br_nl] - else '' - end - txt="#{lead_break}#{fce}\{" + txt.split(Mx[:br_nl]).join("\}#{fce}#{Mx[:br_nl]}#{fce}\{") + "\}#{fce}" - dob.obj=dob.obj.sub(/(?:^|#{Mx[:gl_c]}|\s+|['"]|[#{Mx[:nbsp]}#{Mx[:fa_o_c]}#{Mx[:fa_c]}#{Mx[:lnk_o]}#{Mx[:br_nl]}#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:tc_c]}#{Mx[:tc_p]}]|[\(\[\{]|\>)([*!\/_#])\{.+?\}\1/m,"#{lead}#{txt}") - dob - else dob - end - end - dob - end - dob - end - def fontface(dob) - leader=/^|#{Mx[:gl_c]}|\s+|['"]|[#{Mx[:nbsp]}#{Mx[:fa_o_c]}#{Mx[:fa_c]}#{Mx[:lnk_o]}#{Mx[:br_nl]}#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:tc_c]}#{Mx[:tc_p]}]|[\(\[\{]|[、。]|\>/ - dob=fontface_lines(dob,leader) - dob.obj=dob.obj.gsub(/(#{leader})\*\{(.+?)\}\*/m, - "\\1#{@emph[:o]}\\2#{@emph[:c]}"). #emphasis - gsub(/(#{leader})!\{(.+?)\}!/m, - "\\1#{Mx[:fa_bold_o]}\\2#{Mx[:fa_bold_c]}"). #bold - gsub(/(#{leader})\/\{(.+?)\}\//m, - "\\1#{Mx[:fa_italics_o]}\\2#{Mx[:fa_italics_c]}"). #italics - gsub(/(#{leader})_\{(.+?)\}_/m, - "\\1#{Mx[:fa_underscore_o]}\\2#{Mx[:fa_underscore_c]}"). #underscore - gsub(/(#{leader})#\{(.+?)\}#/m, - "\\1#{Mx[:fa_monospace_o]}\\2#{Mx[:fa_monospace_c]}"). #monospace - gsub(/(^|#{Mx[:gl_c]}|\s+|['"]|[#{Mx[:nbsp]}#{Mx[:fa_o_c]}#{Mx[:fa_c]}]|\(|\>)\"\{(.+?)\}\"/m, - "\\1#{Mx[:fa_cite_o]}\\2#{Mx[:fa_c_o]}cite#{Mx[:fa_c]}"). #cite /blockquote? - gsub(/(^|[^\\])\^\{(.+?)\}\^/m, - "\\1#{Mx[:fa_superscript_o]}\\2#{Mx[:fa_superscript_c]}"). #superscript - gsub(/(^|[^\\]),\{(.+?)\},/m, - "\\1#{Mx[:fa_subscript_o]}\\2#{Mx[:fa_subscript_c]}"). #subscript - gsub(/(^|#{Mx[:gl_c]}|\s+|['"]|#{Mx[:nbsp]}|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)\+\{(.+?)\}\+/m, - "\\1#{Mx[:fa_insert_o]}\\2#{Mx[:fa_insert_c]}"). #inserted text - gsub(/(^|#{Mx[:gl_c]}|\s+|['"]|#{Mx[:nbsp]}|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)-\{(.+?)\}-/m, - "\\1#{Mx[:fa_strike_o]}\\2#{Mx[:fa_strike_c]}"). #strikethrough - deleted text - gsub(/(^|#{Mx[:gl_c]}|\s+|['"]|#{Mx[:nbsp]}|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>|\d+)\^(\S+?)\^/, - "\\1#{Mx[:fa_superscript_o]}\\2#{Mx[:fa_superscript_c]}") #superscript single word, watch digit added - dob - end - def bodymarkup(dob) - # << http://www.jus.uio.no/sisu/sisu_markup_table/markup >> - # See: data/sisu/sample/document_samples_sisu_markup/ - ## fontface - # *{emphasis}* e{emphasis}e emphasis - # !{bold text}! b{bold}b bold text - # _{underline}_ u{underline}u underline - # /{italics}/ i{italics}i italics - # "{citation}" c{citation}c citation #blockquote? - # ^{superscript}^ superscript - # ,{subscript}, subscript - # +{inserted text}+ inserted text - # -{deleted text}- deleted text - # #{monospace text}# - # - # {url address}:url - # {image.png}imageurl - # {image.png}png - # ~{endnote}~ - # !_ #bold/emphasise paragraph - # _" #blockquote paragraph - # _1 <:i1> #indent paragraph 1 step - # _2 <:i2> #indent paragraph 2 steps - # _3 <:i3> #indent paragraph 3 steps - # _4 <:i4> #indent paragraph 4 steps - # _* #bullet (list) ● - # _1* #bullet (list) indented - # _1* #bullet (list) indented - # # #numbered (list) level 1 - # _# #numbered (list) level 2 - dob=dob.dup - if dob.is !=:meta \ - && dob.is !=:comment \ - && dob.is !=:code \ - && dob.is !=:table - line_array=[] - word=dob.obj.scan(/\S+|\n/) #unless line =~/^(?:#{Mx[:meta_o]}|%+\s)/ #visit - if word - word.each do |w| # _ - / # | : ! ^ ~ - unless w =~/~\{|\}~|~\[|\]~|^\^~|~\^|\*~\S+|~#|\{t?~|\{table|https?:\/\/\S+/ # do something earlier about table!! - w=w.gsub(/\\?~/,"#{Mx[:gl_o]}#126#{Mx[:gl_c]}") #escaped special character - end - w=w.gsub(/^\<$/,"#{Mx[:gl_o]}#lt#{Mx[:gl_c]}").gsub(/^\>$/,"#{Mx[:gl_o]}#gt#{Mx[:gl_c]}") #escaped special character - line_array << w - end - dob.obj=line_array.join(' ') - dob.obj=dob.obj.strip - end - dob.obj=dob.obj.gsub(/^([*#-.]{1,12})$/,'\1 ~#'). #ocn off for these paragraph separators - gsub(/~\{(.+?)\}~/m,Mx[:en_a_o] + '\1' + Mx[:en_a_c]). - gsub(/~\[([^*+].+?)\]~/m,Mx[:en_b_o] + '* \1' + Mx[:en_b_c]). #default if markup does not specify - gsub(/~\[(.+?)\]~/m,Mx[:en_b_o] + '\1' + Mx[:en_b_c]) - if dob.is ==:heading \ - and dob.ln ==1 - dob.obj=dob.obj.gsub(/\s*@title\b/," #{@md.title.full}") - dob.obj=if defined? @md.creator.author \ - and @md.creator.author - dob.obj.gsub(/\s+(?:@creator|@author)/,",#{Mx[:br_line]}#{@md.creator.author}") - else dob.obj.gsub(/\s+(?:@creator|@author)/,'') - end - end - if defined? @md.title \ - and @md.title \ - and defined? @md.title.full \ - and defined? @md.creator \ - and @md.creator - if dob.is ==:heading - dob.obj=dob.obj.gsub(/^\s*@title\s*$/,@md.title.full) if dob.lv =~/1/ - dob.obj=if dob.lv =~/[23]/ \ - and defined? @md.creator.author \ - and @md.creator.author - dob.obj.gsub(/^\s*(?:(by\s+)?(?:@creator|@author))\s*$/,"\\1#{@md.creator.author}") - else dob.obj.gsub(/^\s*(?:(by\s+)?(?:@creator|@author))\s*$/,'\1') - end - end - end - dob.obj=dob.obj.gsub(/<(https?:\/\/\S+?)>/,'< \1 >'). #catch problem markup - gsub(/<:=(\S+?)>/,'{ c_\1.png 14x14 }image'). - gsub(//,'<:\1>'). #escaped special character - gsub(/ /,"#{Mx[:nbsp]}"). #escaped special character - gsub(/\\~/,"#{Mx[:gl_o]}#126#{Mx[:gl_c]}"). #escaped special character - gsub(/\\\{/,"#{Mx[:gl_o]}#123#{Mx[:gl_c]}"). #escaped special character - gsub(/\\\}/,"#{Mx[:gl_o]}#125#{Mx[:gl_c]}"). #escaped special character - gsub(/\\\<>/,"#{Mx[:gl_o]}#gt#{Mx[:gl_c]}#{Mx[:gl_o]}#gt#{Mx[:gl_c]}"). #escaped special character - gsub(/\\\/,"#{Mx[:gl_o]}#gt#{Mx[:gl_c]}"). #escaped special character - gsub(/\\\_/,"#{Mx[:gl_o]}#095#{Mx[:gl_c]}"). #escaped special character - gsub(/\\\-/,"#{Mx[:gl_o]}#045#{Mx[:gl_c]}"). #escaped special character - gsub(/\\\+/,"#{Mx[:gl_o]}#043#{Mx[:gl_c]}"). #escaped special character - gsub(/\\\//,"#{Mx[:gl_o]}#047#{Mx[:gl_c]}"). #escaped special character - gsub(/\\\#/,"#{Mx[:gl_o]}#035#{Mx[:gl_c]}"). #escaped special character - gsub(/\\\&/,"#{Mx[:gl_o]}#038#{Mx[:gl_c]}"). #& #escaped special character - gsub(/\\\|/,"#{Mx[:gl_o]}#124#{Mx[:gl_c]}"). #not really a sisu special character but made available as possibility - gsub(/\\\:/,"#{Mx[:gl_o]}#058#{Mx[:gl_c]}"). #not really a sisu special character but made available as possibility - gsub(/\\\!/,"#{Mx[:gl_o]}#033#{Mx[:gl_c]}"). #not really a sisu special character but made available as possibility - gsub(/\\\^/,"#{Mx[:gl_o]}#094#{Mx[:gl_c]}"). #not really a sisu special character but made available as possibility - gsub(/\\\,/,"#{Mx[:gl_o]}#044#{Mx[:gl_c]}"). #not really a sisu special character but made available as possibility - gsub(/\\\\/,"#{Mx[:gl_o]}#092#{Mx[:gl_c]}"). #escaped special character - gsub(/\\\*/,"#{Mx[:gl_o]}#042#{Mx[:gl_c]}"). #escaped special character - gsub(/\\\!/,"#{Mx[:gl_o]}#033#{Mx[:gl_c]}") #escaped special character - if dob.obj=~/(?:https?:|ftp:|\{([^{}]+?)\}(?:#|:|[.]{1,2}\/))\S+/m - if dob.obj=~/(?:^|[#{Mx[:gl_c]}#{Mx[:nbsp]} ])\{~\^ (?:.+?)\s*\}(?:(?:https?:|ftp:|:|[.]{1,2}\/)\S+?)\s*#{Mx[:en_a_o]}(.+?)#{Mx[:en_a_c]}/m - dob.obj=dob.obj.gsub(/(^|[#{Mx[:gl_c]}#{Mx[:nbsp]} ])\{~\^ ([^}]+?)\s*\}((?:https?:|ftp:|:|[.]{1,2}\/)\S+?)\s*#{Mx[:en_a_o]}(.+?)#{Mx[:en_a_c]}/m, - "\\1#{Mx[:lnk_o]}\\2#{Mx[:lnk_c]}\\3 #{Mx[:en_a_o]}\\3 \\4#{Mx[:en_a_c]}") # watch - end - if dob.obj=~/(?:^|[#{Mx[:gl_c]}#{Mx[:nbsp]} ])\{~\^ (?:.+?)\s*\}(?:(?:https?:|ftp:|:|[.]{1,2}\/)\S+?)([;,.]?)(?=\s|[#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:br_nl]}]|$)/m - dob.obj=dob.obj.gsub(/(^|[#{Mx[:gl_c]}#{Mx[:nbsp]} ])\{~\^ (.+?)\s*\}((?:https?:|ftp:|:|[.]{1,2}\/)\S+?)([;,.]?)(?=\s|[#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:br_nl]}]|$)/m, - "\\1#{Mx[:lnk_o]}\\2#{Mx[:lnk_c]}\\3\\4 #{Mx[:en_a_o]}\\3#{Mx[:en_a_c]} ") - end - dob.obj=dob.obj.gsub(/(^|[^#])\{\s*([^{}]+?)\s*\}((?:https?:|:|[.]{2}\/|#)\S+?)(?=\s|[#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:br_nl]}#{Mx[:en_a_o]}#{Mx[:en_b_o]}]|$)/, - "\\1#{Mx[:lnk_o]}\\2#{Mx[:lnk_c]}\\3"). #linked (text or image, however text cannot include modified face, e.g. bold, ital, underline) - gsub(/(^|[#{Mx[:gl_c]}#{Mx[:lnk_c]}#{Mx[:en_a_o]}#{Mx[:en_b_o]}(\s])((?:https?|ftp):\/\/\S+?\.[^>< ]+?)([,.;'"]?)(?=[\s#{Mx[:en_a_c]}#{Mx[:en_b_c]}#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:br_nl]}]|$)/m, - %{\\1#{Mx[:url_o]}\\2#{Mx[:url_c]}\\3}). - gsub(/#{Mx[:lnk_c]}#(\S+?[^>< ]+?)([()\[\]]*[,.;:!?'"]{0,2})(?=[\s#{Mx[:en_a_c]}#{Mx[:en_b_c]}#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:br_nl]}]|$)/m, - %{#{Mx[:lnk_c]}#{Mx[:rel_o]}\\1#{Mx[:rel_c]}\\2}). - gsub(/#{Mx[:lnk_c]}:(\S+?[^>< ]+?)([()\[\]]*[,.;:!?'"]{0,2})(?=[\s#{Mx[:en_a_c]}#{Mx[:en_b_c]}#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:br_nl]}]|$)/m, - %{#{Mx[:lnk_c]}#{Mx[:rel_o]}:\\1#{Mx[:rel_c]}\\2}). - gsub(/#{Mx[:lnk_c]}[.]{2}\/(\S+?[^>< ]+?)([()\[\]]*[,.;:!?'"]{0,2})(?=[\s#{Mx[:en_a_c]}#{Mx[:en_b_c]}#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:br_nl]}]|$)/m, - %{#{Mx[:lnk_c]}#{Mx[:rel_o]}:\\1#{Mx[:rel_c]}\\2}) - end - if dob.obj=~/_(?:https?|ftp):\S+/m # _http://url #CHECK - dob.obj=dob.obj.gsub(/(^|[#{Mx[:gl_c]}#{Mx[:lnk_c]}#{Mx[:en_a_o]}#{Mx[:en_b_o]}(\s])(_(?:https?|ftp):\/\/\S+?\.[^>< ]+?)([,.;'"]?)(?=[\s#{Mx[:en_a_c]}#{Mx[:en_b_c]}#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:br_nl]}]|$)/m, - %{\\1#{Mx[:url_o]}\\2#{Mx[:url_c]}\\3}) - end - dob=fontface(dob) - dob.obj=dob.obj.gsub(/<[:e]\s+(.+?)!?>/, - "#{Mx[:en_a_o]}\\1#{Mx[:en_a_c]}"). #not tested - gsub(/(^|#{Mx[:br_nl]})\s*_\*\s*/, - "\\1#{Mx[:gl_bullet]}"). #bullets, shortcut - gsub(/=\{(.+?)\}/, - "#{Mx[:idx_o]}\\1#{Mx[:idx_c]}"). - gsub(/^\s*_([1-9])\*\s*/, - "#{Mx[:pa_o]}:i\\1:\\1#{Mx[:pa_c]}#{Mx[:gl_bullet]}"). #bullets, shortcut - gsub(/^\s*_([1-9])\s+/, - "#{Mx[:pa_o]}:i\\1:\\1#{Mx[:pa_c]}"). #indent - gsub(/^\s*_([1-9])!\s+(.+?)\s*$/, - "#{Mx[:pa_o]}:i\\1:\\1#{Mx[:pa_c]}#{Mx[:fa_bold_o]}\\2#{Mx[:fa_bold_c]} "). #indent bold - gsub(/^\s*__([1-9])\s+/, - "#{Mx[:pa_o]}:i0:\\1#{Mx[:pa_c]}"). #hang - gsub(/^\s*__([1-9])!\s+(.+?)\s*$/, - "#{Mx[:pa_o]}:i0:\\1#{Mx[:pa_c]}#{Mx[:fa_bold_o]}\\2#{Mx[:fa_bold_c]} "). #hangdef - gsub(/^\s*_([0-9])_([0-9])\s+/, - "#{Mx[:pa_o]}:i\\1:\\2#{Mx[:pa_c]}"). #hang - gsub(/^\s*_([0-9])_([0-9])!\s+(.+?)\s*$/, - "#{Mx[:pa_o]}:i\\1:\\2#{Mx[:pa_c]}#{Mx[:fa_bold_o]}\\3#{Mx[:fa_bold_c]} "). #hangdef - gsub(/<:hi>/,"#{Mx[:fa_hilite_o]}"). #''). # bright yellow rgb(255,255,0) pale yellow rgb(255,255,200) - gsub(/<:\/hi>/,"#{Mx[:fa_hilite_c]}"). #''). - gsub(/(#{Mx[:gr_o]}verse#{Mx[:gr_c]}.+)/m,"\\1\n"). - gsub(/[ ]+($)/,'\1'). - gsub(/\{\s*(.+?)\s*\}(https?:\S+?)([;,.]?)(?=\s|[#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:br_nl]}#{Mx[:en_a_o]}#{Mx[:en_b_o]}]|$)/, - "#{Mx[:lnk_o]}\\1#{Mx[:lnk_c]}#{Mx[:url_o]}\\2#{Mx[:url_c]}\\3"). #any remaining linked text or image - gsub(/\{\s*(.+?)\s*\}(#{Mx[:url_o]}\S+?#{Mx[:url_c]})/, - "#{Mx[:lnk_o]}\\1#{Mx[:lnk_c]}\\2"). #any remaining linked text or image - gsub(/(^|\s)([a-zA-Z0-9._-]+\@\S+?\.[a-zA-Z0-9._-]+)/,"\\1#{Mx[:url_o]}\\2#{Mx[:url_c]}"). - gsub(/(^|[ ])\{\s*(.+?)\s*\}(\S+?)([;,.]?)(?=\s|[#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:br_nl]}#{Mx[:en_a_o]}#{Mx[:en_b_o]}]|$)/, - "\\1#{Mx[:lnk_o]}\\2#{Mx[:lnk_c]}\\3\\4"). #any remaining linked text or image - gsub(/\{\s*(.+?)\s*\}#([a-zA-Z0-9][a-zA-Z0-9_-]*)([;,.]?)(?=\s|[#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:br_nl]}#{Mx[:en_a_o]}#{Mx[:en_b_o]}]|$)/, - "#{Mx[:lnk_o]}\\1#{Mx[:lnk_c]}#{Mx[:rel_o]}\\2#{Mx[:rel_c]}\\3"). #any remaining linked text or image, check need - gsub(/\{\s*(.+?)\s*\}(#{Mx[:rel_o]}\S+?#{Mx[:rel_c]})/, - "#{Mx[:lnk_o]}\\1#{Mx[:lnk_c]}\\2"). #any remaining linked text or image, check need - gsub(/\{\s*(.+?)\s*\}(image)/, - "#{Mx[:lnk_o]}\\1#{Mx[:lnk_c]}\\2") #linked image - elsif dob.is==:table - dob=fontface(dob) - elsif dob.is ==:code - dob.obj=dob.obj.gsub(/#{Mx[:meta_o]}(\S+?)#{Mx[:meta_c]}\s*/,'@\1: '). - gsub(/(^|#{Mx[:gl_c]}|\s)<(br(?: \/)?)>([\s,.]|$)/,'\1<\2>\3') #convert

back, clumsy - if dob.number_ - codeline=[] - ln=1 - dob.obj.split(/#{Mx[:gr_o]}codeline#{Mx[:gr_c]}||\n/).each_with_index do |cl,i| - unless i == 0 - cl=cl.gsub(Mx[:br_nl],'') - w=3-ln.to_s.length - cl = "#{ln}#{Mx[:nbsp]*w}#{Mx[:vline]}#{cl}#{Mx[:br_nl]}" - ln +=1 - end - codeline << cl - end - codeline= codeline.join("") - dob.obj=codeline - else - dob.obj=dob.obj.gsub(/#{Mx[:gr_o]}codeline#{Mx[:gr_c]}/,"\n") - end - dob - else # @\S+?: - end - dob - end - def tech #script markup planned to be more strict for technical documents - # *{emphasis}* e{emphasis}e emphasis - # !{bold text}! b{bold}b bold text - # _{underline}_ u{underline}u underline - # /{italics}/ i{italics}i italics - # "{citation}" c{citation}c citation - # ^{superscript}^ superscript - # ,{subscript}, subscript - # +{inserted text}+ inserted text - # -{deleted text}- deleted text - # #{monospace text}# - # {url address}:url - # {image.png}imageurl - # {image.png}png - # ~{endnote}~ - # +1 - # +2 - puts 'tech' - @data.each do |line| - line=line.gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|[\(\[]|\>)e\{(.+?)\}e/, - "\\1#{@emph[:o]}\\2#{@emph[:c]}"). #emphasis - gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|[\(\[]|\>)b\{(.+?)\}b/, - "\\1#{Mx[:fa_bold_o]}\\2#{Mx[:fa_bold_c]}"). #bold - gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|[\(\[]|\>)u\{(.+?)\}u/, - "\\1#{Mx[:fa_underscore_o]}\\2#{Mx[:fa_underscore_c]}"). #underscore - gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|[\(\[]|\>)c\{(.+?)\}c/, - "\\1#{Mx[:fa_cite_o]}\\2#{Mx[:fa_c_o]}cite#{Mx[:fa_c]}"). #cite - gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|[\(\[]|\>)i\{(.+?)\}i/, - "\\1#{Mx[:fa_italics_o]}\\2#{Mx[:fa_italics_c]}"). #italics - gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|[\(\[]|\>)!\{(.+?)\}!/, - "\\1#{Mx[:fa_bold_o]}\\2#{Mx[:fa_bold_c]}"). #bold - gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|[\(\[]|\>)\*\{(.+?)\}\*/, - "\\1#{@emph[:o]}\\2#{@emph[:c]}"). #emphasis - gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|[\(\[]|\>)_\{(.+?)\}_/, - "\\1#{Mx[:fa_underscore_o]}\\2#{Mx[:fa_underscore_c]}"). #underscore - gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|[\(\[]|\(|\>)\/\{(.+?)\}\//, - "\\1#{Mx[:fa_italics_o]}\\2#{Mx[:fa_italics_c]}"). #italics - gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)\"\{(.+?)\}\"/, - "\\1#{Mx[:fa_cite_o]}\\2#{Mx[:fa_c_o]}cite#{Mx[:fa_c]}"). - gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)\^\{(.+?)\}\^/, - "\\1#{Mx[:fa_superscript_o]}\\2#{Mx[:fa_superscript_c]}"). - gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)9\{(.+?)\}9/, - "\\1#{Mx[:fa_superscript_o]}\\2#{Mx[:fa_superscript_c]}"). - gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>),\{(.+?)\},/, - "\\1#{Mx[:fa_subscript_o]}\\2#{Mx[:fa_subscript_c]}"). - gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)6\{(.+?)\}6/, - "\\1#{Mx[:fa_subscript_o]}\\2#{Mx[:fa_subscript_c]}"). - gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)\+\{(.+?)\}\+/, - "\\1#{Mx[:fa_insert_o]}\\2#{Mx[:fa_insert_c]}"). - gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)v\{(.+?)\}v/, - "\\1#{Mx[:fa_insert_o]}\\2#{Mx[:fa_insert_c]}"). - gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)-\{(.+?)\}-/, - "\\1#{Mx[:fa_strike_o]}\\2#{Mx[:fa_strike_c]}"). - gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)x\{(.+?)\}x/, - "\\1#{Mx[:fa_strike_o]}\\2#{Mx[:fa_strike_c]}"). - gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)\*(\S+?)\*/, - "\\1#{@emph[:o]}\\2#{@emph[:c]}"). #emphasise single word, watch - gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)\!(\S+?)\!/, - "\\1#{Mx[:fa_bold_o]}\\2#{Mx[:fa_bold_c]}"). #bold single word, watch - gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)\/([\(\)a-zA-Z0-9']+?)\/([ ,.;:'"~$]|[^a-zA-Z0-9])/, - "\\1#{Mx[:fa_italics_o]}\\2#{Mx[:fa_italics_c]}\\3"). #italics single word, watch - gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)_(\S+?)_/, - "\\1#{Mx[:fa_underscore_o]}\\2#{Mx[:fa_underscore_c]}"). #underscore single word, watch - gsub(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)\^(\S+?)\^/, - "\\1#{Mx[:fa_superscript_o]}\\2#{Mx[:fa_superscript_c]}"). #check #superscript single word, watch digit added - gsub(/^\s*_\([1-9]\)\(\*\+\)\s*/, - "#{Mx[:pa_o]}:i\\1#{Mx[:pa_c]}#{Mx[:fa_o]}\\2#{Mx[:fa_c_o]}"). #bullets, shortcut - gsub(/^\s*_\([1-9]\)\s+/, - "#{Mx[:pa_o]}:i\\1#{Mx[:pa_c]}"). #watch - gsub(/^\s*__\([1-9]\)\s+/, - "#{Mx[:pa_o]}:h\\1#{Mx[:pa_c]}"). #watch - #line.gsub(/^\s*__\([1-9]\)!\s+/, - # "#{Mx[:pa_o]}:hd\\1#{Mx[:pa_c]}"). #watch - gsub(/#{Mx[:br_line]}\s*_[12]\s+/, - "#{Mx[:br_line]} ") #indent used in endnotes, not implemented, replace when ready with: line.gsub(/(?:
|
)\s*_([12])\s+/,'
<:i\1> ') - end - @data - end - end -end -__END__ diff --git a/lib/sisu/v5/db_import.rb b/lib/sisu/v5/db_import.rb index 6edb0f99..147f27df 100644 --- a/lib/sisu/v5/db_import.rb +++ b/lib/sisu/v5/db_import.rb @@ -121,8 +121,8 @@ module SiSU_DbImport @@dl ||=SiSU_Env::InfoEnv.new.digest.length end def marshal_load - require_relative 'dal' # dal.rb - @dal_array=SiSU_DAL::Source.new(@opt).get # dal file drawn here + require_relative 'ao' # ao.rb + @dal_array=SiSU_AO::Source.new(@opt).get # dal file drawn here if (@opt.act[:verbose][:set]==:on \ || @opt.act[:verbose_plus][:set]==:on \ || @opt.act[:maintenance][:set]==:on) diff --git a/lib/sisu/v5/git.rb b/lib/sisu/v5/git.rb index 92322b7c..447117ca 100644 --- a/lib/sisu/v5/git.rb +++ b/lib/sisu/v5/git.rb @@ -62,7 +62,7 @@ module SiSU_Git require_relative 'param' # param.rb require_relative 'sysenv' # sysenv.rb - require_relative 'dal' # dal.rb + require_relative 'ao' # ao.rb class Source def initialize(opt) @opt=opt @@ -93,7 +93,7 @@ module SiSU_Git video: git_path_fnb + '/' + Gt[:sisupod] + '/' + Gt[:video], conf: git_path_fnb + '/' + Gt[:sisupod] + '/' + Gt[:conf] } - SiSU_DAL::Source.new(@opt).read # -m + SiSU_AO::Source.new(@opt).read # -m end def create_file_structure_git make_dir_fnb @@ -192,7 +192,7 @@ module SiSU_Git if composite_src \ and not @opt.act[:dal][:set]==:on ##SiSU_Assemble::Composite.new(@opt).read - #SiSU_DAL::Source.new(@opt).read # -m + #SiSU_AO::Source.new(@opt).read # -m "#{@env.processing_path.composite_file}/#{@opt.fnb}.ssm.sst" elsif composite_src "#{@env.processing_path.composite_file}/#{@opt.fnb}.ssm.sst" diff --git a/lib/sisu/v5/html_format.rb b/lib/sisu/v5/html_format.rb index c087f1ec..3a20ef67 100644 --- a/lib/sisu/v5/html_format.rb +++ b/lib/sisu/v5/html_format.rb @@ -904,7 +904,7 @@ WOK @lnk_url =t_o[:lnk_url] || nil @lnk_txt =t_o[:lnk_txt] || nil @format =t_o[:format] || nil - elsif t_o.class.inspect =~/^(?:#<)?SiSU_DAL_DocumentStructure/ + elsif t_o.class.inspect =~/^(?:#<)?SiSU_AO_DocumentStructure/ @dob=t_o if defined? t_o.is @named=nametags_seg(@dob) @txt=((defined? t_o.obj) ? t_o.obj : nil) diff --git a/lib/sisu/v5/hub.rb b/lib/sisu/v5/hub.rb index c158f214..c6545c1d 100644 --- a/lib/sisu/v5/hub.rb +++ b/lib/sisu/v5/hub.rb @@ -286,8 +286,8 @@ module SiSU require_relative 'composite' # composite.rb #pre-processing SiSU_Assemble::Composite.new(@opt).read end - require_relative 'dal' # -m dal.rb - SiSU_DAL::Source.new(@opt).read + require_relative 'ao' # -m ao.rb + SiSU_AO::Source.new(@opt).read end end if @opt.act[:qrcode][:set]==:on #% --qrcode, -Q diff --git a/lib/sisu/v5/manpage.rb b/lib/sisu/v5/manpage.rb index 44180819..8f721fd2 100644 --- a/lib/sisu/v5/manpage.rb +++ b/lib/sisu/v5/manpage.rb @@ -61,7 +61,7 @@ =end module SiSU_Manpage - require_relative 'dal' # dal.rb + require_relative 'ao' # ao.rb require_relative 'sysenv' # sysenv.rb include SiSU_Env include SiSU_Param @@ -100,7 +100,7 @@ module SiSU_Manpage || @opt.act[:maintenance][:set]==:on) SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],@opt.fns,"#{@md.file.output_path.manpage.dir}/#{@md.file.base_filename.manpage}").flow end - @dal_array=SiSU_DAL::Source.new(@opt).get # dal file drawn here + @dal_array=SiSU_AO::Source.new(@opt).get # dal file drawn here SiSU_Manpage::Source::Scroll.new(@md,@dal_array).songsheet rescue SiSU_Errors::Rescued.new($!,$@,@opt.cmd,@opt.fns).location do diff --git a/lib/sisu/v5/odf.rb b/lib/sisu/v5/odf.rb index 3e83e1cf..b64c8ebe 100644 --- a/lib/sisu/v5/odf.rb +++ b/lib/sisu/v5/odf.rb @@ -62,7 +62,7 @@ module SiSU_ODF require_relative 'particulars' # particulars.rb include SiSU_Particulars - require_relative 'dal' # dal.rb + require_relative 'ao' # ao.rb require_relative 'sysenv' # sysenv.rb include SiSU_Env include SiSU_Viz diff --git a/lib/sisu/v5/particulars.rb b/lib/sisu/v5/particulars.rb index 000748ff..d06afc12 100644 --- a/lib/sisu/v5/particulars.rb +++ b/lib/sisu/v5/particulars.rb @@ -66,7 +66,7 @@ module SiSU_Particulars include SiSU_Env require_relative 'param' # param.rb include SiSU_Param - require_relative 'dal' # dal.rb + require_relative 'ao' # ao.rb class CombinedSingleton include Singleton def get_all(opt) @@ -152,7 +152,7 @@ module SiSU_Particulars attr_accessor :opt,:dal_array def set_dal(opt) begin - @dal_array=SiSU_DAL::Source.new(opt).get + @dal_array=SiSU_AO::Source.new(opt).get self rescue SiSU_Errors::Rescued.new($!,$@,opt.cmd,opt.fnl).location do @@ -162,7 +162,7 @@ module SiSU_Particulars end def set_sst_idx(opt) begin - @sst_idx=SiSU_DAL::Source.new(opt).get_idx_sst + @sst_idx=SiSU_AO::Source.new(opt).get_idx_sst self rescue SiSU_Errors::Rescued.new($!,$@,opt.cmd,opt.fnl).location do @@ -172,7 +172,7 @@ module SiSU_Particulars end def set_raw_idx(opt) begin - @raw_idx=SiSU_DAL::Source.new(opt).get_idx_raw + @raw_idx=SiSU_AO::Source.new(opt).get_idx_raw self rescue SiSU_Errors::Rescued.new($!,$@,opt.cmd,opt.fnl).location do @@ -182,7 +182,7 @@ module SiSU_Particulars end def set_html_idx(opt) begin - @html_idx=SiSU_DAL::Source.new(opt).get_idx_html + @html_idx=SiSU_AO::Source.new(opt).get_idx_html self rescue SiSU_Errors::Rescued.new($!,$@,opt.cmd,opt.fnl).location do @@ -192,7 +192,7 @@ module SiSU_Particulars end def set_xhtml_idx(opt) begin - @xhtml_idx=SiSU_DAL::Source.new(opt).get_idx_xhtml + @xhtml_idx=SiSU_AO::Source.new(opt).get_idx_xhtml self rescue SiSU_Errors::Rescued.new($!,$@,opt.cmd,opt.fnl).location do @@ -204,7 +204,7 @@ module SiSU_Particulars def set_nametags_map(opt) begin opt=@md ? @md : opt - @nametags_map=SiSU_DAL::Source.new(opt).get_map_nametags + @nametags_map=SiSU_AO::Source.new(opt).get_map_nametags self rescue if @md @@ -221,7 +221,7 @@ module SiSU_Particulars attr_accessor :ocn_htmlseg_map def set_ocn_htmlseg_map(opt) begin - @ocn_htmlseg_map=SiSU_DAL::Source.new(@md).get_map_ocn_htmlseg + @ocn_htmlseg_map=SiSU_AO::Source.new(@md).get_map_ocn_htmlseg self rescue SiSU_Errors::Rescued.new($!,$@,opt.cmd,opt.fnl).location do diff --git a/lib/sisu/v5/plaintext.rb b/lib/sisu/v5/plaintext.rb index 49c198e7..8585ad9d 100644 --- a/lib/sisu/v5/plaintext.rb +++ b/lib/sisu/v5/plaintext.rb @@ -61,7 +61,7 @@ =end module SiSU_Plaintext - require_relative 'dal' # dal.rb + require_relative 'ao' # ao.rb require_relative 'sysenv' # sysenv.rb include SiSU_Env require_relative 'plaintext_format' # plaintext_format.rb @@ -99,7 +99,7 @@ module SiSU_Plaintext SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],@opt.fns,"#{md.file.output_path.txt.dir}/#{md.file.base_filename.txt}").flow end end - dal_array=SiSU_DAL::Source.new(@opt).get # dal file drawn here + dal_array=SiSU_AO::Source.new(@opt).get # dal file drawn here wrap_width=if defined? md.make.plaintext_wrap \ and md.make.plaintext_wrap md.make.plaintext_wrap diff --git a/lib/sisu/v5/po4a.rb b/lib/sisu/v5/po4a.rb index 64f2c18d..43ff51e9 100644 --- a/lib/sisu/v5/po4a.rb +++ b/lib/sisu/v5/po4a.rb @@ -61,7 +61,7 @@ =end module SiSU_Po4a - require_relative 'dal' # dal.rb + require_relative 'ao' # ao.rb require_relative 'sysenv' # sysenv.rb include SiSU_Env require_relative 'composite' # composite.rb @@ -101,7 +101,7 @@ module SiSU_Po4a end md=SiSU_Param::Parameters.new(@opt).get src[:files].each do |fn| - SiSU_DAL::Source.new(@opt,fn).read # -m + SiSU_AO::Source.new(@opt,fn).read # -m env=SiSU_Env::InfoEnv.new(@opt.fns) m=/((.+?)(?:\~\w\w(?:_\w\w)?)?)\.((?:-|ssm\.)?sst|ssm|ssi)$/ #watch added match for sss @fnn,@fnb,@fnt=fn[m,1],fn[m,2],fn[m,3] @@ -126,7 +126,7 @@ module SiSU_Po4a if @opt.fns =~/\S+?~#{@lang_regx}\.ss[mti]/ \ or @opt.f_pth[:lng] !=@opt.lng_base opt_lang_trn_fn=fn - @dal_array_lang_translation=SiSU_DAL::Source.new(@opt,opt_lang_trn_fn).get # dal file drawn here + @dal_array_lang_translation=SiSU_AO::Source.new(@opt,opt_lang_trn_fn).get # dal file drawn here opt_lang_src_fn=if fn =~/\S+?~\S{2}(?:_\S{2})?\.ss[mti]/ fn.gsub(/(\S+?)~\S{2}(?:_\S{2})?(\.ss[mti])/,'\1\2') #check i else fn @@ -141,14 +141,14 @@ module SiSU_Po4a else nil end if FileTest.file?("#{srcdir}/#{opt_lang_src_fn}") - @dal_array_lang_src=SiSU_DAL::Source.new(@@opt_src,opt_lang_src_fn).get # dal file drawn here + @dal_array_lang_src=SiSU_AO::Source.new(@@opt_src,opt_lang_src_fn).get # dal file drawn here else puts "no identified source document" exit end Dir.chdir(transdir) if transdir else - @dal_array_lang_src=SiSU_DAL::Source.new(@opt,fn).get # dal file drawn here + @dal_array_lang_src=SiSU_AO::Source.new(@opt,fn).get # dal file drawn here @dal_array_lang_translation=nil end wrap_width=if defined? md.make.plaintext_wrap \ diff --git a/lib/sisu/v5/sst_do_inline_footnotes.rb b/lib/sisu/v5/sst_do_inline_footnotes.rb index 836d0d29..f03c1c34 100644 --- a/lib/sisu/v5/sst_do_inline_footnotes.rb +++ b/lib/sisu/v5/sst_do_inline_footnotes.rb @@ -67,8 +67,8 @@ module SiSU_ConvertFootnotes include SiSU_Env require_relative 'param' # param.rb include SiSU_Param - require_relative 'dal_syntax' # dal_syntax.rb - include SiSU_DAL_Syntax + require_relative 'ao_syntax' # ao_syntax.rb + include SiSU_AO_Syntax require_relative 'i18n' # i18n.rb class Instantiate < SiSU_Param::Parameters::Instructions @@flag={} #Beware!! diff --git a/lib/sisu/v5/sst_to_s_xml_sax.rb b/lib/sisu/v5/sst_to_s_xml_sax.rb index d6767595..a3fbde9f 100644 --- a/lib/sisu/v5/sst_to_s_xml_sax.rb +++ b/lib/sisu/v5/sst_to_s_xml_sax.rb @@ -68,7 +68,7 @@ module SiSU_SimpleXML_ModelSax include SiSU_Param require_relative 'sysenv' # sysenv.rb include SiSU_Env - require_relative 'dal_doc_str' # dal_doc_str.rb + require_relative 'ao_doc_str' # ao_doc_str.rb require_relative 'shared_xml' # shared_xml.rb include SiSU_XML_Munge require_relative 'shared_sem' # shared_sem.rb @@ -276,7 +276,7 @@ WOK (0..6).each { |x| @cont[x]=@level[x]=false } (4..6).each { |x| @xml_contents_close[x]='' } @data.each do |para| - data << SiSU_DAL_DocumentStructureExtract::Structure.new(@md,para).structure #takes on Mx marks + data << SiSU_AO_DocumentStructureExtract::Structure.new(@md,para).structure #takes on Mx marks end data.each do |para| if para !~/^\s*(?:%+ |<:code>)/ diff --git a/lib/sisu/v5/sysenv.rb b/lib/sisu/v5/sysenv.rb index d4079f8c..19031711 100644 --- a/lib/sisu/v5/sysenv.rb +++ b/lib/sisu/v5/sysenv.rb @@ -142,7 +142,7 @@ module SiSU_Env PROCESSING_PATH=:processing_path PROCESSING_DIR_TMP_ROOT=:processing_dir_tmp_root PROCESSING_PATH_TMP_BASE=:processing_path_tmp_base - PROCESSING_DAL=:processing_dal + PROCESSING_AO=:processing_dal PROCESSING_TUNE=:processing_tune PROCESSING_LATEX=:processing_latex PROCESSING_TEXINFO=:processing_texinfo @@ -186,7 +186,7 @@ module SiSU_Env PROCESSING_PATH => processing_pth, PROCESSING_DIR_TMP_ROOT => prcss_dir_tmp_root, PROCESSING_PATH_TMP_BASE => processing_pth, - PROCESSING_DAL => 'dal', + PROCESSING_AO => 'ao', PROCESSING_TUNE => 'tune', PROCESSING_LATEX => 'tex', PROCESSING_TEXINFO => 'texinfo', diff --git a/lib/sisu/v5/texpdf.rb b/lib/sisu/v5/texpdf.rb index 2dc3e860..df089d31 100644 --- a/lib/sisu/v5/texpdf.rb +++ b/lib/sisu/v5/texpdf.rb @@ -81,8 +81,8 @@ module SiSU_TeX require_relative 'sysenv' # sysenv.rb include SiSU_Env include SiSU_Viz - require_relative 'dal' # dal.rb - include SiSU_DAL + require_relative 'ao' # ao.rb + include SiSU_AO include SiSU_TeX def initialize(opt) @opt=opt @@ -126,7 +126,7 @@ module SiSU_TeX $flag=@md.opt.cmd #introduced to pass 0 for no object citation numbers... to texpdf_format directories #% needed needs to be reprogrammed !!! - dal_array=SiSU_DAL::Source.new(@opt).get # dal file drawn here + dal_array=SiSU_AO::Source.new(@opt).get # dal file drawn here SiSU_TeX::Source::LaTeXcreate.new(@particulars).songsheet dal_array='' pwd=Dir.pwd @@ -1042,7 +1042,7 @@ module SiSU_TeX file[:landscape].puts morph,"\n" end end - elsif morph.class.inspect =~ /SiSU_DAL_DocumentStructure/ \ + elsif morph.class.inspect =~ /SiSU_AO_DocumentStructure/ \ and morph.tmp \ and morph.tmp.is_a?(String) if morph.is !=:code \ diff --git a/lib/sisu/v5/wikispeak.rb b/lib/sisu/v5/wikispeak.rb index da8fc9fa..eab2336d 100644 --- a/lib/sisu/v5/wikispeak.rb +++ b/lib/sisu/v5/wikispeak.rb @@ -60,7 +60,7 @@ =end module SiSU_Wikispeak - require_relative 'dal' # dal.rb + require_relative 'ao' # ao.rb require_relative 'sysenv' # sysenv.rb include SiSU_Env include SiSU_Param @@ -90,7 +90,7 @@ module SiSU_Wikispeak || @opt.act[:maintenance][:set]==:on) SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],@opt.fns,"#{@env.path.output_tell}/#{@md.fnb}/#{@md.fn[:wiki]}").flow end - @dal_array=SiSU_DAL::Source.new(@opt).get # dal file drawn here + @dal_array=SiSU_AO::Source.new(@opt).get # dal file drawn here SiSU_Wikispeak::Source::Scroll.new(@dal_array,@md).songsheet rescue SiSU_Errors::Rescued.new($!,$@,@opt.cmd,@opt.fns).location do diff --git a/lib/sisu/v5/xml_dom.rb b/lib/sisu/v5/xml_dom.rb index f6d86883..36a0dae1 100644 --- a/lib/sisu/v5/xml_dom.rb +++ b/lib/sisu/v5/xml_dom.rb @@ -66,7 +66,7 @@ module SiSU_XML_DOM include SiSU_Particulars require_relative 'sysenv' # sysenv.rb include SiSU_Env - require_relative 'dal' # dal.rb + require_relative 'ao' # ao.rb require_relative 'shared_xml' # shared_xml.rb include SiSU_XML_Munge require_relative 'xml_format' # xml_format.rb diff --git a/lib/sisu/v5/xml_scaffold_structure_collapsed.rb b/lib/sisu/v5/xml_scaffold_structure_collapsed.rb index a90207ff..8f14ea54 100644 --- a/lib/sisu/v5/xml_scaffold_structure_collapsed.rb +++ b/lib/sisu/v5/xml_scaffold_structure_collapsed.rb @@ -62,7 +62,7 @@ module SiSU_XML_Scaffold_Structure_Collapse require_relative 'particulars' # particulars.rb include SiSU_Particulars - require_relative 'dal' # dal.rb + require_relative 'ao' # ao.rb require_relative 'sysenv' # sysenv.rb include SiSU_Env class Source diff --git a/lib/sisu/v5/xml_scaffold_structure_sisu.rb b/lib/sisu/v5/xml_scaffold_structure_sisu.rb index 64173566..12e1088a 100644 --- a/lib/sisu/v5/xml_scaffold_structure_sisu.rb +++ b/lib/sisu/v5/xml_scaffold_structure_sisu.rb @@ -62,7 +62,7 @@ module SiSU_XML_Scaffold_Structure_Sisu require_relative 'particulars' # particulars.rb include SiSU_Particulars - require_relative 'dal' # dal.rb + require_relative 'ao' # ao.rb require_relative 'sysenv' # sysenv.rb include SiSU_Env class Source -- cgit v1.2.3