aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/sisu/v2/dal_syntax.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sisu/v2/dal_syntax.rb')
-rw-r--r--lib/sisu/v2/dal_syntax.rb488
1 files changed, 488 insertions, 0 deletions
diff --git a/lib/sisu/v2/dal_syntax.rb b/lib/sisu/v2/dal_syntax.rb
new file mode 100644
index 00000000..4a13b069
--- /dev/null
+++ b/lib/sisu/v2/dal_syntax.rb
@@ -0,0 +1,488 @@
+# coding: utf-8
+=begin
+
+ * Name: SiSU
+
+ * Description: a framework for document structuring, publishing and search
+
+ * Author: Ralph Amissah
+
+ * Copyright: (C) 1997 - 2010, Ralph Amissah, All Rights Reserved.
+
+ * License: GPL 3 or later:
+
+ SiSU, a framework for document structuring, publishing and search
+
+ Copyright (C) Ralph Amissah
+
+ This program is free software: you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by the Free
+ Software Foundation, either version 3 of the License, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ more details.
+
+ You should have received a copy of the GNU General Public License along with
+ this program. If not, see <http://www.gnu.org/licenses/>.
+
+ If you have Internet connection, the latest version of the GPL should be
+ available at these locations:
+ <http://www.fsf.org/licensing/licenses/gpl.html>
+ <http://www.gnu.org/licenses/gpl.html>
+
+ <http://www.jus.uio.no/sisu/gpl.fsf/toc.html>
+ <http://www.jus.uio.no/sisu/gpl.fsf/doc.html>
+ <http://www.jus.uio.no/sisu/gpl.fsf/plain.txt>
+
+ * SiSU uses:
+ * Standard SiSU markup syntax,
+ * Standard SiSU meta-markup syntax, and the
+ * Standard SiSU object citation numbering and system
+
+ * Hompages:
+ <http://www.jus.uio.no/sisu>
+ <http://www.sisudoc.org>
+
+ * Download:
+ <http://www.jus.uio.no/sisu/SiSU/download.html>
+
+ * Ralph Amissah
+ <ralph@amissah.com>
+ <ralph.amissah@gmail.com>
+
+ ** Description: Syntax for markup, input markup syntaxes, determined here
+
+=end
+module SiSU_Syntax
+ class Words
+ def initialize(line,md,mkp)
+ @line,@md,@mkp=line,md,mkp
+ end
+ end
+ class Markup
+ def initialize(md='',data='')
+ @data,@md=data,md
+ @vz=SiSU_Env::Get_init.instance.skin
+ @data_new=[]
+ url_and_stub=SiSU_Env::Info_env.new.url
+ @output_url="#{url_and_stub.remote}"
+ @http_m=%r{\{.+?\}https?://\S+|https?:\S+|\.\.\/\S+|\S+?\.png\b|[*]~\S+|^#{Mx[:meta_o]}.+|#{Mx[:gr_o]}(?:code|group|alt|verse)(?:-end)?#{Mx[:gr_c]}|#{Mx[:fa_o]}:br#{Mx[:fa_c]}}
+ @manmkp_ital='[i/]\\{.+?\\}[i/]'
+ tail_m_ital=%q{(?:\s|[.,;:?!'")]|~\^|~\\\{\s|$)}
+ tail_m_bold=%{(?:(?:#{Mx[:fa_italics_c]})?(?:\s|[.,;:?!'")]|~\^|~\\\{\s|$))?}
+ bold_line=%{^!_\s.+?(?:#{Mx[:br_line]}|\n|$)}
+ ital_line=%{^/_\s.+?(?:#{Mx[:br_line]}|\n|$)}
+ @line_scan_ital=if defined? @md.make.italics[:str] \
+ and defined? @vz.markup_make_italic[:str]
+ /#{@http_m}|#{bold_line}|#{@manmkp_ital}#{tail_m_ital}|(?:#{@md.make.italics[:str]}|#{@vz.markup_make_italic[:str]})#{tail_m_ital}|\S+|\n/
+ elsif defined? @md.make.italics[:str]
+ /#{@http_m}|#{bold_line}|#{@manmkp_ital}#{tail_m_ital}|#{@md.make.italics[:str]}#{tail_m_ital}|\S+|\n/
+ elsif defined? @vz.markup_make_italic[:str]
+ /#{@http_m}|#{bold_line}|#{@manmkp_ital}#{tail_m_ital}|#{@vz.markup_make_italic[:str]}#{tail_m_ital}|\S+|\n/
+ end
+ @manmkp_bold='^!_\s.+?(?:\n|$)|[*!b]\\{.+?\\}[*!b]|[*!][a-zA-Z0-9\-_]+[*!]'
+ @line_scan_bold=if (defined? @md.make.bold[:str] \
+ and @md.make.bold[:str]) \
+ and (defined? @vz.markup_make_bold[:str] \
+ and @vz.markup_make_bold[:str])
+ /#{@http_m}|#{bold_line}|(?:#{@manmkp_bold}|#{@md.make.bold[:str]}|#{@vz.markup_make_bold[:str]})#{tail_m_bold}|\S+|\n/
+ elsif defined? @md.make.bold[:str] \
+ and @md.make.bold[:str]
+ /#{@http_m}|#{bold_line}|(?:#{@manmkp_bold}|#{@md.make.bold[:str]})#{tail_m_bold}|\S+|\n/
+ elsif defined? @vz.markup_make_bold[:str] \
+ and @vz.markup_make_bold[:str]
+ /#{@http_m}|#{bold_line}|(?:#{@manmkp_bold}|#{@vz.markup_make_bold[:str]})#{tail_m_bold}|\S+|\n/
+ end
+ end
+ def songsheet
+ @data.compact!
+ @data.each do |dob|
+ dob=if @md.sem_tag then sem(dob) else dob end #revisit
+ 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 wordlist_italics(dob)
+ dob=dob.dup
+ if (defined? @md.make.italics[:str] \
+ and @md.make.italics[:str]) \
+ or (defined? @vz.markup_make_italic[:str] \
+ and @vz.markup_make_italic[:str])
+ dob.obj=if dob.is !~/^(?:meta|heading|code|comment)/
+ word=dob.obj.scan(@line_scan_ital)
+ word.flatten!
+ word.compact! #reinstated
+ line_array=[]
+ word.each do |w|
+ unless /#{@manmkp_ital}|#{@http_m}/.match(w)
+ if defined? @md.make.italics[:regx] \
+ and @md.make.italics[:regx]
+ w.gsub!(@md.make.italics[:regx],
+ "#{Mx[:fa_italics_o]}\\1#{Mx[:fa_italics_c]}")
+ elsif defined? @vz.markup_make_italic \
+ and @vz.markup_make_italic
+ w.gsub!(@vz.markup_make_italic,
+ "#{Mx[:fa_italics_o]}\\1#{Mx[:fa_italics_c]}")
+ else w
+ end
+ end
+ line_array << w
+ end
+ line_array.join(' ')
+ else dob.obj
+ end
+ end
+ dob
+ end
+ def embolden(given)
+ given.gsub!(/^!_\s+((?:\{|#{Mx[:lnk_o]})(?:~^ )?.+?(?:\}|#{Mx[:lnk_o]})http:\/\/\S+.*?)(<br>|[#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:br_nl]}])/,
+ "#{Mx[:fa_bold_o]} \\1 #{Mx[:fa_bold_c]}\\2")
+ given.gsub!(/^!_\s+((?:\{|#{Mx[:lnk_o]})(?:~^ )?.+?(?:\}|#{Mx[:lnk_o]})http:\/\/\S+.*)/,
+ "#{Mx[:fa_bold_o]} \\1 #{Mx[:fa_bold_c]}")
+ given.gsub!(/(?:^!_|^#{Mx[:lv_o]}[7-9]:\S*?#{Mx[:lv_c]})\s*(.+?)(<br>|[#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:br_nl]}])/,
+ "#{Mx[:fa_bold_o]}\\1#{Mx[:fa_bold_c]}\\2")
+ given.gsub!(/(?:^!_|^#{Mx[:lv_o]}[7-9]:\S*?#{Mx[:lv_c]})\s*(.+?)\s+((?:[*]~\S+\s*)+)/,
+ "#{Mx[:fa_bold_o]}\\1#{Mx[:fa_bold_c]}\\2")
+ given.gsub!(/(?:^!_|^#{Mx[:lv_o]}[7-9]:\S*?#{Mx[:lv_c]})\s*(.+?)\s*([~-]#)$/,
+ "#{Mx[:fa_bold_o]}\\1#{Mx[:fa_bold_c]}\\2")
+ given.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.gsub!(/^\/_\s*(.+?)(<br>|[#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:br_nl]}])/,
+ "#{Mx[:fa_italics_o]}\\1#{Mx[:fa_italics_c]}\\2")
+ given.gsub!(/^\/_\s*(.+?)\s+((?:[*]~\S+\s*)+)/,
+ "#{Mx[:fa_italics_o]}\\1#{Mx[:fa_italics_c]}\\2")
+ given.gsub!(/^\/_\s*(.+?)\s*([~-]#)$/,
+ "#{Mx[:fa_italics_o]}\\1#{Mx[:fa_italics_c]}\\2")
+ given.gsub!(/^\/_\s+(.*)?\s*$/,
+ "#{Mx[:fa_italics_o]}\\1#{Mx[:fa_italics_c]}")
+ end
+ def wordlist_bold(dob)
+ dob=dob.dup
+ if (defined? @md.make.bold[:str] \
+ and @md.make.bold[:str]) \
+ or (defined? @vz.markup_make_bold[:str] \
+ and @vz.markup_make_bold[:str])
+ dob.obj=if dob.is !~/^(?:meta|heading|code|comment|table)/
+ line_array=[]
+ word=dob.obj.scan(@line_scan_bold)
+ word.flatten!
+ word.compact!
+ word.each do |w|
+ unless /#{@manmkp_bold}|#{@http_m}/.match(w)
+ if defined? @md.make.bold[:regx] \
+ and @md.make.bold[:regx] #document header: @bold: [bold word list]
+ w.gsub!(@md.make.bold[:regx],"#{Mx[:fa_bold_o]}\\1#{Mx[:fa_bold_c]}")
+ elsif defined? @vz.markup_make_bold \
+ and @vz.markup_make_bold #defaults and skin adjusted bold word list
+ w.gsub!(@vz.markup_make_bold,"#{Mx[:fa_bold_o]}\\1#{Mx[:fa_bold_c]}")
+ end
+ else
+ 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
+ if dob.is !~/^(?:heading|comment|meta)/ \
+ and dob.obj =~ /^!_\s+/
+ embolden(dob.obj)
+ elsif dob.is=='heading' \
+ and dob.ln.to_s =~/[7-9]/
+ embolden(dob.obj)
+ end
+ if dob.obj =~ /\/_\s+/
+ italicise(dob.obj)
+ end
+ end
+ dob
+ end
+ def bodymarkup(dob)
+ # << http://www.jus.uio.no/sisu/sisu_markup_table/markup >>
+ # See: data/sisu/sample/document_samples_sisu_markup/
+ # !{emphasis}! e{emphasis}e <strong>emphasis</strong>
+ # *{bold text}* b{bold}b <b>bold text</b>
+ # _{underline}_ u{underline}u <u>underline</u>
+ # /{italics}/ i{italics}i <i>italics</i>
+ # "{citation}" c{citation}c <cite>citation</cite> #blockquote?
+ # ^{superscript}^ <sup>superscript</sup>
+ # ,{subscript}, <sub>subscript</sub>
+ # +{inserted text}+ <ins>inserted text</ins>
+ # -{deleted text}- <del>deleted text</del>
+ # {url address}:url
+ # {image.png}imageurl
+ # {image.png}png
+ # ~{endnote}~ <!e 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|comment|code|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|http:\/\/\S+/ # do something earlier about table!!
+ w.gsub!(/\\?~/,"#{Mx[:gl_o]}#126#{Mx[:gl_c]}") #escaped special character
+ end
+ w.gsub!(/^\<$/,"#{Mx[:gl_o]}#lt#{Mx[:gl_c]}") #escaped special character
+ w.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.gsub!(/^([*#-.]{1,12})$/,'\1 ~#') #ocn off for these paragraph separators
+ dob.obj.gsub!(/~\{(.+?)\}~/m,Mx[:en_a_o] + '\1' + Mx[:en_a_c])
+ dob.obj.gsub!(/~\[([^*+].+?)\]~/m,Mx[:en_b_o] + '* \1' + Mx[:en_b_c]) #default if markup does not specify
+ dob.obj.gsub!(/~\[(.+?)\]~/m,Mx[:en_b_o] + '\1' + Mx[:en_b_c])
+ if dob.is =='heading' \
+ and dob.ln ==1
+ dob.obj.gsub!(/\s*@title\b/," #{@md.title.full}")
+ if defined? @md.creator.author \
+ and @md.creator.author
+ dob.obj.gsub!(/\s+(?:@creator|@author)/,",<br />#{@md.creator.author}")
+ else dob.obj.gsub!(/\s+(?:@creator|@author)/,'')
+ end
+ end
+ if dob.is =='heading'
+ dob.obj.gsub!(/^\s*@title\s*$/,@md.title.full) if dob.lv =~/1/ #
+ 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
+ dob.obj.gsub!(/<(https?:\/\/\S+?)>/,'< \1 >') #catch problem markup
+ dob.obj.gsub!(/<:=(\S+?)>/,'{ c_\1.png 14x14 }http://www.jus.uio.no/sisu') #adjustment 2005w30
+ dob.obj.gsub!(/<!(\S+)!>/,'<:\1>') #escaped special character
+ dob.obj.gsub!(/&nbsp;/,"#{Mx[:nbsp]}") #escaped special character
+ dob.obj.gsub!(/\\~/,"#{Mx[:gl_o]}#126#{Mx[:gl_c]}") #escaped special character
+ dob.obj.gsub!(/\\\{/,"#{Mx[:gl_o]}#123#{Mx[:gl_c]}") #escaped special character
+ dob.obj.gsub!(/\\\}/,"#{Mx[:gl_o]}#125#{Mx[:gl_c]}") #escaped special character
+ dob.obj.gsub!(/\\\<</,"#{Mx[:gl_o]}#lt#{Mx[:gl_c]}#{Mx[:gl_o]}#lt#{Mx[:gl_c]}") #escaped special character
+ dob.obj.gsub!(/\\\>>/,"#{Mx[:gl_o]}#gt#{Mx[:gl_c]}#{Mx[:gl_o]}#gt#{Mx[:gl_c]}") #escaped special character
+ dob.obj.gsub!(/\\\</,"#{Mx[:gl_o]}#lt#{Mx[:gl_c]}") #escaped special character
+ dob.obj.gsub!(/\\\>/,"#{Mx[:gl_o]}#gt#{Mx[:gl_c]}") #escaped special character
+ dob.obj.gsub!(/\\\_/,"#{Mx[:gl_o]}#095#{Mx[:gl_c]}") #escaped special character
+ dob.obj.gsub!(/\\\-/,"#{Mx[:gl_o]}#045#{Mx[:gl_c]}") #escaped special character
+ dob.obj.gsub!(/\\\+/,"#{Mx[:gl_o]}#043#{Mx[:gl_c]}") #escaped special character
+ dob.obj.gsub!(/\\\//,"#{Mx[:gl_o]}#047#{Mx[:gl_c]}") #escaped special character
+ dob.obj.gsub!(/\\\#/,"#{Mx[:gl_o]}#035#{Mx[:gl_c]}") #escaped special character
+ dob.obj.gsub!(/\\\&/,"#{Mx[:gl_o]}#038#{Mx[:gl_c]}") #&amp; #escaped special character
+ dob.obj.gsub!(/\\\|/,"#{Mx[:gl_o]}#124#{Mx[:gl_c]}") #not really a sisu special character but made available as possibility
+ dob.obj.gsub!(/\\\:/,"#{Mx[:gl_o]}#058#{Mx[:gl_c]}") #not really a sisu special character but made available as possibility
+ dob.obj.gsub!(/\\\!/,"#{Mx[:gl_o]}#033#{Mx[:gl_c]}") #not really a sisu special character but made available as possibility
+ dob.obj.gsub!(/\\\^/,"#{Mx[:gl_o]}#094#{Mx[:gl_c]}") #not really a sisu special character but made available as possibility
+ dob.obj.gsub!(/\\\,/,"#{Mx[:gl_o]}#044#{Mx[:gl_c]}") #not really a sisu special character but made available as possibility
+ dob.obj.gsub!(/\\\\/,"#{Mx[:gl_o]}#092#{Mx[:gl_c]}") #escaped special character
+ dob.obj.gsub!(/\\\*/,"#{Mx[:gl_o]}#042#{Mx[:gl_c]}") #escaped special character
+ dob.obj.gsub!(/\\\!/,"#{Mx[:gl_o]}#033#{Mx[:gl_c]}") #escaped special character
+ dob.obj.gsub!(/(?:<:?br>|<br \/>)/,"#{Mx[:br_line]}") #indent used in endnotes, not implemented, replace when ready with: line.gsub!(/(?:<br>|<br \/>)\s*_([12])\s+/,'<br><:i\1> ')
+ 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.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.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.gsub!(/\{\s*([^{}]+?)\s*\}((?:https?:|[.]{2}\/|#)\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]}\\2") #linked (text or image, however text cannot include modified face, e.g. bold, ital, underline)
+ 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})
+ if dob.obj=~/#{Mx[:lnk_c]}([.]{2}\/\S+?[^>< ]+?)[,.;'"]?(?=[\s#{Mx[:en_a_c]}#{Mx[:en_b_c]}#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:br_nl]}]|$)/m
+ lnk=$1
+ dob.obj.gsub!(/#{Mx[:lnk_c]}#{lnk}([,.;'"]?)(?=[\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]}#{lnk}#{Mx[:rel_c]}\\1})
+ end
+ if dob.obj=~/#{Mx[:lnk_c]}#(\S+?[^>< ]+?)[,.;'"]?(?=[\s#{Mx[:en_a_c]}#{Mx[:en_b_c]}#{Mx[:br_line]}#{Mx[:br_paragraph]}#{Mx[:br_nl]}]|$)/m
+ lnk=$1
+ dob.obj.gsub!(/#{Mx[:lnk_c]}##{lnk}([,.;'"]?)(?=[\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]}#{lnk}#{Mx[:rel_c]}\\1})
+ end
+ end
+ if dob.obj=~/_(?:https?|ftp):\S+/m # _http://url #CHECK
+ 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.obj.gsub!(/<:?p([nb])>/,"#{Mx[:fa_o]}p\\1#{Mx[:fa_c]}") #indent used in endnotes, not implemented, replace when ready with: line.gsub!(/(?:<br>|<br \/>)\s*_([12])\s+/,'<br><:i\1> ')
+ dob.obj.gsub!(/(^|#{Mx[:gl_c]}|\s+|['"]|#{Mx[:nbsp]}|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|#{Mx[:lnk_o]}|#{Mx[:br_line]}|#{Mx[:br_paragraph]}|[\(\[\{]|\>)!\{(.+?)\}!/,
+ "\\1#{Mx[:fa_bold_o]}\\2#{Mx[:fa_bold_c]}") #emphasis
+ dob.obj.gsub!(/(^|#{Mx[:gl_c]}|\s+|['"]|#{Mx[:nbsp]}|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|#{Mx[:lnk_o]}|#{Mx[:br_line]}|#{Mx[:br_paragraph]}|[\(\[\{]|\>)\*\{(.+?)\}\*/,
+ "\\1#{Mx[:fa_bold_o]}\\2#{Mx[:fa_bold_c]}") #bold
+ dob.obj.gsub!(/(^|#{Mx[:gl_c]}|\s+|['"]|#{Mx[:nbsp]}|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|#{Mx[:lnk_o]}|#{Mx[:br_line]}|#{Mx[:br_paragraph]}|[\(\[\{]|\>)_\{(.+?)\}_/,
+ "\\1#{Mx[:fa_underscore_o]}\\2#{Mx[:fa_underscore_c]}") #underscore
+ dob.obj.gsub!(/(^|#{Mx[:gl_c]}|\s+|['"]|#{Mx[:nbsp]}|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|#{Mx[:lnk_o]}|#{Mx[:br_line]}|#{Mx[:br_paragraph]}|[\(\[]|\(|\>)\/\{(.+?)\}\//,
+ "\\1#{Mx[:fa_italics_o]}\\2#{Mx[:fa_italics_c]}") #italics
+ dob.obj.gsub!(/(^|#{Mx[:gl_c]}|\s+|['"]|#{Mx[:nbsp]}|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)\"\{(.+?)\}\"/,
+ "\\1#{Mx[:fa_cite_o]}\\2#{Mx[:fa_c_o]}cite#{Mx[:fa_c]}") #cite /blockquote?
+ dob.obj.gsub!(/(^|[^\\])\^\{(.+?)\}\^/,
+ "\\1#{Mx[:fa_superscript_o]}\\2#{Mx[:fa_superscript_c]}") #superscript
+ dob.obj.gsub!(/(^|#{Mx[:gl_c]}|\s+|['"]|#{Mx[:nbsp]}|\(|\>|\S)9\{(.+?)\}9/,
+ "\\1#{Mx[:fa_superscript_o]}\\2#{Mx[:fa_superscript_c]}") #superscript
+ dob.obj.gsub!(/(^|[^\\]),\{(.+?)\},/,
+ "\\1#{Mx[:fa_subscript_o]}\\2#{Mx[:fa_subscript_c]}") #subscript
+ dob.obj.gsub!(/(^|#{Mx[:gl_c]}|\s+|['"]|#{Mx[:nbsp]}|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)6\{(.+?)\}6/,
+ "\\1#{Mx[:fa_subscript_o]}\\2#{Mx[:fa_subscript_c]}") #subscript
+ dob.obj.gsub!(/(^|#{Mx[:gl_c]}|\s+|['"]|#{Mx[:nbsp]}|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)\+\{(.+?)\}\+/,
+ "\\1#{Mx[:fa_insert_o]}\\2#{Mx[:fa_insert_c]}") #inserted text
+ dob.obj.gsub!(/(^|#{Mx[:gl_c]}|\s+|['"]|#{Mx[:nbsp]}|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)v\{(.+?)\}v/,
+ "\\1#{Mx[:fa_insert_o]}\\2#{Mx[:fa_insert_c]}") #inserted text
+ dob.obj.gsub!(/(^|#{Mx[:gl_c]}|\s+|['"]|#{Mx[:nbsp]}|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)-\{(.+?)\}-/,
+ "\\1#{Mx[:fa_strike_o]}\\2#{Mx[:fa_strike_c]}") #strikethrough - deleted text
+ dob.obj.gsub!(/(^|#{Mx[:gl_c]}|\s+|['"]|#{Mx[:nbsp]}|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)x\{(.+?)\}x/,
+ "\\1#{Mx[:fa_strike_o]}\\2#{Mx[:fa_strike_c]}") #deleted text
+ dob.obj.gsub!(/(^|#{Mx[:gl_c]}|\s+|['"]|#{Mx[:nbsp]}|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)\*(\S+?)\*/,
+ "\\1#{Mx[:fa_bold_o]}\\2#{Mx[:fa_bold_c]}") #bold single word, watch
+ dob.obj.gsub!(/(^|#{Mx[:gl_c]}|\s+|['"]|#{Mx[:nbsp]}|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)\!(\S+?)\!/,
+ "\\1#{Mx[:fa_bold_o]}\\2#{Mx[:fa_bold_c]}") #bold single word, watch
+ dob.obj.gsub!(/(^|#{Mx[:gl_c]}|\s+|['"]|#{Mx[:nbsp]}|#{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
+ dob.obj.gsub!(/(^|#{Mx[:gl_c]}|\s+|['"]|#{Mx[:nbsp]}|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)_(\S+?)_([.,!'")]?(?:\s|$))/,
+ "\\1#{Mx[:fa_underscore_o]}\\2#{Mx[:fa_underscore_c]}\\3") #underscore single word, watch (made more complicated by url decoration escape tag (_url))
+ dob.obj.gsub!(/(^|#{Mx[:gl_c]}|\s+)-([^{]\S+?)-( |$)/,
+ "\\1#{Mx[:fa_strike_o]}\\2#{Mx[:fa_strike_c]}\\3") #underscore single word, watch
+ dob.obj.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.obj.gsub!(/<[:e]\s+(.+?)!?>/,
+ "#{Mx[:en_a_o]}\\1#{Mx[:en_a_c]}") #not tested
+ dob.obj.gsub!(/^\s*_\*\s*/,
+ "#{Mx[:gl_bullet]}") #bullets, shortcut
+ dob.obj.gsub!(/=\{(.+?)\}/,
+ "#{Mx[:idx_o]}\\1#{Mx[:idx_c]}")
+ dob.obj.gsub!(/^\s*_([1-9])\*\s*/,
+ "#{Mx[:pa_o]}:i\\1#{Mx[:pa_c]}#{Mx[:gl_bullet]}") #bullets, shortcut
+ dob.obj.gsub!(/^\s*_([1-9])\s+/,
+ "#{Mx[:pa_o]}:i\\1#{Mx[:pa_c]}") #indent
+ dob.obj.gsub!(/(?:<:?br>|<br \/>)/,
+ "#{Mx[:br_line]}") #indent used in endnotes, not implemented, replace when ready with: line.gsub!(/(?:<br>|<br \/>)\s*_([12])\s+/,'<br><:i\1> ')
+ dob.obj.gsub!(/<:hi>/,"#{Mx[:fa_hilite_o]}") #'<span style="background-color: rgb(255,240,196)">') # bright yellow rgb(255,255,0) pale yellow rgb(255,255,200)
+ dob.obj.gsub!(/<:\/hi>/,"#{Mx[:fa_hilite_c]}") #'</span>')
+ dob.obj.gsub!(/(#{Mx[:gr_o]}verse#{Mx[:gr_c]}.+)/m,"\\1\n")
+ dob.obj.gsub!(/[ ]+($)/,'\1')
+ dob.obj.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]}\\2\\3") #any remaining linked text or image
+ dob.obj.gsub!(/\{\s*(.+?)\s*\}(#{Mx[:url_o]}\S+?#{Mx[:url_c]})/,
+ "#{Mx[:lnk_o]}\\1#{Mx[:lnk_c]}\\2") #any remaining linked text or image
+ dob.obj.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
+ dob.obj.gsub!(/\{\s*(.+?)\s*\}(#{Mx[:rel_o]}\S+?#{Mx[:rel_c]})/,
+ "#{Mx[:lnk_o]}\\1#{Mx[:lnk_c]}\\2") #any remaining linked text or image
+ dob.obj.gsub!(/\{\s*(.+?)\s*\}(image)/,
+ "#{Mx[:lnk_o]}\\1#{Mx[:lnk_c]}\\2") #linked image
+ elsif dob.is=='table'
+ elsif dob.is =='code' # /^<:code>/ #should be enough # underscore used as escape for angle brackets
+ dob.obj.gsub!(/#{Mx[:meta_o]}(\S+?)#{Mx[:meta_c]}\s*/,'@\1: ')
+ dob.obj.gsub!(/([<>])/,'_\1')
+ dob.obj.gsub!(/_<:(\S+?)_>/,'<:\1>') #convert <:\S+> back, clumsy
+ dob.obj.gsub!(/_<(br(?: \/)?)_>/,'<\1>') #convert <br> <br /> back, clumsy
+ dob.obj.gsub!(/(^|#{Mx[:gl_c]}|\s)&lt;(br(?: \/)?)&gt;([\s,.]|$)/,'\1<\2>\3') #convert <br> <br /> back, clumsy
+ dob.obj.gsub!(/#{Mx[:gr_o]}codeline#{Mx[:gr_c]}/,
+ "\n#{Mx[:nbsp]}#{Mx[:nbsp]}") #temporary fix, prefer: #line.gsub!(/<:codeline>/,"\n")
+ dob
+ else # @\S+?:
+ end
+ dob
+ end
+ def tech #script markup planned to be more strict for technical documents
+ # !{emphasis}! e{emphasis}e <strong>emphasis</strong>
+ # *{bold text}* b{bold}b <b>bold text</b>
+ # _{underline}_ u{underline}u <u>underline</u>
+ # /{italics}/ i{italics}i <i>italics</i>
+ # "{citation}" c{citation}c <cite>citation</cite>
+ # ^{superscript}^ <sup>superscript</sup>
+ # ,{subscript}, <sub>subscript</sub>
+ # +{inserted text}+ <ins>inserted text</ins>
+ # -{deleted text}- <del>deleted text</del>
+ # {url address}:url
+ # {image.png}imageurl
+ # {image.png}png
+ # ~{endnote}~ <!e endnote !>
+ # +1 <!i1!>
+ # +2 <!i2!>
+ puts 'tech'
+ @data.each do |line|
+ line.gsub!(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|[\(\[]|\>)e\{(.+?)\}e/,
+ "\\1#{Mx[:fa_bold_o]}\\2#{Mx[:fa_bold_c]}") #emphasis
+ line.gsub!(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|[\(\[]|\>)b\{(.+?)\}b/,
+ "\\1#{Mx[:fa_bold_o]}\\2#{Mx[:fa_bold_c]}") #bold
+ line.gsub!(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|[\(\[]|\>)u\{(.+?)\}u/,
+ "\\1#{Mx[:fa_underscore_o]}\\2#{Mx[:fa_underscore_c]}") #underscore
+ line.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
+ line.gsub!(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|[\(\[]|\>)i\{(.+?)\}i/,
+ "\\1#{Mx[:fa_italics_o]}\\2#{Mx[:fa_italics_c]}") #italics
+ line.gsub!(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|[\(\[]|\>)!\{(.+?)\}!/,
+ "\\1#{Mx[:fa_bold_o]}\\2#{Mx[:fa_bold_c]}") #emphasis
+ line.gsub!(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|[\(\[]|\>)\*\{(.+?)\}\*/,
+ "\\1#{Mx[:fa_bold_o]}\\2#{Mx[:fa_bold_c]}") #bold
+ line.gsub!(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|[\(\[]|\>)_\{(.+?)\}_/,
+ "\\1#{Mx[:fa_underscore_o]}\\2#{Mx[:fa_underscore_c]}") #underscore
+ line.gsub!(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|[\(\[]|\(|\>)\/\{(.+?)\}\//,
+ "\\1#{Mx[:fa_italics_o]}\\2#{Mx[:fa_italics_c]}") #italics
+ line.gsub!(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)\"\{(.+?)\}\"/,
+ "\\1#{Mx[:fa_cite_o]}\\2#{Mx[:fa_c_o]}cite#{Mx[:fa_c]}")
+ line.gsub!(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)\^\{(.+?)\}\^/,
+ "\\1#{Mx[:fa_superscript_o]}\\2#{Mx[:fa_superscript_c]}")
+ line.gsub!(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)9\{(.+?)\}9/,
+ "\\1#{Mx[:fa_superscript_o]}\\2#{Mx[:fa_superscript_c]}")
+ line.gsub!(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>),\{(.+?)\},/,
+ "\\1#{Mx[:fa_subscript_o]}\\2#{Mx[:fa_subscript_c]}")
+ line.gsub!(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)6\{(.+?)\}6/,
+ "\\1#{Mx[:fa_subscript_o]}\\2#{Mx[:fa_subscript_c]}")
+ line.gsub!(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)\+\{(.+?)\}\+/,
+ "\\1#{Mx[:fa_insert_o]}\\2#{Mx[:fa_insert_c]}")
+ line.gsub!(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)v\{(.+?)\}v/,
+ "\\1#{Mx[:fa_insert_o]}\\2#{Mx[:fa_insert_c]}")
+ line.gsub!(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)-\{(.+?)\}-/,
+ "\\1#{Mx[:fa_strike_o]}\\2#{Mx[:fa_strike_c]}")
+ line.gsub!(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)x\{(.+?)\}x/,
+ "\\1#{Mx[:fa_strike_o]}\\2#{Mx[:fa_strike_c]}")
+ line.gsub!(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)\*(\S+?)\*/,
+ "\\1#{Mx[:fa_bold_o]}\\2#{Mx[:fa_bold_c]}") #bold single word, watch
+ line.gsub!(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)\!(\S+?)\!/,
+ "\\1#{Mx[:fa_bold_o]}\\2#{Mx[:fa_bold_c]}") #bold single word, watch
+ line.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
+ line.gsub!(/(^|\s+|['"]|#{Mx[:fa_o_c]}|#{Mx[:fa_c]}|\(|\>)_(\S+?)_/,
+ "\\1#{Mx[:fa_underscore_o]}\\2#{Mx[:fa_underscore_c]}") #underscore single word, watch
+ line.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
+ line.gsub!(/^\s*_\([1-9]\)\(\*\+\)\s*/,
+ "#{Mx[:pa_o]}:i\\1#{Mx[:pa_c]}#{Mx[:fa_o]}\\2#{Mx[:fa_c_o]}") #bullets, shortcut
+ line.gsub!(/^\s*_\([1-9]\)\s+/,
+ "#{Mx[:pa_o]}:i\\1#{Mx[:pa_c]}")
+ line.gsub!(/(?:<:?br>|<br \/>)\s*_[12]\s+/,
+ "#{Mx[:br_line]} ") #indent used in endnotes, not implemented, replace when ready with: line.gsub!(/(?:<br>|<br \/>)\s*_([12])\s+/,'<br><:i\1> ')
+ end
+ @data
+ end
+ end
+end
+__END__