'
+ 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
'
+ 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
+ data.each.map do |para|
+ para.gsub(/\n*#{@rgx_idx}/m,'')
+ end
+ end
+ end
+end
+__END__
diff --git a/lib/sisu/ao_images.rb b/lib/sisu/ao_images.rb
new file mode 100644
index 00000000..06aec134
--- /dev/null
+++ b/lib/sisu/ao_images.rb
@@ -0,0 +1,187 @@
+# encoding: utf-8
+=begin
+
+* Name: SiSU
+
+** Description: documents, structuring, processing, publishing, search
+*** system environment, resource control and configuration details
+
+** Author: Ralph Amissah
+
+
+
+** Copyright: (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
+ 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 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:
+
+
+
+** Git
+
+
+
+=end
+module SiSU_AO_Images
+ class Images
+ begin
+ require 'RMagick'
+ include Magick
+ rescue LoadError
+ #SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).mark('RMagic NOT FOUND')
+ end
+ def initialize(md,data)
+ @md,@data=md,data
+ end
+ def images
+ data=@data
+ @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_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.select 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_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.graphicsmagick
+ 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
+ else
+ errmsg='imagemagick or graphicsmagick are required to process images'
+ if @md.opt.act[:no_stop][:set]==:on
+ SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).
+ error("#{errmsg}, proceeding (as requested) without image processing")
+ break
+ else
+ SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).
+ error("#{errmsg}, STOPPING")
+ exit
+ end
+ 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
+ dob unless dob.nil?
+ end
+ end
+ end
+end
+__END__
+imgsys=`identify #{image_path}/#{image}`.strip
diff --git a/lib/sisu/ao_metadata.rb b/lib/sisu/ao_metadata.rb
new file mode 100644
index 00000000..1a9418ce
--- /dev/null
+++ b/lib/sisu/ao_metadata.rb
@@ -0,0 +1,86 @@
+# encoding: utf-8
+=begin
+
+* Name: SiSU
+
+** Description: documents, structuring, processing, publishing, search
+*** system environment, resource control and configuration details
+
+** Author: Ralph Amissah
+
+
+
+** Copyright: (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
+ 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 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:
+
+
+
+** Git
+
+
+
+=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/ao_misc_arrange.rb b/lib/sisu/ao_misc_arrange.rb
new file mode 100644
index 00000000..da54bb80
--- /dev/null
+++ b/lib/sisu/ao_misc_arrange.rb
@@ -0,0 +1,207 @@
+# encoding: utf-8
+=begin
+
+* Name: SiSU
+
+** Description: documents, structuring, processing, publishing, search
+*** system environment, resource control and configuration details
+
+** Author: Ralph Amissah
+
+
+
+** Copyright: (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
+ 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 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:
+
+
+
+** Git
+
+
+
+=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-D])~\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 markup_blocks(para)
+ def ticks(para)
+ block_open,block_close,text=nil,nil,nil
+ if para =~/\A```[ ]+(?:code(?:\.[a-z][0-9a-z_]+)?|box(?:\.[a-z_]+)?|poem|alt|group|block|table).*?\n.+?\n```(?:\s+[~-][#]|\s+\~\{.+?\}\~)?\s*\Z/m
+ @flag=:close
+ block_open,text,block_close=
+ /\A(```[ ]+(?:code(?:\.[a-z][0-9a-z_]+)?|box(?:\.[a-z_]+)?|poem|alt|group|block|table).*?)\n(.+?)\n(```([ ]+[~-][#]|\s+\~\{.+?\}\~)?)\s*\Z/m.
+ match(para)[1..3]
+ ((para=~/^```[ ]+table(?:~h)?\s+/) \
+ and (para !~/^```[ ]+table(?:~h)?\s+c\d+/)) \
+ ? para
+ : (para=[]; para << block_open << text << block_close)
+ elsif para =~/\A```[ ]+(?:code(?:\.[a-z][0-9a-z_]+)?|box(?:\.[a-z_]+)?|poem|alt|group|block|table).*?\n.*?\Z/m #look at, study
+ @flag=:open
+ block_open,text=/\A(```(?:[ ]+.+?))\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```(?:\s+\~\{.+?\}\~)?(?:\s+[~-][#])?(\s*=\{.+?\})?\s*\Z/m \
+ and @flag==:open
+ @flag=:close
+ text,block_close=
+ /\A(.+?)\n(```(?:\s+\~\{.+?\}\~)?(?:\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 ticks_remove(para)
+ unless @md.opt.act[:quiet][:set] ==:on
+ SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:fuchsia).
+ mark("ticks not recognized, ticks removed from pargraph\n#{para}")
+ end
+ para=para.gsub(/```[ ]+\S+[ ]*/m,'').
+ gsub(/```\s*/m,'').
+ strip
+ end
+ def ticks_quote(para)
+ @flag=:quote_open
+ text=para
+ para=[]
+ if text =~ /```[ ]+quote/m
+ para << '`:quote_open`'
+ text=text.gsub(/```[ ]+quote/m,'')
+ end
+ text=if text =~/(?:\n|\A)=\{.+?\}/m #exclude book index from indent markup
+ txt,bkidx,tail=/(.+?)((?:\n|\A)=\{.+?\}$)(.*)/m.match(text).captures
+ txt=txt.gsub(/(?:\n|\A)([^`\n]+)/m,'_1 \1')
+ txt + bkidx + tail
+ else text.gsub(/(?:\n|\A)([^`\n]+)/m,'_1 \1')
+ end
+ para << text.gsub(/```/m,'')
+ if text =~/```/m
+ @flag=:quote_close
+ para << '`:quote_close`'
+ end
+ para
+ end
+ def curly_braces(para)
+ block_open,block_close,text=nil,nil,nil
+ para=if para =~/\A(?:code(?:\.[a-z][0-9a-z_]+)?|box(?:\.[a-z_]+)?|poem|alt|group|block|table)\{ .+?\n.+?\n\}(?:code|box|poem|alt|group|block|table)(?: [~-][#])?\s*\Z/m
+ block_open,text,block_close=
+ /\A((?:code(?:\.[a-z][0-9a-z_]+)?|box(?:\.[a-z_]+)?|poem|alt|group|block|table)\{ .+?)\n(.+?)\n(\}(?:code|box|poem|alt|group|block|table)(?: [~-][#])?)\s*\Z/m.
+ match(para)[1..3]
+ para=[]
+ para << block_open << text << block_close
+ elsif para =~/\A(?:code(?:\.[a-z][0-9a-z_]+)?|box(?:\.[a-z_]+)?|poem|alt|group|block|table)\{ .+?\n.+?\Z/m
+ block_open,text=
+ /\A((?:code(?:\.[a-z][0-9a-z_]+)?|box(?:\.[a-z_]+)?|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|box|poem|alt|group|block|table)(?: [~-][#])?\s*\Z/m
+ text,block_close=
+ /\A(.+?)\n(\}(?:code|box|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=if (para =~/\A```[ ]+quote/m \
+ and @flag !=:open) \
+ or @flag==:quote_open
+ ticks_quote(para)
+ elsif para =~/\A```[ ]+(?:code(?:\.[a-z][0-9a-z_]+)?|box(?:\.[a-z_]+)?|poem|alt|group|block|table).*?\n.*?\Z/m \
+ or @flag==:open
+ ticks(para)
+ elsif para =~/```/m
+ ticks_remove(para)
+ else
+ para
+ end
+ para=if para =~/^(?:code(?:\.[a-z][0-9a-z_]+)?|box(?:\.[a-z_]+)?|poem|alt|group|block|table)\{|^\}(?:code|box|poem|alt|group|block|table)/m
+ curly_braces(para)
+ else
+ para
+ end
+ end
+ def prepare_text
+ data=@data
+ 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.map do |para|
+ para=conditional_headings(para)
+ markup_blocks(para)
+ end.flatten
+ end
+ end
+end
+__END__
diff --git a/lib/sisu/ao_numbering.rb b/lib/sisu/ao_numbering.rb
new file mode 100644
index 00000000..fdf54605
--- /dev/null
+++ b/lib/sisu/ao_numbering.rb
@@ -0,0 +1,720 @@
+# encoding: utf-8
+=begin
+
+* Name: SiSU
+
+** Description: documents, structuring, processing, publishing, search
+*** system environment, resource control and configuration details
+
+** Author: Ralph Amissah
+
+
+
+** Copyright: (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
+ 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 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:
+
+
+
+** Git
+
+
+
+=end
+module SiSU_AO_Numbering
+ class Numbering
+ attr_accessor :obj,:osp,:ocn,:lv,:name,:index,:comment
+ @@segments_count=0
+ def initialize(md,data,fnx,process)
+ @md,@data,@fnx,@process=md,data,fnx,process
+ @obj=@type=@ocn=@lv=@name=@index=@comment=nil
+ @chosen_seg_names=[]
+ end
+ def chosen_seg_names(chosen,chosen_seg_name,dob,md,type)
+ @chosen_seg_names=if chosen.compact.uniq.length \
+ == chosen.compact.length
+ chosen
+ else
+ if md.opt.act[:maintenance][:set]==:on
+ SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:green).
+ mark(
+ "duplicated auto segment name: #{type} #{chosen}\n" \
+ + "#{chosen}\n" \
+ + " manually name level 1 segments '1~given_name'\n" \
+ + 'filename: ' + md.fns + "\n" \
+ + 'heading text: "' + dob.obj + '"' + "\n" \
+ + 'duplication: "' + chosen_seg_name + '" (level: ' + dob.lv + '; numbering type: ' + type.to_s + ')'
+ )
+ end
+ chosen=chosen[0..-2]
+ chosen_seg_name=auto_numbering_exceptions(chosen,md,dob)
+ chosen << chosen_seg_name
+ end
+ end
+ def number_of_segments?
+ if @@segments_count==0
+ @data.each do |dob|
+ if dob.is == :heading \
+ and dob.lv == '1'
+ @@segments_count += 1
+ end
+ end
+ @@segments_count
+ else @@segments_count
+ end
+ end
+ def numbering_song
+ begin
+ 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)
+ if @process==:complete
+ data,tags_map,ocn_html_seg_map=name_para_seg_filename(data)
+ end
+ data=set_heading_top(data) unless @md.set_heading_top
+ [data,tags_map,ocn_html_seg_map]
+ ensure
+ @@segments_count=0
+ end
+ end
+ def set_tags(tags,tag)
+ tags=if not tag.empty? \
+ and tag !~/^\d+$/
+ tag=tag.gsub(/[^a-z0-9._-]/,'')
+ [tag,tags].flatten
+ else tags
+ end
+ 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 /-/ then dob.obj.gsub(/^/,"#{title_no} ")
+ when /^#/ then dob.obj.gsub(/^/,"#{title_no} ")
+ when /^[a-z_\.]+/ then 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
+ 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
+ @tuned_file=data.each.map do |dob| #@md.seg_names << [additions to segment names]
+ title_no=nil
+ 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 =~/^[0-6]/ \
+ and not dob.use_ ==:dummy \
+ 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=set_tags(dob.tags,title_no)
+ tag=dob.obj.
+ gsub(/(Article|Clause|Section|Chapter)\s+/,
+ "\\1_#{title_no}").
+ downcase
+ tag=heading_tag_clean(tag)
+ dob.tags=set_tags(dob.tags,tag)
+ 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=set_tags(dob.tags,title_no)
+ 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=set_tags(dob.tags,title_no)
+ dob.obj=dob.obj.gsub(/^/i,"#{title_no}. ")
+ end
+ end
+ if dob.ln==no1 #watch because here you change dob.name
+ dob.tags=set_tags(dob.tags,"h#{title_no}")
+ 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=set_tags(dob.tags,"h#{title_no}")
+ 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=set_tags(dob.tags,"h#{title_no}")
+ dob=number_sub_heading(dob,no3,title_no)
+ end
+ elsif dob.ln.to_s =~/^[0-6]/ \
+ and dob.name =~ /^[\w-]+-/ # endnotes, watch2005# endnotes, watch2005
+ dob.tags=set_tags(dob.tags,dob.name)
+ 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 =~/^[0-9]/ \
+ and dob.obj =~ /^([\d\.]+)/ #risky (must be unique) consider output to 4~~\d instead of 4~\d
+ dob.name=$1
+ dob.tags=set_tags(dob.tags,dob.name)
+ end
+ if @md.toc_lev_limit
+ end
+ elsif defined? dob.name \
+ and dob.name
+ dob.tags=set_tags(dob.tags,dob.name)
+ end
+ dob.tags=dob.tags.uniq if defined? dob.tags
+ dob
+ end.flatten
+ end
+ def ocn(data) #and auto segment numbering increment
+ @tuned_file=SiSU_AO_DocumentStructureExtract::OCN.new(@md,data,@fnx,@process).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
+ 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 )
+ @tuned_file=data.each.map 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=~/^[0-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
+ dob
+ end.flatten
+ end
+ def leading_zeros_fixed_width_number(possible_seg_name)
+ if possible_seg_name.to_s =~/^([0-9]+?\.|[0-9]+)$/m #!~/[.,:-]+/
+ possible_seg_name=possible_seg_name.to_s.
+ gsub(/\.$/,'')
+ nl=possible_seg_name.to_s.length
+ zero='0'
+ zeros_fixed_width=number_of_segments?.to_s.length
+ zero_width=(zeros_fixed_width - nl)
+ zero_width == 0 \
+ ? possible_seg_name.to_s
+ : zero*zero_width +
+ possible_seg_name.to_s
+ end
+ end
+ def auto_numbering_exceptions(chosen_seg_names_,md,dob)
+ number_make=case dob.lv.to_i
+ when 1
+ @num_exc={
+ t1: @num_exc[:t1] += 1,
+ t2: 0,
+ t3: 0,
+ t4: 0
+ }
+ Mx[:segname_prefix_auto_num_other] + '_' \
+ + @num_exc[:t1].to_s
+ when 2
+ @num_exc={
+ t1: @num_exc[:t1],
+ t2: @num_exc[:t2] += 1,
+ t3: 0,
+ t4: 0
+ }
+ Mx[:segname_prefix_auto_num_other] + '_' \
+ + @num_exc[:t1].to_s + '_' \
+ + @num_exc[:t2].to_s
+ when 3
+ @num_exc={
+ t1: @num_exc[:t1],
+ t2: @num_exc[:t2],
+ t3: @num_exc[:t3] += 1,
+ t4: 0
+ }
+ Mx[:segname_prefix_auto_num_other] + '_' \
+ + @num_exc[:t1].to_s + '_' \
+ + @num_exc[:t2].to_s + '_' \
+ + @num_exc[:t3].to_s
+ when 4
+ @num_exc[:t4] += 1
+ @num_exc={
+ t1: @num_exc[:t1],
+ t2: @num_exc[:t2],
+ t3: @num_exc[:t3],
+ t4: @num_exc[:t4] += 1
+ }
+ Mx[:segname_prefix_auto_num_other] + '_' \
+ + @num_exc[:t1].to_s + '_' \
+ + @num_exc[:t2].to_s + '_' \
+ + @num_exc[:t3].to_s + '_' \
+ + @num_exc[:t4].to_s
+ end
+ end
+ def check_that_seg_names_are_unique(chosen_seg_names_,chosen_seg_name,type,md,dob)
+ begin
+ chosen_seg_names_ << chosen_seg_name
+ chosen_seg_names_=chosen_seg_names(chosen_seg_names_,chosen_seg_name,dob,md,type)
+ if chosen_seg_names_.compact.uniq.length \
+ == chosen_seg_names_.compact.length
+ #check that all auto given seg names are unique
+ chosen_seg_names_=chosen_seg_names(chosen_seg_names_,chosen_seg_name,dob,md,type)
+ chosen_seg_name
+ else
+ SiSU_Utils::CodeMarker.new(__LINE__,__FILE__,:green).
+ mark(
+ "duplicated auto segment name: #{type} #{chosen_seg_name}\n" \
+ + "#{chosen_seg_names_}\n" \
+ + " manually name level 1 segments '1~given_name'\n" \
+ + 'filename: ' + md.fns + "\n" \
+ + 'heading text: "' + dob.obj + '"' + "\n" \
+ + 'duplication: "' + chosen_seg_name + '" (level: ' + dob.lv + '; numbering type: ' + type.to_s + ')'
+ )
+ chosen_seg_name=auto_numbering_exceptions(chosen_seg_names_,md,dob)
+ check_that_seg_names_are_unique(chosen_seg_names_,chosen_seg_name,:exception,md,dob)
+ end
+ rescue
+ end
+ end
+ def auto_seg_name(possible_seg_name,heading_num_is,dob,type)
+ prefix=case type
+ when :auto then Mx[:segname_prefix_auto_num_provide]
+ when :extract then Mx[:segname_prefix_auto_num_extract]
+ else '_'*dob.lv.to_i #should not occur
+ end
+ if possible_seg_name =~/^[0-9]+?\.$/m #!~/[.,:-]+/
+ possible_seg_name=possible_seg_name.
+ gsub(/\.$/,'')
+ end
+ @chosen_seg_name=
+ if dob.lv=='4' \
+ and possible_seg_name.to_s =~/^[0-9]+(?:[.,:-][0-9]){3}/m
+ possible_seg_name=possible_seg_name.to_s.
+ gsub(/(?:[:,-]|\W)/,'.').
+ gsub(/\.$/,'')
+ prefix + possible_seg_name
+ elsif dob.lv=='3' \
+ and possible_seg_name.to_s =~/^[0-9]+(?:[.,:-][0-9]){2}/m
+ possible_seg_name=possible_seg_name.to_s.
+ gsub(/(?:[:,-]|\W)/,'.').
+ gsub(/\.$/,'')
+ prefix + possible_seg_name
+ elsif dob.lv=='2' \
+ and possible_seg_name.to_s =~/^[0-9]+(?:[.,:-][0-9]){1}/m
+ possible_seg_name=possible_seg_name.to_s.
+ gsub(/(?:[:,-]|\W)/,'.').
+ gsub(/\.$/,'')
+ prefix + possible_seg_name
+ elsif dob.lv=='1' \
+ and possible_seg_name.to_s =~/^[0-9]+[:,-]?$/m
+ if possible_seg_name.to_i <= heading_num_is.to_i
+ prefix + leading_zeros_fixed_width_number(possible_seg_name)
+ else
+ possible_seg_name=possible_seg_name.to_s.
+ gsub(/(?:[:,-]|\W)/,'.').
+ gsub(/\.$/,'')
+ prefix + possible_seg_name
+ end
+ else
+ @chosen_seg_name=auto_numbering_exceptions(@chosen_seg_names,md,dob)
+ end
+ check_that_seg_names_are_unique(@chosen_seg_names,@chosen_seg_name,type,@md,dob)
+ end
+ def set_name_and_tags(dob,possible_seg_name)
+ if @md.seg_names.is_a?(Array) \
+ and not @md.seg_names.include?(possible_seg_name)
+ dob.name=possible_seg_name
+ dob.tags=set_tags(dob.tags,dob.name)
+ @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
+ 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=0
+ @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=[]
+ @num_exc={ t1: 0, t2: 0, t3: 0, t4: 0 }
+ data.each do |dob|
+ if dob.is==:heading \
+ && dob.ln \
+ and dob.ln.to_s =~/^[4-7]/
+ heading_num_is=/^\d+:(\d+);\d/m.match(dob.node)[1]
+ 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.ln.to_s =~/^[5-7]/ \
+ and dob.obj =~/^\s*(?:\S+\s+)?([0-9]+(?:[.,:-][0-9])+)/m
+ #heading starts with a recognised numeric
+ #or word followed by a recognised numeric construct,
+ #use that as name
+ if dob.ln==7 \
+ and dob.obj =~/^\s*(?:\S+\s+)?([0-9]+(?:[.,:-][0-9]){3})/m
+ possible_seg_name=$1.
+ gsub(/(?:[:,-]|\W)/,'.').
+ gsub(/\.$/,'')
+ possible_seg_name=
+ auto_seg_name(possible_seg_name,heading_num_is,dob,:extract)
+ set_name_and_tags(dob,possible_seg_name)
+ elsif dob.ln==6 \
+ and dob.obj =~/^\s*(?:\S+\s+)?([0-9]+(?:[.,:-][0-9]){2})/m
+ possible_seg_name=$1.
+ gsub(/(?:[:,-]|\W)/,'.').
+ gsub(/\.$/,'')
+ possible_seg_name=
+ auto_seg_name(possible_seg_name,heading_num_is,dob,:extract)
+ set_name_and_tags(dob,possible_seg_name)
+ elsif dob.ln==5 \
+ and dob.obj =~/^\s*(?:\S+\s+)?([0-9]+(?:[.,:-][0-9]){1})/m
+ possible_seg_name=$1.
+ gsub(/(?:[:,-]|\W)/,'.').
+ gsub(/\.$/,'')
+ possible_seg_name=
+ auto_seg_name(possible_seg_name,heading_num_is,dob,:extract)
+ set_name_and_tags(dob,possible_seg_name)
+ end
+ end
+ if dob.ln==4
+ if dob.name !~/^\S+/ \
+ and dob.obj =~/^\s*(?:\S+\s+)?([0-9]+)/m
+ #heading starts with a recognised numeric
+ #or word followed by a recognised numeric construct,
+ #use that as name
+ possible_seg_name=$1
+ possible_seg_name=
+ auto_seg_name(possible_seg_name,heading_num_is,dob,:extract)
+ set_name_and_tags(dob,possible_seg_name)
+ end
+ if 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=set_tags(dob.tags,dob.name)
+ @md.seg_names << dob.name
+ end
+ else
+ #if no segment name,
+ #provide a numerical one
+ @art_filename_auto+=1
+ possible_seg_name=
+ auto_seg_name(@art_filename_auto,heading_num_is,dob,:auto)
+ if @md.seg_names.is_a?(Array) \
+ and not @md.seg_names.include?(possible_seg_name)
+ dob.name=possible_seg_name
+ dob.tags=set_tags(dob.tags,dob.name)
+ @md.seg_names << possible_seg_name
+ else puts 'segment name (numbering) error'
+ end
+ end
+ if not dob.name #should not occur
+ puts "e r r o r -\t#{__FILE__}::#{__LINE__}\n#{dob.inspect}"
+ end
+ 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 =~/[0-3]/
+ {
+ seg: nil,
+ level: dob.ln,
+ }
+ #elsif dob.ln =~/[4-6]/
+ else
+ {
+ 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 !~/^[0-3]/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/ao_persist.rb b/lib/sisu/ao_persist.rb
new file mode 100644
index 00000000..6111cc41
--- /dev/null
+++ b/lib/sisu/ao_persist.rb
@@ -0,0 +1,194 @@
+# encoding: utf-8
+=begin
+
+* Name: SiSU
+
+** Description: documents, structuring, processing, publishing, search
+*** document abstraction
+
+** Author: Ralph Amissah
+
+
+
+** Copyright: (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
+ 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 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:
+
+
+
+** Git
+
+
+
+=end
+module SiSU_AO_Persist
+ class Persist
+ @@persistance=nil
+ attr_accessor :fns, :ao_arr, :idx_arr_sst, :idx_arr_tex, :idx_arr_html, :idx_arr_xhtml, :map_arr_nametags, :map_arr_ocn_htmlseg
+ def initialize(args=nil)
+ @@persistance=args=(args ? args : (@@persistance || persist_init_hash_values))
+ @fns=args[:fns]
+ @ao_arr=args[:ao_arr]
+ @idx_arr_sst=args[:idx_arr_sst]
+ @idx_arr_tex=args[:idx_arr_tex]
+ @idx_arr_html=args[:idx_arr_html]
+ @idx_arr_xhtml=args[:idx_arr_xhtml]
+ @map_arr_nametags=args[:map_arr_nametags]
+ @map_arr_ocn_htmlseg=args[:map_arr_ocn_htmlseg]
+ end
+ def fns
+ @fns
+ end
+ def ao_arr
+ @ao_arr
+ end
+ def idx_arr_sst
+ @idx_arr_sst
+ end
+ def idx_arr_tex
+ @idx_arr_tex
+ end
+ def idx_arr_html
+ @idx_arr_html
+ end
+ def idx_arr_xhtml
+ @idx_arr_xhtml
+ end
+ def map_arr_nametags
+ @map_arr_nametags
+ end
+ def map_arr_ocn_htmlseg
+ @map_arr_ocn_htmlseg
+ end
+ def persist_init_hash_values
+ {
+ fns: nil,
+ ao_arr: [],
+ idx_arr_sst: [],
+ idx_arr_tex: [],
+ idx_arr_html: [],
+ idx_arr_xhtml: [],
+ map_arr_nametags: [],
+ map_arr_ocn_htmlseg: [],
+ }
+ end
+ def persist_init
+ @@persistance=nil
+ Persist.new(persist_init_hash_values)
+ end
+ end
+ class PersistDocStructExt
+ @@persist=nil
+ attr_accessor :ocn, :lng, :lng_is, :code, :lngsyn, :poem, :block, :box, :group, :alt, :quote, :table, :table_to
+ def initialize(args=nil)
+ @@persist=args=(args ? args : (@@persist || persist_init_hash_values))
+ @ocn=args[:ocn]
+ @lng=args[:lng]
+ @lng_is=args[:lng_is]
+ @code=args[:code]
+ @lngsyn=args[:lngsyn]
+ @poem=args[:poem]
+ @block=args[:block]
+ @box=args[:box]
+ @group=args[:group]
+ @alt=args[:alt]
+ @quote=args[:quote]
+ @table=args[:table]
+ @table_to=args[:table_to]
+ end
+ def ocn
+ @ocn
+ end
+ def lng
+ @lng
+ end
+ def lng_is
+ @lng_is
+ end
+ def code
+ @code
+ end
+ def lngsyn
+ @lngsyn
+ end
+ def poem
+ @poem
+ end
+ def block
+ @block
+ end
+ def box
+ @box
+ end
+ def group
+ @group
+ end
+ def alt
+ @alt
+ end
+ def quote
+ @quote
+ end
+ def table
+ @table
+ end
+ def table_to
+ @table_to
+ end
+ def persist_init_hash_values
+ {
+ ocn: :on,
+ lng: :off,
+ lng_is: :doc_default,
+ code: :off,
+ lngsyn: :txt,
+ poem: :off,
+ block: :off,
+ box: :off,
+ group: :off,
+ alt: :off,
+ quote: :off,
+ table: :off,
+ table_to: :off,
+ }
+ end
+ def persist_init
+ @@persist=nil
+ PersistDocStructExt.new(persist_init_hash_values)
+ end
+ end
+end
+__END__
diff --git a/lib/sisu/ao_references.rb b/lib/sisu/ao_references.rb
new file mode 100644
index 00000000..cd410f77
--- /dev/null
+++ b/lib/sisu/ao_references.rb
@@ -0,0 +1,502 @@
+# encoding: utf-8
+=begin
+
+* Name: SiSU
+
+** Description: documents, structuring, processing, publishing, search
+*** system environment, resource control and configuration details
+
+** Author: Ralph Amissah
+
+
+
+** Copyright: (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
+ 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 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:
+
+
+
+** Git
+
+
+
+=end
+module SiSU_AO_References
+ class Bibliography
+ def initialize(md,data)
+ @md,@data=md,data
+ end
+ def sort_bibliography_array_by_author_year_title(bib)
+ if bib
+ bib.compact.sort_by do |c|
+ [c[:author_arr][0],c[:year],c[:title]]
+ end
+ end
+ end
+ def citation_in_prepared_bibliography(cite)
+ @cite=cite
+ def article
+ {
+ is: :article,
+ author_raw: nil,
+ author: nil,
+ author_arr: nil,
+ title: nil,
+ language: nil,
+ journal: nil,
+ volume: nil,
+ editor: nil,
+ year: nil,
+ where: nil,
+ url: nil,
+ note: nil,
+ short_name: nil,
+ id: nil,
+ }
+ end
+ def book
+ {
+ is: :book,
+ author_raw: nil,
+ author: nil,
+ author_arr: nil,
+ #editor: nil,
+ title: nil,
+ subtitle: nil,
+ fulltitle: nil,
+ language: nil,
+ publisher: nil,
+ edition: nil,
+ year: nil,
+ where: nil,
+ url: nil,
+ note: nil,
+ short_name: nil,
+ id: nil,
+ }
+ end
+ def citation_metadata
+ type=if @cite =~/^jo: \S+/m
+ :article
+ elsif @cite =~/^au: \S+/m
+ :book
+ end
+ if type
+ citeblock=@cite.split("\n")
+ if type == :article
+ citation=article
+ citeblock.select do |meta|
+ case meta
+ when /^((?:au|author):\s+)\S+/ #req
+ citation[:author_raw]=/^#{$1}(.+)/.match(meta)[1]
+ when /^((?:ti|title):\s+)\S+/ #req
+ citation[:title]=/^#{$1}(.+)/.match(meta)[1]
+ when /^((?:lng|language):\s+)\S+/
+ citation[:language]=/^#{$1}(.+)/.match(meta)[1]
+ when /^((?:jo|journal):\s+)\S+/ #req?
+ citation[:journal]=/^#{$1}(.+)/.match(meta)[1]
+ when /^((?:vo|volume):\s+)\S+/
+ citation[:volume]=/^#{$1}(.+)/.match(meta)[1]
+ when /^((?:edr|editor):\s+)\S+/
+ citation[:editor]=/^#{$1}(.+)/.match(meta)[1]
+ when /^((?:yr|year):\s+)\S+/ #req?
+ citation[:year]=/^#{$1}(.+)/.match(meta)[1]
+ when /^((?:pst|publisher_state):\s+)\S+/
+ citation[:where]=/^#{$1}(.+)/.match(meta)[1]
+ when /^(url:\s+)\S+/
+ citation[:url]=/^#{$1}(.+)/.match(meta)[1]
+ when /^(note:\s+)\S+/
+ citation[:note]=/^#{$1}(.+)/.match(meta)[1]
+ when /^((?:sn|shortname):\s+)\S+/
+ citation[:short_name]=/^#{$1}(.+)/.match(meta)[1]
+ when /^(id:\s+)\S+/
+ citation[:id]=/^#{$1}(.+)/.match(meta)[1]
+ end
+ end
+ end
+ if type == :book
+ citation=book
+ citeblock.select do |meta|
+ case meta
+ when /^((?:au|author):\s+)\S+/ #req
+ citation[:author_raw]=/^#{$1}(.+)/.match(meta)[1]
+ when /^((?:ti|title):\s+)\S+/ #req
+ citation[:title]=/^#{$1}(.+)/.match(meta)[1]
+ when /^((?:st|subtitle):\s+)\S+/
+ citation[:subtitle]=/^#{$1}(.+)/.match(meta)[1]
+ when /^((?:lng|language):\s+)\S+/
+ citation[:language]=/^#{$1}(.+)/.match(meta)[1]
+ when /^((?:pb|publisher):\s+)\S+/
+ citation[:publisher]=/^#{$1}(.+)/.match(meta)[1]
+ when /^((?:edn|edition):\s+)\S+/
+ citation[:edition]=/^#{$1}(.+)/.match(meta)[1]
+ when /^((?:yr|year):\s+)\S+/ #req?
+ citation[:year]=/^#{$1}(.+)/.match(meta)[1]
+ when /^((?:pst|publisher_state):\s+)\S+/
+ citation[:where]=/^#{$1}(.+)/.match(meta)[1]
+ when /^(url:\s+)\S+/
+ citation[:url]=/^#{$1}(.+)/.match(meta)[1]
+ when /^(note:\s+)\S+/
+ citation[:note]=/^#{$1}(.+)/.match(meta)[1]
+ when /^((?:sn|shortname):\s+)\S+/
+ citation[:short_name]=/^#{$1}(.+)/.match(meta)[1]
+ when /^(id:\s+)\S+/
+ citation[:id]=/^#{$1}(.+)/.match(meta)[1]
+ end
+ end
+ end
+ if citation[:is]==:book
+ if citation[:subtitle]
+ citation[:fulltitle] = citation[:title] \
+ + ' - ' \
+ + citation[:subtitle]
+ else
+ citation[:fulltitle] = citation[:title]
+ end
+ end
+ citation[:author_arr]=citation[:author_raw].split(/;\s*/)
+ citation[:author]=citation[:author_arr].map do |author|
+ author.gsub(/(.+?),\s+(.+)/,'\2 \1').strip
+ end.join(', ').strip
+ unless citation[:short_name]
+ citation[:short_name]=%{#{c[:author]}, "#{c[:short_name]}" (#{c[:date]})}
+ end
+ end
+ citation
+ end
+ self
+ end
+ def biblio_extraction
+ bibliography=[]
+ biblioflag=false
+ code_flag=false
+ flag_code_curly=:not_code_curly
+ flag_code_tics=:not_code_tics
+ @data=@data.select do |t_o|
+ if t_o =~/^code\{/
+ flag_code_curly=:code_curly
+ elsif t_o =~/^\}code/
+ flag_code_curly=:not_code_curly
+ elsif t_o =~/^``` code/
+ flag_code_tics=:code_tics
+ elsif flag_code_tics ==:code_tics \
+ and t_o =~/^```/
+ flag_code_tics=:not_code_tics
+ end
+ code_flag=if flag_code_curly==:code_curly \
+ or flag_code_tics==:code_tics
+ true
+ else false
+ end
+ unless code_flag
+ if @md.flag_auto_biblio
+ if t_o =~/^1~biblio(?:graphy)?/
+ biblioflag = true
+ t_o
+ elsif t_o =~/^:?[B-D1]~/
+ biblioflag = false
+ t_o
+ elsif biblioflag
+ if t_o !~/\A%+ /
+ bibliography << citation_in_prepared_bibliography(t_o).citation_metadata
+ next
+ else
+ t_o
+ end
+ else t_o
+ end
+ elsif @md.flag_biblio
+ if t_o =~/^1~biblio(?:graphy)?/
+ biblioflag = true
+ next
+ elsif t_o =~/^:?[B-D]~/
+ next
+ elsif t_o =~/^:?[B-D1]~/
+ biblioflag = false
+ t_o
+ elsif biblioflag
+ if t_o !~/\A%+ /
+ bibliography << t_o
+ next
+ else
+ t_o
+ end
+ else t_o
+ end
+ else t_o
+ end
+ else t_o
+ end
+ end.compact
+ if @md.flag_auto_biblio \
+ and bibliography.length > 0
+ data_new=[]
+ bibliography=sort_bibliography_array_by_author_year_title(bibliography)
+ @data.select do |t_o|
+ if t_o =~/^1~biblio(?:graphy)?/
+ bibliography.each do |c|
+ if c[:is]==:book
+ <<-WOK
+
+!_ #{c[:author]}
+/{"#{c[:fulltitle]}"}/ #{c[:publisher]} (#{c[:year]})
+ WOK
+ elsif c[:is]==:article
+ <<-WOK
+
+!_ #{c[:author]}
+/{"#{c[:title]}"}/ #{c[:journal]} (#{c[:year]})
+ WOK
+ end
+ end
+ else data_new << t_o
+ end
+ end
+ @data=data_new
+ end
+ [@data,bibliography]
+ end
+ end
+ class Citations
+ def initialize(md='',data='')
+ @md,@data=md,data
+ #@biblio=[]
+ end
+ def songsheet
+ tuned_file,citations=citations_scan(@data)
+ [tuned_file,citations]
+ end
+ def sort_bibliography_array_by_author_year(bib)
+ bib.sort_by do |c|
+ [c[:author_raw],c[:year]]
+ #[c[:author_arr][0],c[:year],c[:title]]
+ end
+ end
+ def citations_regex
+ def pages_pattern
+ %r{(?:[,.:]?\s+(?:p{1,2}\.?\s+)?(?:\d+--?\d+)[,.]?\s+)?}
+ end
+ def editor_pattern
+ %r{(?(?:editor|edited by)\s+.+?)}
+ end
+ def year_pattern
+ %r{[(\[]?(?\d{4})[\])]?[.,]?}
+ end
+ def authors_year_title_publication_editor_pages
+ /(?.+?)\s+#{year_pattern}\s+"(?.+?)"\s+(?:#{Mx[:fa_italics_o]}|#{Mx[:srcrgx_italics_o]})(?.+?)(?:#{Mx[:fa_italics_c]}|#{Mx[:srcrgx_italics_c]})\s+#{editor_pattern}#{pages_pattern}/m # note ed. is usually edition rather than editor
+ end
+ def authors_title_publication_year_editor_pages
+ /(?.+?)\s+"(?.+?)"\s+(?:#{Mx[:fa_italics_o]}|#{Mx[:srcrgx_italics_o]})(?.+?)(?:#{Mx[:fa_italics_c]}|#{Mx[:srcrgx_italics_c]})\s+#{year_pattern}\s+#{editor_pattern}#{pages_pattern}/m # note ed. is usually edition rather than editor
+ end
+ def authors_title_publication_editor_year_pages ###
+ /(?.+?)\s+"(?.+?)"\s+(?:#{Mx[:fa_italics_o]}|#{Mx[:srcrgx_italics_o]})(?.+?)(?:#{Mx[:fa_italics_c]}|#{Mx[:srcrgx_italics_c]})\s+ed.\s+#{editor_pattern}#{year_pattern}#{pages_pattern}/m
+ # note ed. is usually edition rather than editor
+ end
+ def authors_title_publication_editor_pages_year ###
+ /(?.+?)\s+"(?.+?)"\s+(?:#{Mx[:fa_italics_o]}|#{Mx[:srcrgx_italics_o]})(?.+?)(?:#{Mx[:fa_italics_c]}|#{Mx[:srcrgx_italics_c]})\s+#{editor_pattern}#{pages_pattern}#{year_pattern}/m # note ed. is usually edition rather than editor
+ end
+ def authors_year_title_publication_pages
+ /(?.+?)\s+#{year_pattern}\s+"(?.+?)"\s+(?:#{Mx[:fa_italics_o]}|#{Mx[:srcrgx_italics_o]})(?.+?)(?:#{Mx[:fa_italics_c]}|#{Mx[:srcrgx_italics_c]})[,.;]?#{pages_pattern}/m
+ end
+ def authors_title_publication_year_pages
+ /(?.+?)\s+"(?.+?)"\s+(?:#{Mx[:fa_italics_o]}|#{Mx[:srcrgx_italics_o]})(?.+?)(?:#{Mx[:fa_italics_c]}|#{Mx[:srcrgx_italics_c]})\s+#{year_pattern}\s+#{pages_pattern}/m
+ end
+ def authors_title_publication_pages_year ###
+ /(?.+?)\s+"(?.+?)"\s+(?:#{Mx[:fa_italics_o]}|#{Mx[:srcrgx_italics_o]})(?.+?)(?:#{Mx[:fa_italics_c]}|#{Mx[:srcrgx_italics_c]})#{pages_pattern}#{year_pattern}/m
+ end
+ def authors_year_publication_pages
+ /(?.+?)\s+#{year_pattern}\s+(?:#{Mx[:fa_italics_o]}|#{Mx[:srcrgx_italics_o]})(?.+?)(?:#{Mx[:fa_italics_c]}|#{Mx[:srcrgx_italics_c]})#{pages_pattern}/m
+ end
+ def authors_publication_year_pages
+ /(?.+?)\s+(?:#{Mx[:fa_italics_o]}|#{Mx[:srcrgx_italics_o]})(?.+?)(?:#{Mx[:fa_italics_c]}|#{Mx[:srcrgx_italics_c]})[,.;]?\s+(?.+?)?#{year_pattern}#{pages_pattern}[.;]?/m
+ end
+ self
+ end
+ def authors?(citations)
+ citations.each.map do |b|
+ if b =~ /^.+\s+::.+?:$/
+ c=/^(?.+?)\s+::(?.+?):$/.match(b)
+ {
+ citation: c[:citation],
+ shortref: c[:shortref],
+ c[:shortref].to_s => c[:citation]
+ }
+ else { citation: b }
+ end
+ end
+ end
+ def long_and_short_ref?(citations) #could be useful, keep ... ectract shortref
+ citations.each.map do |b|
+ if b =~ /^.+\s+::.+?:$/
+ c=/^(?.+?)\s+::(?.+?):$/.match(b)
+ {
+ citation: c[:citation],
+ shortref: c[:shortref],
+ c[:shortref].to_s => c[:citation]
+ }
+ else { citation: b }
+ end
+ end
+ end
+ def citation_detail(citations) #could be useful, keep ... extract shortref
+ bibahash=[]
+ number=0
+ missed=0
+ citations.select do |b|
+ z=if b =~citations_regex.authors_year_title_publication_editor_pages
+ c=citations_regex.authors_year_title_publication_editor_pages.match(b)
+ {
+ is: :article,
+ author_raw: c[:authors],
+ year: c[:year],
+ title: c[:title],
+ publication: c[:publication],
+ editor: c[:editor],
+ }
+ elsif b =~citations_regex.authors_title_publication_year_editor_pages
+ c=citations_regex.authors_title_publication_year_editor_pages.match(b)
+ {
+ is: :article,
+ author_raw: c[:authors],
+ year: c[:year],
+ title: c[:title],
+ publication: c[:publication],
+ editor: c[:editor],
+ }
+ elsif b =~citations_regex.authors_title_publication_editor_year_pages
+ c=citations_regex.authors_title_publication_editor_year_pages.match(b)
+ {
+ is: :article,
+ author_raw: c[:authors],
+ year: c[:year],
+ title: c[:title],
+ publication: c[:publication],
+ editor: c[:editor],
+ }
+ elsif b =~citations_regex.authors_title_publication_editor_pages_year
+ c=citations_regex.authors_title_publication_editor_pages_year.match(b)
+ {
+ is: :article,
+ author_raw: c[:authors],
+ year: c[:year],
+ title: c[:title],
+ publication: c[:publication],
+ editor: c[:editor],
+ }
+ elsif b =~citations_regex.authors_year_title_publication_pages
+ c=citations_regex.authors_year_title_publication_pages.match(b)
+ {
+ is: :article,
+ author_raw: c[:authors],
+ year: c[:year],
+ title: c[:title],
+ publication: c[:publication],
+ }
+ elsif b =~citations_regex.authors_title_publication_year_pages
+ c=citations_regex.authors_title_publication_year_pages.match(b)
+ {
+ is: :article,
+ author_raw: c[:authors],
+ year: c[:year],
+ title: c[:title],
+ publication: c[:publication],
+ }
+ elsif b =~citations_regex.authors_year_publication_pages
+ c=citations_regex.authors_year_publication_pages.match(b)
+ {
+ is: :book,
+ author_raw: c[:authors],
+ year: c[:year],
+ publication: c[:publication],
+ }
+ elsif b =~citations_regex.authors_publication_year_pages
+ c=citations_regex.authors_publication_year_pages.match(b)
+ {
+ is: :book,
+ author_raw: c[:authors],
+ year: c[:year],
+ publication: c[:publication],
+ }
+ else b
+ end
+ if not z.is_a?(NilClass) \
+ and z.is_a?(Hash) \
+ and z[:author_raw].length > 0
+ z[:author_arr]=z[:author_raw].split(/;\s*/)
+ z[:author]=z[:author_arr].map do |author|
+ author.gsub(/(.+?),\s+(.+)/,'\2 \1').strip
+ end.join(', ').strip
+ if @md.opt.act[:verbose_plus][:set]==:on \
+ || @md.opt.act[:maintenance][:set]==:on
+ number +=1 if z.is_a?(Hash)
+ missed +=1 if z.is_a?(String)
+ (z.is_a?(Hash)) \
+ ? (p '[' + number.to_s + '] ' + z.to_s)
+ : (p '<' + missed.to_s + '> ' + z.to_s)
+ end
+ end
+ bibahash << z if z.is_a?(Hash)
+ end
+ bibahash=sort_bibliography_array_by_author_year(bibahash.compact)
+ bibahash
+ end
+ def citations_scan(data)
+ citations=[]
+ #short_ref=[]
+ tuned_file = data.compact.select do |dob|
+ if dob.is !=:meta \
+ && dob.is !=:comment \
+ && dob.is !=:code \
+ && dob.is !=:table
+ if dob.obj =~/\.:.+?:\./
+ citations << dob.obj.scan(/\.:\s*(.+?)\s*:\./m)
+ #short_ref << dob.obj.scan(/\.:\s+(.+?)\s+::([^:]+)::\./m) #look at later
+ ##short_ref << dob.obj.scan(/\.:\s+(.+?)\s+::(.+?)::\./m) #look at later
+ #short_ref << dob.obj.scan(/\.:\s*(.+?)\s*(::(.+?):)?:\./m) #look at later
+ citations=citations.flatten.compact
+ dob.obj=dob.obj. #remove citations delimiter & helpers from text
+ gsub(/\.:|:\./,'')
+ end
+ end
+ dob if dob.is_a?(Object)
+ end
+ #bib=long_and_short_ref?(citations) #could be useful, keep ... extract shortref
+ citations=citation_detail(citations)
+ [tuned_file,citations]
+ end
+ end
+end
+__END__
diff --git a/lib/sisu/ao_syntax.rb b/lib/sisu/ao_syntax.rb
new file mode 100644
index 00000000..010e9285
--- /dev/null
+++ b/lib/sisu/ao_syntax.rb
@@ -0,0 +1,640 @@
+# encoding: utf-8
+=begin
+
+* Name: SiSU
+
+** Description: documents, structuring, processing, publishing, search
+*** Syntax for markup, input markup syntaxes, determined here
+
+** Author: Ralph Amissah
+
+
+
+** Copyright: (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
+ 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 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:
+
+
+
+** Git
+
+
+
+=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='',biblio=[])
+ @md,@data,@bibliography=md,data,biblio
+ @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(?:\.[a-z][0-9a-z_]+)?|box(?:\.[a-z_]+)?|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\b|[.,;:?!'")]|~\^|~\\\{\s|$)}
+ tail_m_bold=%{(?:(?:#{Mx[:fa_italics_c]})?(?:\s|'s\b|[.,;:?!'")]|~\^|~\\\{\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
+ 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]
+ /#{@http_m}|#{bold_line}|(?:#{@manmkp_bold}|#{@md.bold_match_list[: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])
+ dob.obj=if dob.is !=:meta \
+ && dob.is !=:heading \
+ && dob.is !=:heading_insert \
+ && dob.is !=:code \
+ && dob.is !=:layout \
+ && 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]}")
+ 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 @md.flag_auto_biblio \
+ and @bibliography.length > 0
+ dob=if dob.is !=:meta \
+ && dob.is !=:heading_insert \
+ && dob.is !=:code \
+ && dob.is !=:comment \
+ && dob.is !=:table
+ @bibliography.each do |c|
+ if c[:id] and not c[:id].nil? and not c[:id].empty?
+ dob.obj=dob.obj.gsub(/#{c[:id]}/mi,c[:short_name])
+ end
+ end
+ dob
+ else dob
+ end
+ dob
+ else dob
+ end
+ 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])
+ 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]}")
+ 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 ==0
+ 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]}#lt#{Mx[:gl_c]}#{Mx[:gl_o]}#lt#{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]}#lt#{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') #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/cgi.rb b/lib/sisu/cgi.rb
new file mode 100644
index 00000000..6d8d8e04
--- /dev/null
+++ b/lib/sisu/cgi.rb
@@ -0,0 +1,84 @@
+# encoding: utf-8
+=begin
+
+* Name: SiSU
+
+** Description: documents, structuring, processing, publishing, search
+*** generates naive cgi search form for search of sisu database (pgsql sqlite)
+
+** Author: Ralph Amissah
+
+
+
+** Copyright: (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
+ 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 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:
+
+
+
+** Git
+
+
+
+=end
+module SiSU_CGI #% database building documents
+ require_relative 'se' # se.rb
+ require_relative 'cgi_pgsql' # cgi_pgsql.rb
+ require_relative 'cgi_sqlite' # cgi_sqlite.rb
+ class SearchSQL
+ def initialize(opt)
+ @opt=opt
+ @webserv=@opt.files[0].to_s.strip
+ end
+ def read
+ if @opt.act[:sample_search_form][:db]==:pg # cgi_pgsql.rb
+ SiSU_CGI_PgSQL::SearchPgSQL.new(@opt,@webserv).pgsql
+ elsif @opt.act[:sample_search_form][:db]==:sqlite # cgi_sqlite.rb
+ SiSU_CGI_SQLite::SearchSQLite.new(@opt,@webserv).sqlite
+ else
+ puts <<-WOK
+ please select database type for which sample search form should be built (pgsql or sqlite)
+ sisu --sample-search-form --db=sqlite
+ sisu --sample-search-form --db=pg
+ other options include
+ --webserv-cgi='[cgi-server-name]'
+ --webserv-output='[sisu-output-server-with-base-path]'
+ WOK
+ end
+ end
+ end
+end
+__END__
diff --git a/lib/sisu/cgi_pgsql.rb b/lib/sisu/cgi_pgsql.rb
new file mode 100644
index 00000000..0011d182
--- /dev/null
+++ b/lib/sisu/cgi_pgsql.rb
@@ -0,0 +1,270 @@
+# encoding: utf-8
+=begin
+
+* Name: SiSU
+
+** Description: documents, structuring, processing, publishing, search
+*** generates naive cgi search form for search of sisu database (pgsql)
+
+** Author: Ralph Amissah
+
+
+
+** Copyright: (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
+ 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 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:
+
+
+
+** Git
+
+
+
+=end
+module SiSU_CGI_PgSQL #% database building documents
+ require_relative 'se' # se.rb
+ require_relative 'cgi_sql_common' # cgi_sql_common.rb
+ include SiSU_CGI_SQL
+ class SearchPgSQL < CGI_Common
+ def initialize(opt,webserv)
+ @opt,@webserv=opt,webserv
+ @cX=SiSU_Screen::Ansi.new(opt.act[:color_state][:set]).cX
+ @env=SiSU_Env::InfoEnv.new('',opt)
+ @sys=SiSU_Env::SystemCall.new
+ @db=SiSU_Env::InfoDb.new
+ get_init=SiSU_Env::GetInit.new
+ @rc=get_init.sisu_yaml.rc
+ @name_of={}
+ @name_of[:output_dir_structure]=if opt.dir_structure_by.to_s =~/(?:language|filetype|filename)/
+ opt.dir_structure_by.to_s
+ else 'language'
+ end
+ @name_of[:lingual]=if opt.lingual.to_s =~/(?:mono|multi)/
+ opt.lingual.to_s
+ else 'multi'
+ end
+ @name_of[:db]=if defined? @rc['search'] \
+ and defined? @rc['search']['sisu'] \
+ and defined? @rc['search']['sisu']['action'] \
+ and @rc['search']['sisu']['action'] =~/https?:\/\/\S+?\.cgi/ \
+ and defined? @rc['search']['sisu']['db'] \
+ and @rc['search']['sisu']['db'] =~/\S+/
+ @rc['search']['sisu']['db']
+ else
+ @env.path.base_markup_dir_stub #'sisu' #breaks if not present
+ end
+ @name_of[:host_url_cgi]=%q{http://#{ENV['HTTP_HOST']}#{ENV['PATH_INFO']}}
+ @name_of[:host_url_docs]=%q{http://#{ENV['HTTP_HOST']}}
+ @name_of[:cgi_script]=%q{#{ENV['SCRIPT_NAME']}}
+ @name_of[:user]=@db.psql.user(opt)
+ @image_src=%q{http://#{ENV['HTTP_HOST']}/_sisu/image_sys}
+ @common=SiSU_CGI_SQL::CGI_Common.new(@webserv,opt,@image_src,@env)
+ @cgi_file_name=@env.url.cgi_sample_search_form_name(opt)
+ end
+ def pgsql
+ serve=[]
+ if @sys.psql
+ available_db_table=`psql --list` # system call requires psql
+ available_db=available_db_table.scan(/(#{Db[:name_prefix]}\S+)/) if not available_db_table.nil?
+ if available_db \
+ and available_db.is_a?(Array)
+ available_db.flatten.each do |x|
+ serve << x.gsub(/#{Db[:name_prefix]}(\S+)/,'\1')
+ end
+ else STDERR.puts "WARNING: no postgresql database available, (have you created one?)"
+ end
+ serve=serve.sort
+ f1,f2='',''
+ serve.each do |x|
+ f1 << %{ \n} unless x =~/apache|sisu\/image/ #check
+ end
+ end
+ f2 << %q{ selected_db=%{}} + "\n"
+ if FileTest.writable?('.')
+ output=File.open(@cgi_file_name,'w')
+ output << header0 << header1 << header_desc << header2 << f1 << buttons1 << buttons1_pgsql << buttons2 << search_request << search_statement << search_statement_common << search_query1 << @common.pages << search_query2 << @common.tail << @common.main1 << f2 << dbi_connect << @common.main2 << @common.dir_structure << @common.main3
+ puts <<-WOK
+ generated sample search form: #{@cX.green}#{@cgi_file_name}#{@cX.off}
+ default database name: #{@cX.green}#{Db[:name_prefix]}#{@name_of[:db]}#{@cX.off} (#{@name_of[:db]})
+ db user: #{@cX.green}#{@name_of[:user]}#{@cX.off}
+ to modify use: #{@cX.brown}sisu --db-pg --db-user='#{@name_of[:user]}'#{@cX.off}
+
+ #{@cX.fuchsia}BASED ON ALREADY EXISTING databases#{@cX.off} (default database name: #{@db.psql.db})
+ NOTE it is first necessary to createdb,
+ use sisu to create the tables & populate the postgresql db
+
+ the database to be used for this directory (#{@db.psql.db})
+ will have to be created manually if it does not exist:
+ using postgresql tools directly (the following may work):
+ (i) if you are not yet a postgresql user,
+ #{@cX.brown}sudo su postgres
+ createuser -d -a #{@env.user}
+ exit#{@cX.off}
+ (ii) create the database:
+ #{@cX.brown}createdb #{@db.psql.db}#{@cX.off}
+ [for a list of existing databases try 'psql --list']"
+
+ you can use sisu to create the database tables and populate the database with documents
+
+ sisu --pg --dropall # removes existing postgresql db & tables
+ sisu --pg --createall -v # creates postgresql db & tables
+ sisu --pg --update -v *.sst *.ssm # populate the db
+ sisu --sample-search-form --db-pg # creates the postgresql search form
+ # this should be done after creating the db
+ # to be searched
+ sisu --webrick & # starts ruby webrick web server
+
+ # if necessary make the directory '/usr/lib/cgi-bin'
+ # here we copy the postgresql search form to cgi-bin
+ # (copy #{@cgi_file_name} to your cgi directory)
+ # set file permissions to 755
+ WOK
+ a=case @webserv
+ when /pwd/ then ''
+ else <<-WOK
+
+ sudo cp -vi #{Dir.pwd}/#{@cgi_file_name} /usr/lib/cgi-bin/.; \\
+ sudo chmod -v 755 /usr/lib/cgi-bin/#{@cgi_file_name}
+ WOK
+ end
+ SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],a).warn
+ a=<<-WOK
+ #{@env.webserv_base_cgi(@opt)}/cgi-bin/#{@cgi_file_name}
+ WOK
+ SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],a).print_blue
+ a="\n\t(to create and populate postgresql database see 'man sisu' and in particular the --pg option)\n\t[the database to be used for this directory (#{@db.psql.db}) will have to be created manually if it does not exist,\n\tusing postgresql tools directly: 'createdb #{@db.psql.db}' for a list of existing databases try 'psql --list']"
+ SiSU_Screen::Ansi.new(@opt.act[:color_state][:set],a).txt_grey
+ else puts 'failed in attempt to write #{@cgi_file_name} to present directory, is directory writable?'
+ end
+ end
+ def header0
+ <<-WOK_SQL
+#!/usr/bin/env ruby
+=begin
+#{about}
+ * Description: generates naive cgi search form for search of sisu database (pgsql)
+#{gpl}
+=end
+ begin
+ require 'cgi'
+ require 'fcgi'
+ require 'pg'
+ rescue LoadError
+ puts 'cgi, fcgi or pg NOT FOUND (LoadError)'
+ end
+ @stub_default='#{@name_of[:db]}'
+ @image_src="#{@image_src}"
+ @hosturl_cgi="#{@name_of[:host_url_cgi]}"
+ @hosturl_files="#{@name_of[:host_url_docs]}"
+ @output_dir_structure_by='#{@name_of[:output_dir_structure]}'
+ @lingual='#{@name_of[:lingual]}'
+ @port='#{@db.psql.port}'
+ @db_name_prefix='#{Db[:name_prefix]}'
+ @user='#{@name_of[:user]}' # check user name for access to pg database: e.g. www-data or '#{@env.user}'
+ @base="#{@name_of[:host_url_cgi]}#{@name_of[:cgi_script]}"
+ WOK_SQL
+ end
+ def search_statement
+ <<-'WOK_SQL'
+ class DBI_SearchString
+ def initialize(l,t,q,cse=false)
+ @l,@t,@q,@c=l,t,q,cse
+ end
+ def string
+ search={ search: [], flag: false }
+ if @t =~/\S+/ or @q =~/\S+/
+ if @t =~/\S+/ then unescaped_search=CGI.unescape(@t)
+ elsif @q =~/\S+/ then unescaped_search=CGI.unescape(@q)
+ end
+ search_construct=[]
+ unescaped_search=if @c
+ unescaped_search.gsub(/\s*(AND|OR)\s*/,"' \) \\1 #{@l}~\( '").
+ gsub(/(.+)/,"#{@l}~\( '\\1' \)")
+ else
+ unescaped_search.gsub(/\s*(AND|OR)\s*/,"' \) \\1 #{@l}~*\( '").
+ gsub(/(.+)/,"#{@l}~*\( '\\1' \)")
+ end
+ search_construct << unescaped_search
+ search_construct=search_construct.join(' ')
+ search[:search] << search_construct
+ search[:flag]=true
+ search
+ end
+ search
+ end
+ end
+ WOK_SQL
+ end
+ def search_query1
+ <<-'WOK_SQL'
+ @search_text=''
+ @search_text=search[:text].flatten.join(' AND ')
+ @search_text=@search_text.gsub(/(doc_objects\.clean~[*]?\(\s*'[^']+'\s*\)\s+(?:(?:AND|OR)\s+doc_objects\.clean~[*]?\(\s*'[^']+'\s*\))+)/,'(\1)')
+ end
+ WOK_SQL
+ end
+ def search_query2
+ <<-'WOK_SQL'
+ def sql_select_body
+ limit ||=@@limit
+ offset ||=@@offset
+ @sql_statement[:body]=%{SELECT metadata_and_text.title, metadata_and_text.creator_author, metadata_and_text.src_filename, metadata_and_text.language_document_char, metadata_and_text.notes_suffix, doc_objects.body, doc_objects.seg, doc_objects.ocn, metadata_and_text.tid FROM doc_objects, metadata_and_text WHERE (#{@search_text}) AND doc_objects.metadata_tid = metadata_and_text.tid ORDER BY metadata_and_text.language_document_char, metadata_and_text.title, metadata_and_text.src_filename, doc_objects.ocn}
+ @sql_statement[:range]=%{LIMIT #{limit} OFFSET #{offset} ;}
+ select=@sql_statement[:body] + ' ' + @sql_statement[:range]
+ select
+ end
+ def sql_select_body_format
+ %{#{sql_select_body}}
+ end
+ def contents
+ @conn.exec(sql_select_body)
+ end
+ end
+ WOK_SQL
+ end
+ def buttons1_pgsql
+ <<-'WOK_SQL'
+ case sensitive
+ WOK_SQL
+ end
+ def dbi_connect
+ <<-'WOK_SQL'
+ @conn=PG::Connection.open(dbname: @db, port: @port, user: @user)
+ WOK_SQL
+ end
+ end
+end
+__END__
diff --git a/lib/sisu/cgi_sql_common.rb b/lib/sisu/cgi_sql_common.rb
new file mode 100644
index 00000000..2d599bf4
--- /dev/null
+++ b/lib/sisu/cgi_sql_common.rb
@@ -0,0 +1,986 @@
+# encoding: utf-8
+=begin
+
+* Name: SiSU
+
+** Description: documents, structuring, processing, publishing, search
+*** generates naive cgi search form for search of sisu database (pgsql sqlite)
+
+** Author: Ralph Amissah
+
+
+
+** Copyright: (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
+ 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 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:
+
+
+
+** Git
+
+
+
+=end
+module SiSU_CGI_SQL
+ class CGI_Common
+ def initialize(webserv,opt,image_src,dir)
+ @webserv,@opt,@image_src,@env=webserv,opt,image_src,dir
+ end
+ def about
+ <<-'WOK_SQL'
+ * Name: SiSU information Structuring Universe
+ * Author: Ralph Amissah
+ * http://www.jus.uio.no/sisu
+ * http://www.jus.uio.no/sisu/SiSU/download
+ WOK_SQL
+ end
+ def gpl
+ <<-'WOK_SQL'
+ * Name: SiSU generated sample cgi search form
+
+ * Description: generated sample cgi search form for SiSU
+ (SiSU is a framework for document structuring, publishing and search)
+
+ * Author: Ralph Amissah
+
+ * Copyright: (C) 1997 - 2014, 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:
+
+
+
+ * Ralph Amissah
+
+
+ WOK_SQL
+ end
+ def header1
+ <<-'WOK_SQL'
+#Common TOP
+ @@offset=0
+ @@canned_search_url=@base
+ @color_heading='#DDFFAA'
+ @color_match='#ffff48'
+ class Form
+ def initialize(base,search_field,selected_db,result_type,checked_sql_limit,checked_tip,checked_stats,checked_searched,checked_url,checked_case,checked_echo,checked_sql,checked_all,checked_none,checked_selected,checked_default,search_note,the_can='')
+ search_note='' if checked_searched !~/\S/
+ the_can='' if checked_url !~/\S/
+ search_field='' if checked_echo !~/\S/
+ @base,@search_field,@selected_db,@result_type,@checked_sql_limit,@checked_tip,@checked_stats,@checked_searched,@checked_url,@checked_case,@checked_echo,@checked_sql,@checked_all,@checked_none,@checked_selected,@checked_default,@search_note,@the_can=base,search_field,selected_db,result_type,checked_sql_limit,checked_tip,checked_stats,checked_searched,checked_url,checked_case,checked_echo,checked_sql,checked_all,checked_none,checked_selected,checked_default,search_note,the_can
+ @tip=if checked_tip =~/\S/
+ 'text:__; fulltxt:__; keywords:__; title:__; author:__; topic_register:__; subject:__; description:__; publisher:__; editor:__; contributor:__; date:__; type:__; format:__; identifier:__; source:__; language:__; relation:__; coverage:__; rights:__; comment:__; abstract:__; filename:__; '
+ else ''
+ end
+ end
+ def submission_form
+ search_form=<<-WOK
+ WOK_SQL
+ end
+ def header_desc
+ <<-WOK_SQL
+
+
+
+
+
+
+ SiSU search form (sample): SiSU information Structuring Universe
+
+
+
+
+
+
+