From 75e3bf86382edf99275a25895b362647158e25c1 Mon Sep 17 00:00:00 2001 From: Ralph Amissah Date: Tue, 10 Jan 2012 22:37:26 -0500 Subject: v3dv, add dev branch (use to make some changes to module & class names & test) * (intended as) short term branch, merge back into v3 once tested * sisu --dev (to invoke) --- lib/sisu/v3dv/html_tune.rb | 383 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 383 insertions(+) create mode 100644 lib/sisu/v3dv/html_tune.rb (limited to 'lib/sisu/v3dv/html_tune.rb') diff --git a/lib/sisu/v3dv/html_tune.rb b/lib/sisu/v3dv/html_tune.rb new file mode 100644 index 00000000..e8c12d6a --- /dev/null +++ b/lib/sisu/v3dv/html_tune.rb @@ -0,0 +1,383 @@ +# encoding: utf-8 +=begin + + * Name: SiSU + + * Description: a framework for document structuring, publishing and search + + * Author: Ralph Amissah + + * Copyright: (C) 1997 - 2012, Ralph Amissah, All Rights Reserved. + + * License: GPL 3 or later: + + SiSU, a framework for document structuring, publishing and search + + Copyright (C) Ralph Amissah + + This program is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + more details. + + You should have received a copy of the GNU General Public License along with + this program. If not, see . + + If you have Internet connection, the latest version of the GPL should be + available at these locations: + + + + + + + + * SiSU uses: + * Standard SiSU markup syntax, + * Standard SiSU meta-markup syntax, and the + * Standard SiSU object citation numbering and system + + * Hompages: + + + + * Download: + + + * Ralph Amissah + + + + ** Description: html generation, html pre-processing + +=end +require_relative 'param' +module SiSU_HTML_Tune + require_relative 'sysenv' # sysenv.rb + include SiSU_Env; include SiSU_Screen + require_relative 'html_format' # html_format.rb #watch + @@line_mode='' + @@endnote_array=[] + @@endnote_call_counter=1 + @@table_align=' + + +
+ \;' + @@table_align_close=' + +   
' + @@counter,@@column,@columns=0,0,0 + class Output + def initialize(data,md) + @data,@md=data,md + @file=SiSU_Env::Info_file.new(@md.fns) + @cX=SiSU_Screen::Ansi.new(@md.opt.cmd).cX + end + def hard_output + @filename_tune=@file.write_file_processing.html_tune + data=[] + @data.each do |x| + unless x.obj.empty? + x.obj.strip! + data << x + end + end + data.each do |dob| + @filename_tune.puts dob, "\n" + end + end + def marshal + File.open(@file.marshal.html_tune,'w') {|f| Marshal.dump(@data.to_a,f)} + end + end + class Clean_html + def initialize(html='') + @html=html + end + def clean + html=@html + str=if html.class==String + html + else html.obj + end + str.gsub!(/#{Mx[:gl_o]}(#[0-9]{3})#{Mx[:gl_c]}/u,'&\1;') + str.gsub!(/#{Mx[:gl_o]}#([a-z]{2,4})#{Mx[:gl_c]}/u,'&\1;') + str.gsub!(/¢/u,'¢') # ¢ + str.gsub!(/£/u,'£') # £ + str.gsub!(/¥/u,'¥') # ¥ + str.gsub!(/§/u,'§') # § + str.gsub!(/©/u,'©') # © + str.gsub!(/ª/u,'ª') # ª + str.gsub!(/«/u,'«') # « + str.gsub!(/®/u,'®') # ® + str.gsub!(/°/u,'°') # ° + str.gsub!(/±/u,'±') # ± + str.gsub!(/²/u,'²') # ² + str.gsub!(/³/u,'³') # ³ + str.gsub!(/µ/u,'µ') # µ + str.gsub!(/¶/u,'¶') # ¶ + str.gsub!(/¹/u,'¹') # ¹ + str.gsub!(/º/u,'º') # º + str.gsub!(/»/u,'»') # » + str.gsub!(/¼/u,'¼') # ¼ + str.gsub!(/½/u,'½') # ½ + str.gsub!(/¾/u,'¾') # ¾ + str.gsub!(/×/u,'×') # × + str.gsub!(/÷/u,'÷') # ÷ + str.gsub!(/¿/u,'¿') # ¿ + str.gsub!(/À/u,'À') # À + str.gsub!(/Á/u,'Á') # Á + str.gsub!(/Â/u,'Â') # Â + str.gsub!(/Ã/u,'Ã') # Ã + str.gsub!(/Ä/u,'Ä') # Ä + str.gsub!(/Å/u,'Å') # Å + str.gsub!(/Æ/u,'Æ') # Æ + str.gsub!(/Ç/u,'Ç') # Ç + str.gsub!(/È/u,'È') # È + str.gsub!(/É/u,'É') # É + str.gsub!(/Ê/u,'Ê') # Ê + str.gsub!(/Ë/u,'Ë') # Ë + str.gsub!(/Ì/u,'Ì') # Ì + str.gsub!(/Í/u,'Í') # Í + str.gsub!(/Î/u,'Î') # Î + str.gsub!(/Ï/u,'Ï') # Ï + str.gsub!(/Ð/u,'Ð') # Ð + str.gsub!(/Ñ/u,'Ñ') # Ñ + str.gsub!(/Ò/u,'Ò') # Ò + str.gsub!(/Ó/u,'Ó') # Ó + str.gsub!(/Ô/u,'Ô') # Ô + str.gsub!(/Õ/u,'Õ') # Õ + str.gsub!(/Ö/u,'Ö') # Ö + str.gsub!(/Ø/u,'Ø') # Ø + str.gsub!(/Ù/u,'Ù') # Ù + str.gsub!(/Ú/u,'Ú') # Ú + str.gsub!(/Û/u,'Û') # Û + str.gsub!(/Ü/u,'Ü') # Ü + str.gsub!(/Ý/u,'Ý') # Ý + str.gsub!(/Þ/u,'Þ') # Þ + str.gsub!(/ß/u,'ß') # ß + str.gsub!(/à/u,'à') # à + str.gsub!(/á/u,'á') # á + str.gsub!(/â/u,'â') # â + str.gsub!(/ã/u,'ã') # ã + str.gsub!(/ä/u,'ä') # ä + str.gsub!(/å/u,'å') # å + str.gsub!(/æ/u,'æ') # æ + str.gsub!(/ç/u,'ç') # ç + str.gsub!(/è/u,'è') # è + str.gsub!(/é/u,'é') # é + str.gsub!(/ê/u,'ê') # ê + str.gsub!(/ë/u,'ë') # ë + str.gsub!(/ì/u,'ì') # ì + str.gsub!(/í/u,'í') # í + str.gsub!(/î/u,'î') # î + str.gsub!(/ï/u,'ï') # ï + str.gsub!(/ð/u,'ð') # ð + str.gsub!(/ñ/u,'ñ') # ñ + str.gsub!(/ò/u,'ò') # ò + str.gsub!(/ó/u,'ó') # ó + str.gsub!(/ô/u,'ô') # ô + str.gsub!(/õ/u,'õ') # õ + str.gsub!(/ö/u,'ö') # ö + str.gsub!(/ø/u,'ø') # ø + str.gsub!(/ù/u,'ù') # ú + str.gsub!(/ú/u,'ú') # û + str.gsub!(/û/u,'û') # ü + str.gsub!(/ü/u,'ü') # ý + str.gsub!(/þ/u,'þ') # þ + str.gsub!(/ÿ/u,'ÿ') # ÿ + str.gsub!(/ý/u,'ý') + str + end + end + class Tune + def initialize(data,md) + @data,@md=data,md + @vz=SiSU_Env::Get_init.instance.skin + @env=SiSU_Env::Info_env.new(@md.fns) + @sys=SiSU_Env::System_call.new + @env=SiSU_Env::Info_env.new(@md.fns) + @brace_url=SiSU_Viz::Skin.new.url_decoration + end + def songsheet + begin + @cX=SiSU_Screen::Ansi.new(@md.opt.cmd).cX + SiSU_Screen::Ansi.new(@md.opt.cmd,'Tune').txt_grey if @md.opt.cmd =~/[MVv]/ + songsheet_array(@data) + #data=songsheet_array(@data) + if @md.opt.cmd =~/M/ #Hard Output Tune Optional on/off here + data=Output.new(@data,@md).hard_output + Output.new(@data,@md).marshal + end + tuned=Tune.new(@data,@md).output + rescue; SiSU_Errors::Info_error.new($!,$@,@md.opt.cmd,@md.fns).error + ensure + end + end + def songsheet_array(data) + data_tuned=[] + #@tuned_file=[] + data.each do |dob| + dob=angle_brackets(dob) + dob=endnotes_html(dob) + dob=url_markup(dob) + dob=markup(dob) + data_tuned << dob + end + data_tuned + end + def urls(data) + @words=[] + data.each do |word| + @words << if word=~/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}|image)/ + http_=true + if word =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/ + m,u=/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/.match(word).captures + elsif word =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:rel_o]}:\S+?#{Mx[:rel_c]}/ + #http_=false + m,u=/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:rel_o]}:(\S+?)#{Mx[:rel_c]}/.match(word).captures + u="#{Xx[:html_relative2]}/" + u + elsif word =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}/ + http_=false + m,u=/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}#{Mx[:rel_o]}(\S+?)#{Mx[:rel_c]}/.match(word).captures + elsif word =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}image/ + m,u=/#{Mx[:lnk_o]}(.+?)#{Mx[:lnk_c]}(image)/.match(word).captures + end + case m + when /\.png|\.jpg|\.gif|c=|\s\d+x\d+/ + w,h=/\s(\d+)x(\d+)/.match(m).captures if m =~/\s\d+x\d+/ + w=%{width="#{w}"} if w + h=%{height="#{h}"} if h + c=m[/"(.+?)"/m,1] + caption=%{

#{c}

} if c + png=m.scan(/\S+/)[0] + image_path=@md.file.output_path.html_seg.rel_image + #image_path=(@md.fns =~/\.-ss[tm]$/) \ + #? @env.url.images_external + #: @env.url.images_local + ins=if u \ + and u.strip !~/^image$/ + %{#{caption}} + else %{#{caption}} + end + word.gsub!(/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|image)/,ins) + else + link=m[/(.+)/m] + png=m.scan(/\S+/)[0].strip + link=link.strip + u.gsub!(/(\S+)/,"#{Xx[:segment]}#\\1") if u !~/\// unless http_ #marker: in scroll remove; in seg replace + ins=%{#{link}} + word.gsub!(/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:url_o]}\S+?#{Mx[:url_c]}/,ins) + word.gsub!(/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}/,ins) + end + word + else word + end + word + end + @words=@words.join(' ') + end + def url_markup(dob) + unless dob.is=='code' + if dob.obj =~/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}|image)/ + @word_mode=dob.obj.scan(/#{Mx[:lnk_o]}.+?#{Mx[:lnk_c]}(?:#{Mx[:url_o]}\S+?#{Mx[:url_c]}|#{Mx[:rel_o]}\S+?#{Mx[:rel_c]}|image)[()\[\]]*[,.;:!?'"]{0,2}|(?:#{Mx[:gl_o]}\S+?#{Mx[:gl_c]})+|[^#{Mx[:lnk_o]}#{Mx[:lnk_c]}]+/mu) + words=urls(@word_mode) + dob.obj.gsub!(/.+/m,words) + end #consider change, do a while loop + dob.obj.gsub!(/\\copyright/i,%{©}) + if (dob.obj !~/\<:ad\s+\.\.\//) + dob.obj.gsub!(/\<:ad\s+(\S+)?\s+(\S+\.png)\s+(.+)?\;\s+(.+)?\;\s*!\>/, + %{\n
\\3
\n}) + else + dob.obj.gsub!(/\<:ad\s+(\S+)?\s+(\S+\.png)\s+(.+)?\;\s+(.+)?\;\s*\>/, + %{\n
\\3
\n}) + end + dob.obj.gsub!(/!pick/,%{stellar}) + dob.obj.gsub!(/!new/,%{ new}) + dob.obj.gsub!(/<:h(.{1,7}?)>/,'\1') + dob.obj.gsub!(/<:to(\d{1,7}?)>/,'to { \1 } ') + dob.obj.gsub!(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/,'\1') #http ftp matches escaped, no decoration + dob.obj.gsub!(/#{Mx[:url_o]}([a-zA-Z0-9._-]+\@\S+?\.[a-zA-Z0-9._-]+)#{Mx[:url_c]}/,%{#{@brace_url.xml_open}\\1#{@brace_url.xml_close}}) + dob.obj.gsub!(/#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,%{#{@brace_url.xml_open}\\1#{@brace_url.xml_close}}) #http ftp matches with decoration + if dob.obj =~/#{Xx[:html_relative2]}\/\S+/ \ + and dob.obj !~/(\"#{Xx[:html_relative2]}\/\S+?\"|>\s*#{Xx[:html_relative2]}\/\S+<)/ + dob.obj.gsub!(/(#{Xx[:html_relative2]}\/\S+)/,'\1') + end + if dob.obj =~/..\/\S+/ \ + and dob.obj !~/(\"..\/\S+?\"|>\s*..\/\S+<)/ + dob.obj.gsub!(/\.\.(\/\S+)/,%{\1}) + end + dob.obj.gsub!(//m,'>') + end + dob + end + def para_numbers + data=@data + @tuned_file=[] + data.each do |dob| + dob.gsub!(/#{Mx[:lv_o]}\d:(\S?)#{Mx[:lv_c]}/,'\0#\1. ') #fix Mx[:lv_o] + @tuned_file << dob + end + end + def angle_brackets(dob) + dob.obj.gsub!(/<([a-z:\/]+)>/,"#{Dx[:lt_xml]}\\1#{Dx[:gt_xml]}") + dob + end + def endnotes_html(dob) + unless dob.is =~/^code/ + dob.obj.gsub!(/(#{Mx[:en_a_o]}|#{Mx[:en_b_o]})(\d+)\s+(.+?)(#{Mx[:en_a_c]}|#{Mx[:en_b_c]})/, + '  \2  ' + #note- endnote- + '\1\2  \2. \3 \4') #endnote- note- (careful may have switched) + dob.obj.gsub!(/(#{Mx[:en_b_o]})([*+]\d+)\s+(.+?)(#{Mx[:en_b_c]})/, + '  \2  ' + #note- endnote- + '\1\2  \2. \3 \4') #endnote- note- (careful may have switched) + dob.obj.gsub!(/(#{Mx[:en_a_o]})([*+]+)\s+(.+?)(#{Mx[:en_a_c]})/, + '  \2  ' + #note- endnote- + '\1\2  \2 \3 \4') #endnote- note- (careful may have switched) + end + dob + end + def markup(dob) + dob.obj.gsub!(/#{Mx[:mk_o]}#([a-zA-Z]+)#{Mx[:mk_c]}/,'&\1;') + dob.obj.gsub!(/#{Mx[:mk_o]}(#[0-9]+)#{Mx[:mk_c]}/,'&\1;') + dob.obj.gsub!(/#{Mx[:br_line]}|#{Mx[:br_nl]}/,'
') unless dob.is=='table' + dob.obj.gsub!(/#{Mx[:fa_bold_o]}(.+?)#{Mx[:fa_bold_c]}/,'\1') + dob.obj.gsub!(/#{Mx[:fa_italics_o]}(.+?)#{Mx[:fa_italics_c]}/,'\1') + dob.obj.gsub!(/#{Mx[:fa_underscore_o]}(.+?)#{Mx[:fa_underscore_c]}/,'\1') + dob.obj.gsub!(/#{Mx[:fa_superscript_o]}(.+?)#{Mx[:fa_superscript_c]}/,'\1') + dob.obj.gsub!(/#{Mx[:fa_subscript_o]}(.+?)#{Mx[:fa_subscript_c]}/,'\1') + dob.obj.gsub!(/#{Mx[:fa_insert_o]}(.+?)#{Mx[:fa_insert_c]}/,'\1') + dob.obj.gsub!(/#{Mx[:fa_cite_o]}(.+?)#{Mx[:fa_cite_c]}/,'\1') + dob.obj.gsub!(/#{Mx[:fa_strike_o]}(.+?)#{Mx[:fa_strike_c]}/,'\1') + dob.obj.gsub!(/#{Mx[:fa_monospace_o]}(.+?)#{Mx[:fa_monospace_c]}/,'\1') # tt, kbd + dob.obj.gsub!(/#{Mx[:mk_o]}:name#(\S+?)#{Mx[:mk_c]}/,'') + dob.obj.gsub!(/^#{Mx[:gl_bullet]}/m,'●  ') + dob.obj.gsub!(/#{Mx[:nbsp]}/,' ') + dob.obj.gsub!(/<(p|br)>/,'<\1 />') + dob=SiSU_HTML_Tune::Clean_html.new(dob).clean + dob + end + def output + data=@data + @tuned_file=[] + data.each do |dob| + dob.obj.strip! + dob.obj.chomp! + @tuned_file << dob + end + @tuned_file << "\n" if (@md.fns =~/\.sst0/) #remove + @tuned_file + end + end +end +__END__ -- cgit v1.2.3