aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/sisu
diff options
context:
space:
mode:
authorRalph Amissah <ralph@amissah.com>2014-02-05 01:09:02 -0500
committerRalph Amissah <ralph@amissah.com>2014-02-05 01:09:02 -0500
commitd79d6050ce31f7d8d65a87be4008e11fae368770 (patch)
tree7599c14156ab2e5a79e9d87117e2d2ff7835da61 /lib/sisu
parentv5 v6: epub, hash digests used only if available (diff)
v5 v6: html, (output) cleaning
Diffstat (limited to 'lib/sisu')
-rw-r--r--lib/sisu/v5/html.rb3
-rw-r--r--lib/sisu/v5/html_format.rb9
-rw-r--r--lib/sisu/v5/html_tune.rb13
-rw-r--r--lib/sisu/v6/html.rb3
-rw-r--r--lib/sisu/v6/html_format.rb9
-rw-r--r--lib/sisu/v6/html_tune.rb13
6 files changed, 40 insertions, 10 deletions
diff --git a/lib/sisu/v5/html.rb b/lib/sisu/v5/html.rb
index ef62b9bd..4a911d2c 100644
--- a/lib/sisu/v5/html.rb
+++ b/lib/sisu/v5/html.rb
@@ -623,7 +623,8 @@ WOK
toc_shared << format_txt_obj.center_bold
@segtoc << format_txt_obj.center_bold
if defined? @md.creator.author
- creator_endnote=@md.creator.author.gsub(/(\*+)/,
+ creator=SiSU_HTML_Tune::CleanHTML.new(@md.creator.author).clean_for_html
+ creator_endnote=creator.gsub(/(\*+)/,
%{&nbsp;<sup><a href="#notes">\\1</a></sup>})
tmp_head=creator_endnote + "\n"
txt_obj={ txt: tmp_head }
diff --git a/lib/sisu/v5/html_format.rb b/lib/sisu/v5/html_format.rb
index a933d091..e244bbb8 100644
--- a/lib/sisu/v5/html_format.rb
+++ b/lib/sisu/v5/html_format.rb
@@ -502,7 +502,8 @@ WOK
end
def rights
def all
- rights=@md.rights.all.gsub(/^\s*Copyright\s+\(C\)/,'Copyright <sup>&copy;</sup>&nbsp;')
+ rights=SiSU_HTML_Tune::CleanHTML.new(@md.rights.all).clean_for_html
+ rights=rights.gsub(/^\s*Copyright\s+\(C\)/,'Copyright <sup>&copy;</sup>&nbsp;')
%{<p class="small_left">Rights: #{rights}</p>
<p />}
end
@@ -977,7 +978,9 @@ WOK
end
def para_form_css(tag,attrib) # regular paragraphs shaped here
ul=ulc=''
- ul,ulc="<ul>\n ","\n </ul>" if @tag =~/li/
+ if tag =~/li/
+ ul,ulc="<ul>\n ","\n </ul>"
+ end
%{
<div class="substance">
#{@p_num.ocn_display}
@@ -1250,7 +1253,7 @@ WOK
note=$1
note=note.gsub(/[\s]+/m,' ')
txt=txt.gsub(/(?:#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]})\s*/m,' ').
- gsub(/<a[\n\s]+name="-\d+"[\n\s]+href="#_\d+">&nbsp;<sup>\d+<\/sup>&nbsp;/m,'')
+ gsub(/<a[\s]+name="-\d+"[\s]+href="#_\d+">&nbsp;<sup>\d+<\/sup>&nbsp;/m,'')
end
%{<#{tag} class="#{attrib}">
<a href="##{@ocn_html_identifier}#{@ocn}"><i>#{txt}</i></a> #{note}
diff --git a/lib/sisu/v5/html_tune.rb b/lib/sisu/v5/html_tune.rb
index 84336861..39cbb708 100644
--- a/lib/sisu/v5/html_tune.rb
+++ b/lib/sisu/v5/html_tune.rb
@@ -104,6 +104,16 @@ module SiSU_HTML_Tune
def initialize(html='')
@html=html
end
+ def clean_for_html
+ html=@html
+ str=if html.is_a?(String)
+ html
+ else html.obj
+ end
+ str=str.gsub(/#{Mx[:gl_o]}(#[0-9]{3})#{Mx[:gl_c]}/u,'&\1;').
+ gsub(/#{Mx[:gl_o]}#([a-z]{2,4})#{Mx[:gl_c]}/u,'&\1;').
+ gsub(/[<]/m,'&lt;').gsub(/[>]/m,'&gt;')
+ end
def clean
html=@html
str=if html.is_a?(String)
@@ -111,7 +121,8 @@ module SiSU_HTML_Tune
else html.obj
end
str=str.gsub(/#{Mx[:gl_o]}(#[0-9]{3})#{Mx[:gl_c]}/u,'&\1;').
- gsub(/#{Mx[:gl_o]}#([a-z]{2,4})#{Mx[:gl_c]}/u,'&\1;')
+ gsub(/#{Mx[:gl_o]}#([a-z]{2,4})#{Mx[:gl_c]}/u,'&\1;').
+ gsub(/[\\]{2}/m,'<br />')
end
end
class Tune
diff --git a/lib/sisu/v6/html.rb b/lib/sisu/v6/html.rb
index f1651326..8c9869e2 100644
--- a/lib/sisu/v6/html.rb
+++ b/lib/sisu/v6/html.rb
@@ -623,7 +623,8 @@ WOK
toc_shared << format_txt_obj.center_bold
@segtoc << format_txt_obj.center_bold
if defined? @md.creator.author
- creator_endnote=@md.creator.author.gsub(/(\*+)/,
+ creator=SiSU_HTML_Tune::CleanHTML.new(@md.creator.author).clean_for_html
+ creator_endnote=creator.gsub(/(\*+)/,
%{&nbsp;<sup><a href="#notes">\\1</a></sup>})
tmp_head=creator_endnote + "\n"
txt_obj={ txt: tmp_head }
diff --git a/lib/sisu/v6/html_format.rb b/lib/sisu/v6/html_format.rb
index 63271d95..de5a7144 100644
--- a/lib/sisu/v6/html_format.rb
+++ b/lib/sisu/v6/html_format.rb
@@ -502,7 +502,8 @@ WOK
end
def rights
def all
- rights=@md.rights.all.gsub(/^\s*Copyright\s+\(C\)/,'Copyright <sup>&copy;</sup>&nbsp;')
+ rights=SiSU_HTML_Tune::CleanHTML.new(@md.rights.all).clean_for_html
+ rights=rights.gsub(/^\s*Copyright\s+\(C\)/,'Copyright <sup>&copy;</sup>&nbsp;')
%{<p class="small_left">Rights: #{rights}</p>
<p />}
end
@@ -977,7 +978,9 @@ WOK
end
def para_form_css(tag,attrib) # regular paragraphs shaped here
ul=ulc=''
- ul,ulc="<ul>\n ","\n </ul>" if @tag =~/li/
+ if tag =~/li/
+ ul,ulc="<ul>\n ","\n </ul>"
+ end
%{
<div class="substance">
#{@p_num.ocn_display}
@@ -1250,7 +1253,7 @@ WOK
note=$1
note=note.gsub(/[\s]+/m,' ')
txt=txt.gsub(/(?:#{Mx[:en_a_o]}.+?#{Mx[:en_a_c]}|#{Mx[:en_b_o]}.+?#{Mx[:en_b_c]})\s*/m,' ').
- gsub(/<a[\n\s]+name="-\d+"[\n\s]+href="#_\d+">&nbsp;<sup>\d+<\/sup>&nbsp;/m,'')
+ gsub(/<a[\s]+name="-\d+"[\s]+href="#_\d+">&nbsp;<sup>\d+<\/sup>&nbsp;/m,'')
end
%{<#{tag} class="#{attrib}">
<a href="##{@ocn_html_identifier}#{@ocn}"><i>#{txt}</i></a> #{note}
diff --git a/lib/sisu/v6/html_tune.rb b/lib/sisu/v6/html_tune.rb
index 516deaa5..42568a36 100644
--- a/lib/sisu/v6/html_tune.rb
+++ b/lib/sisu/v6/html_tune.rb
@@ -104,6 +104,16 @@ module SiSU_HTML_Tune
def initialize(html='')
@html=html
end
+ def clean_for_html
+ html=@html
+ str=if html.is_a?(String)
+ html
+ else html.obj
+ end
+ str=str.gsub(/#{Mx[:gl_o]}(#[0-9]{3})#{Mx[:gl_c]}/u,'&\1;').
+ gsub(/#{Mx[:gl_o]}#([a-z]{2,4})#{Mx[:gl_c]}/u,'&\1;').
+ gsub(/[<]/m,'&lt;').gsub(/[>]/m,'&gt;')
+ end
def clean
html=@html
str=if html.is_a?(String)
@@ -111,7 +121,8 @@ module SiSU_HTML_Tune
else html.obj
end
str=str.gsub(/#{Mx[:gl_o]}(#[0-9]{3})#{Mx[:gl_c]}/u,'&\1;').
- gsub(/#{Mx[:gl_o]}#([a-z]{2,4})#{Mx[:gl_c]}/u,'&\1;')
+ gsub(/#{Mx[:gl_o]}#([a-z]{2,4})#{Mx[:gl_c]}/u,'&\1;').
+ gsub(/[\\]{2}/m,'<br />')
end
end
class Tune