From 9b67ec9247d8322ede2bb47405862fd0ce6de375 Mon Sep 17 00:00:00 2001
From: Ralph Amissah <ralph@amissah.com>
Date: Wed, 20 Feb 2013 19:18:56 -0500
Subject: v4 (v3): epub, tinkering with headers & cleaning of angle brackets
 '<' & '>'

---
 lib/sisu/v3/epub_tune.rb   |  8 +++++---
 lib/sisu/v4/epub_format.rb | 22 ++++++++++++----------
 lib/sisu/v4/epub_tune.rb   |  9 ++++++---
 3 files changed, 23 insertions(+), 16 deletions(-)

(limited to 'lib')

diff --git a/lib/sisu/v3/epub_tune.rb b/lib/sisu/v3/epub_tune.rb
index a6b23a0d..664f143e 100644
--- a/lib/sisu/v3/epub_tune.rb
+++ b/lib/sisu/v3/epub_tune.rb
@@ -123,7 +123,7 @@ module SiSU_EPUB_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=SiSU_EPUB_Tune::Tune.new(@data,@md).amp_html
+        data=SiSU_EPUB_Tune::Tune.new(@data,@md).amp_angle_brackets
         data=SiSU_EPUB_Tune::Tune.new(data,@md).endnotes_html
         data=SiSU_EPUB_Tune::Tune.new(data,@md).url_markup
         data=SiSU_EPUB_Tune::Tune.new(data,@md).markup
@@ -274,10 +274,12 @@ module SiSU_EPUB_Tune
         @tuned_file << dob
       end
     end
-    def amp_html
+    def amp_angle_brackets
       data,data_new=@data,[]
       data.each do |dob|
-        dob.obj=dob.obj.gsub(/&/u,'&amp;')
+        dob.obj=dob.obj.
+          gsub(/&/u,'&amp;').
+          gsub(/</u,'&lt;').gsub(/>/u,'&gt;')
         data_new << dob
       end
       data_new
diff --git a/lib/sisu/v4/epub_format.rb b/lib/sisu/v4/epub_format.rb
index a56ea394..98f4d7e4 100644
--- a/lib/sisu/v4/epub_format.rb
+++ b/lib/sisu/v4/epub_format.rb
@@ -71,23 +71,21 @@ module SiSU_EPUB_Format
       if make.build.ocn?
         ocn_class='ocn'
         if @ocn.to_i==0
-          @ocn.gsub(/^(\d+|)$/,
-            %{<label class="#{ocn_class}">#{$ep[:hsp]}</label>})
+          @ocn.gsub(/^(\d+|)$/,'')
         else
           @ocn.gsub(/^(\d+|)$/,
             %{<label class="#{ocn_class}"><a href="#o\\1" class="lnk#{ocn_class}">\\1</a></label>})
         end
       else
         ocn_class='ocn_off'
-        @ocn.gsub(/^(\d+|)$/,
-          %{<label class="#{ocn_class}">#{$ep[:hsp]}</label>})
+        @ocn.gsub(/^(\d+|)$/,'')
       end
     end
     def name
       %{<a name="#{@ocn}"></a>}
     end
     def id #w3c? "tidy" complains about numbers as identifiers ! annoying
-      %{id="o#{@ocn}"}
+      (@ocn.empty?) ? '' : %{id="o#{@ocn}"}
     end
     def goto
       %{<a href="##{@ocn}">}
@@ -1225,7 +1223,8 @@ module SiSU_EPUB_Format
       if x.is_a?(String)
         x=x.gsub(/&nbsp;/,' ') if Ep[:alt]==:on
         x.gsub(/&/,'&amp;').
-          gsub(/</,'&lt;').gsub(/>/,'&gt;').
+          gsub(/</,"&lt;").gsub(/>/,"&gt;").
+          gsub(/#{Dx[:url_o]}/,Dx[:url_o_xml]).gsub(/#{Dx[:url_c]}/,Dx[:url_o_xml]).
           #gsub(/</,'&#60;').gsub(/>/,'&#62;').
           gsub(/\\\\/,'<br />').
           gsub(/&lt;br(?: \/)?&gt;/,'<br />')
@@ -1243,9 +1242,8 @@ module SiSU_EPUB_Format
       @css=SiSU_Env::CSS_Stylesheet.new(md)
       @seg_name_xhtml=(SiSU_EPUB::Source::Seg.new.seg_name_xhtml || [])
       @seg_name_xhtml_tracker=(SiSU_EPUB::Source::Seg.new.seg_name_xhtml_tracker || [])
-      @index='index'
-      @metalink='#metadata'
       @tocband_scroll,@tocband_segtoc=nil,nil
+      @index,@metalink='index','#metadata'
     end
     def doc_type_xhtml
       <<-WOK
@@ -1572,17 +1570,21 @@ output_epub_cont_seg.close
         rights=if defined? @md.rights.all \
         and @md.rights.all =~/\S+/
           rights=SanitizeXML.xml(@md.rights.all)
+          rights=rights.gsub(/<br\s*\/?>/,' ')
           %{\n    <dc:rights>#{rights}</dc:rights>}
         else ''
         end
         f=SiSU_Env::FileOp.new(@md)
         <<-WOK
-  <#{$ep[:o]}metadata xmlns:dc="http://purl.org/dc/elements/1.1/"
+  <#{$ep[:o]}metadata
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns:opf="http://www.idpf.org/2007/opf"
+    xmlns:dcterms="http://purl.org/dc/terms/"
+    xmlns:dc="http://purl.org/dc/elements/1.1/"
     unique-identifier="urn:uuid:#{@md.dgst[1]}" version="2.0">
     <dc:title>#{@md.title.full}</dc:title>
     #{cover_image}#{author}#{editor}#{translator}#{illustrator}#{language}#{date_published}#{subject}#{rights}
-    <dc:identifier opf:scheme="URI">#{f.output_path.epub.url}/#{f.base_filename.epub}</dc:identifier>
+    <dc:identifier opf:scheme="URI">#{f.output_path.epub.url.gsub(/http:\/\//,'')}/#{f.base_filename.epub}</dc:identifier>
     <dc:identifier id="bookid">urn:uuid:#{@md.dgst[1]}</dc:identifier>
     <!-- <dc:identifier id="EPB-UUID">urn:uuid:#{@md.dgst[1]}</dc:identifier> -->
   </#{$ep[:o]}metadata>
diff --git a/lib/sisu/v4/epub_tune.rb b/lib/sisu/v4/epub_tune.rb
index bce4aed7..fbb42bc4 100644
--- a/lib/sisu/v4/epub_tune.rb
+++ b/lib/sisu/v4/epub_tune.rb
@@ -123,7 +123,7 @@ module SiSU_EPUB_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=SiSU_EPUB_Tune::Tune.new(@data,@md).amp_html
+        data=SiSU_EPUB_Tune::Tune.new(@data,@md).amp_angle_brackets
         data=SiSU_EPUB_Tune::Tune.new(data,@md).endnotes_html
         data=SiSU_EPUB_Tune::Tune.new(data,@md).url_markup
         data=SiSU_EPUB_Tune::Tune.new(data,@md).markup
@@ -156,6 +156,7 @@ module SiSU_EPUB_Tune
           gsub(/#{Mx[:fa_monospace_o]}(.+?)#{Mx[:fa_monospace_c]}/,'<tt>\1</tt>'). # tt, kbd
           gsub(/#{Mx[:mk_o]}:name#(\S+?)#{Mx[:mk_c]}/,'').
           gsub(/#{Mx[:gl_bullet]}/m,"●#{$ep[:hsp]*2}").
+          gsub(/#{Dx[:url_o]}/,Dx[:url_o_xml]).gsub(/#{Dx[:url_c]}/,Dx[:url_o_xml]).
           gsub(/#{Mx[:nbsp]}/,$ep[:hsp]).
           gsub(/<(p|br)>/,'<\1 />')
         dob.obj=SiSU_EPUB_Tune::CleanXHTML.new(dob.obj).clean
@@ -274,10 +275,12 @@ module SiSU_EPUB_Tune
         @tuned_file << dob
       end
     end
-    def amp_html
+    def amp_angle_brackets
       data,data_new=@data,[]
       data.each do |dob|
-        dob.obj=dob.obj.gsub(/&/u,'&amp;')
+        dob.obj=dob.obj.
+          gsub(/&/u,'&amp;').
+          gsub(/</u,'&lt;').gsub(/>/u,'&gt;')
         data_new << dob
       end
       data_new
-- 
cgit v1.2.3