diff options
-rw-r--r-- | data/doc/sisu/CHANGELOG_v3 | 5 | ||||
-rw-r--r-- | lib/sisu/v3/html_tune.rb | 179 |
2 files changed, 99 insertions, 85 deletions
diff --git a/data/doc/sisu/CHANGELOG_v3 b/data/doc/sisu/CHANGELOG_v3 index fd2fd32e..4f2f4713 100644 --- a/data/doc/sisu/CHANGELOG_v3 +++ b/data/doc/sisu/CHANGELOG_v3 @@ -38,6 +38,11 @@ http://www.jus.uio.no/sisu/pkg/src/sisu_3.0.13.orig.tar.gz * plaintext, codeblock keep backslashes + * html_tune revision + * deal with angle brackets in markup (test, could cause breakage) + * reduce loops + + * constants, a sisupod & an xml related addition * ansi screen reporting include document language code diff --git a/lib/sisu/v3/html_tune.rb b/lib/sisu/v3/html_tune.rb index 26072704..c97183f1 100644 --- a/lib/sisu/v3/html_tune.rb +++ b/lib/sisu/v3/html_tune.rb @@ -82,7 +82,12 @@ module SiSU_HTML_Tune def hard_output @filename_tune=@file.write_file_processing.html_tune data=[] - @data.each {|x| x.obj.strip; data << x if not x.obj.empty?} #1.9 array? + @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 @@ -204,48 +209,28 @@ module SiSU_HTML_Tune 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]/ - data=Tune.new(@data,@md).endnotes_html - data=Tune.new(data,@md).url_markup - data=Tune.new(data,@md).markup + 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 + 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 para_numbers - data=@data - @tuned_file=[] + def songsheet_array(data) + data_tuned=[] + #@tuned_file=[] data.each do |dob| - dob.gsub!(/#{Mx[:lv_o]}\d:(\S?)#{Mx[:lv_c]}/,'\0<a name="H#\1">#\1.</a> ') #fix Mx[:lv_o] - @tuned_file << dob - end - end - def markup - @tuned_file=[] - @data.each do |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]}/,'<br />') unless dob.is=='table' - dob.obj.gsub!(/#{Mx[:fa_bold_o]}(.+?)#{Mx[:fa_bold_c]}/,'<b>\1</b>') - dob.obj.gsub!(/#{Mx[:fa_italics_o]}(.+?)#{Mx[:fa_italics_c]}/,'<i>\1</i>') - dob.obj.gsub!(/#{Mx[:fa_underscore_o]}(.+?)#{Mx[:fa_underscore_c]}/,'<u>\1</u>') - dob.obj.gsub!(/#{Mx[:fa_superscript_o]}(.+?)#{Mx[:fa_superscript_c]}/,'<sup>\1</sup>') - dob.obj.gsub!(/#{Mx[:fa_subscript_o]}(.+?)#{Mx[:fa_subscript_c]}/,'<sub>\1</sub>') - dob.obj.gsub!(/#{Mx[:fa_insert_o]}(.+?)#{Mx[:fa_insert_c]}/,'<ins>\1</ins>') - dob.obj.gsub!(/#{Mx[:fa_cite_o]}(.+?)#{Mx[:fa_cite_c]}/,'<cite>\1</cite>') - dob.obj.gsub!(/#{Mx[:fa_strike_o]}(.+?)#{Mx[:fa_strike_c]}/,'<del>\1</del>') - dob.obj.gsub!(/#{Mx[:fa_monospace_o]}(.+?)#{Mx[:fa_monospace_c]}/,'<tt>\1</tt>') # tt, kbd - dob.obj.gsub!(/#{Mx[:mk_o]}:name#(\S+?)#{Mx[:mk_c]}/,'<a name="\1"></a>') - 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 - @tuned_file << 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=[] @@ -297,67 +282,91 @@ module SiSU_HTML_Tune end @words=@words.join(' ') end - def url_markup - data=@data - @tuned_file=[] - data.each do |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,%{<sup>©</sup>}) - if (dob.obj !~/\<:ad\s+\.\.\//) - dob.obj.gsub!(/\<:ad\s+(\S+)?\s+(\S+\.png)\s+(.+)?\;\s+(.+)?\;\s*!\>/, - %{\n<center><a href="http:\/\/\\1" target="external"><img src="#{@env.url.images_local}/\\2" alt="\\3"></a></center>\n}) - else - dob.obj.gsub!(/\<:ad\s+(\S+)?\s+(\S+\.png)\s+(.+)?\;\s+(.+)?\;\s*\>/, - %{\n<center><a href="\\1" target="_top"><img src="#{@env.url.images_local}/\\2" alt="\\3"></a></center>\n}) - end - dob.obj.gsub!(/!pick/,%{<img border="0" height="15" width="15" src="#{@env.url.images}/#{@vz.icon_choice}" alt="stellar">}) - dob.obj.gsub!(/!new/,%{ <img border="0" height="15" width="15" src="#{@env.url.images}/#{@vz.icon_new}" alt="new">}) - dob.obj.gsub!(/<:h(.{1,7}?)>/,'<a href="#h\1">\1</a>') - dob.obj.gsub!(/<:to(\d{1,7}?)>/,'<a href="#to\1">to { \1 }</a> ') - dob.obj.gsub!(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/,'<a href="\1" target="_top">\1</a>') #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}<a href="mailto:\\1">\\1</a>#{@brace_url.xml_close}}) - dob.obj.gsub!(/#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,%{#{@brace_url.xml_open}<a href="\\1" target="_top">\\1</a>#{@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+)/,'<a href="\1">\1</a>') - end - if dob.obj =~/..\/\S+/ \ - and dob.obj !~/(\"..\/\S+?\"|>\s*..\/\S+<)/ - dob.obj.gsub!(/\.\.(\/\S+)/,%{<a href="#{Xx[:html_relative2]}\1">\1</a>}) - end - dob.obj.gsub!(/<a href=":/,%{<a href="#{@vz.url_site}/}) - dob.obj.gsub!(/<a href="\.\.\//,%{<a href="#{@vz.url_site}/}) - dob.obj.gsub!(/<a href="#{Xx[:html_relative2]}\//,%{<a href="#{@vz.url_site}/}) + 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,%{<sup>©</sup>}) + if (dob.obj !~/\<:ad\s+\.\.\//) + dob.obj.gsub!(/\<:ad\s+(\S+)?\s+(\S+\.png)\s+(.+)?\;\s+(.+)?\;\s*!\>/, + %{\n<center><a href="http:\/\/\\1" target="external"><img src="#{@env.url.images_local}/\\2" alt="\\3"></a></center>\n}) else - dob.obj.gsub!(/(^|[^}])_</m,'\1<'); dob.obj.gsub!(/(^|[^}])_>/m,'\1>') #code-block: angle brackets special characters - dob.obj.gsub!(/(^|[^}])_</m,'\1<'); dob.obj.gsub!(/(^|[^}])_>/m,'\1>') + dob.obj.gsub!(/\<:ad\s+(\S+)?\s+(\S+\.png)\s+(.+)?\;\s+(.+)?\;\s*\>/, + %{\n<center><a href="\\1" target="_top"><img src="#{@env.url.images_local}/\\2" alt="\\3"></a></center>\n}) end - @tuned_file << dob + dob.obj.gsub!(/!pick/,%{<img border="0" height="15" width="15" src="#{@env.url.images}/#{@vz.icon_choice}" alt="stellar">}) + dob.obj.gsub!(/!new/,%{ <img border="0" height="15" width="15" src="#{@env.url.images}/#{@vz.icon_new}" alt="new">}) + dob.obj.gsub!(/<:h(.{1,7}?)>/,'<a href="#h\1">\1</a>') + dob.obj.gsub!(/<:to(\d{1,7}?)>/,'<a href="#to\1">to { \1 }</a> ') + dob.obj.gsub!(/#{Mx[:url_o]}_(\S+?)#{Mx[:url_c]}/,'<a href="\1" target="_top">\1</a>') #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}<a href="mailto:\\1">\\1</a>#{@brace_url.xml_close}}) + dob.obj.gsub!(/#{Mx[:url_o]}(\S+?)#{Mx[:url_c]}/,%{#{@brace_url.xml_open}<a href="\\1" target="_top">\\1</a>#{@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+)/,'<a href="\1">\1</a>') + end + if dob.obj =~/..\/\S+/ \ + and dob.obj !~/(\"..\/\S+?\"|>\s*..\/\S+<)/ + dob.obj.gsub!(/\.\.(\/\S+)/,%{<a href="#{Xx[:html_relative2]}\1">\1</a>}) + end + dob.obj.gsub!(/<a href=":/,%{<a href="#{@vz.url_site}/}) + dob.obj.gsub!(/<a href="\.\.\//,%{<a href="#{@vz.url_site}/}) + dob.obj.gsub!(/<a href="#{Xx[:html_relative2]}\//,%{<a href="#{@vz.url_site}/}) + else + dob.obj.gsub!(/(^|[^}])_</m,'\1<'); dob.obj.gsub!(/(^|[^}])_>/m,'\1>') #code-block: angle brackets special characters + dob.obj.gsub!(/(^|[^}])_</m,'\1<'); dob.obj.gsub!(/(^|[^}])_>/m,'\1>') end + dob end - def endnotes_html + def para_numbers data=@data @tuned_file=[] data.each do |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]})/, - ' <a name="-\2" href="#_\2"> <sup>\2</sup> </a> ' + #note- endnote- - '\1\2 <a name="_\2" href="#-\2"> <sup>\2.</sup></a> \3 \4') #endnote- note- (careful may have switched) - dob.obj.gsub!(/(#{Mx[:en_b_o]})([*+]\d+)\s+(.+?)(#{Mx[:en_b_c]})/, - ' <a name="-\2" href="#_\2"> <sup>\2</sup> </a> ' + #note- endnote- - '\1\2 <a name="_\2" href="#-\2"> <sup>\2.</sup></a> \3 \4') #endnote- note- (careful may have switched) - dob.obj.gsub!(/(#{Mx[:en_a_o]})([*+]+)\s+(.+?)(#{Mx[:en_a_c]})/, - ' <a name="-\2" href="#_\2"> <sup>\2</sup> </a> ' + #note- endnote- - '\1\2 <a name="_\2" href="#-\2"> <sup>\2</sup></a> \3 \4') #endnote- note- (careful may have switched) - end + dob.gsub!(/#{Mx[:lv_o]}\d:(\S?)#{Mx[:lv_c]}/,'\0<a name="H#\1">#\1.</a> ') #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]})/, + ' <a name="-\2" href="#_\2"> <sup>\2</sup> </a> ' + #note- endnote- + '\1\2 <a name="_\2" href="#-\2"> <sup>\2.</sup></a> \3 \4') #endnote- note- (careful may have switched) + dob.obj.gsub!(/(#{Mx[:en_b_o]})([*+]\d+)\s+(.+?)(#{Mx[:en_b_c]})/, + ' <a name="-\2" href="#_\2"> <sup>\2</sup> </a> ' + #note- endnote- + '\1\2 <a name="_\2" href="#-\2"> <sup>\2.</sup></a> \3 \4') #endnote- note- (careful may have switched) + dob.obj.gsub!(/(#{Mx[:en_a_o]})([*+]+)\s+(.+?)(#{Mx[:en_a_c]})/, + ' <a name="-\2" href="#_\2"> <sup>\2</sup> </a> ' + #note- endnote- + '\1\2 <a name="_\2" href="#-\2"> <sup>\2</sup></a> \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]}/,'<br />') unless dob.is=='table' + dob.obj.gsub!(/#{Mx[:fa_bold_o]}(.+?)#{Mx[:fa_bold_c]}/,'<b>\1</b>') + dob.obj.gsub!(/#{Mx[:fa_italics_o]}(.+?)#{Mx[:fa_italics_c]}/,'<i>\1</i>') + dob.obj.gsub!(/#{Mx[:fa_underscore_o]}(.+?)#{Mx[:fa_underscore_c]}/,'<u>\1</u>') + dob.obj.gsub!(/#{Mx[:fa_superscript_o]}(.+?)#{Mx[:fa_superscript_c]}/,'<sup>\1</sup>') + dob.obj.gsub!(/#{Mx[:fa_subscript_o]}(.+?)#{Mx[:fa_subscript_c]}/,'<sub>\1</sub>') + dob.obj.gsub!(/#{Mx[:fa_insert_o]}(.+?)#{Mx[:fa_insert_c]}/,'<ins>\1</ins>') + dob.obj.gsub!(/#{Mx[:fa_cite_o]}(.+?)#{Mx[:fa_cite_c]}/,'<cite>\1</cite>') + dob.obj.gsub!(/#{Mx[:fa_strike_o]}(.+?)#{Mx[:fa_strike_c]}/,'<del>\1</del>') + dob.obj.gsub!(/#{Mx[:fa_monospace_o]}(.+?)#{Mx[:fa_monospace_c]}/,'<tt>\1</tt>') # tt, kbd + dob.obj.gsub!(/#{Mx[:mk_o]}:name#(\S+?)#{Mx[:mk_c]}/,'<a name="\1"></a>') + 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=[] |