aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/sisu/v4/epub_format.rb
diff options
context:
space:
mode:
authorRalph Amissah <ralph@amissah.com>2013-01-31 18:36:08 -0500
committerRalph Amissah <ralph@amissah.com>2013-01-31 18:36:08 -0500
commit8fe365726f3bb7866a7a9285cb5045c50c39fd67 (patch)
tree29ed9813072aeb435d8b548fe3d24c810689bc93 /lib/sisu/v4/epub_format.rb
parentv4 v3: dal, on ocn excluded paragraphs (~# -#), hang/indent bullet, fix (diff)
v4: epub, constants, debug alternative for various readers ... work on
Diffstat (limited to 'lib/sisu/v4/epub_format.rb')
-rw-r--r--lib/sisu/v4/epub_format.rb137
1 files changed, 67 insertions, 70 deletions
diff --git a/lib/sisu/v4/epub_format.rb b/lib/sisu/v4/epub_format.rb
index dd3273d0..d8baae63 100644
--- a/lib/sisu/v4/epub_format.rb
+++ b/lib/sisu/v4/epub_format.rb
@@ -69,7 +69,7 @@ module SiSU_EPUB_Format
ocn_class='ocn'
if @ocn.to_i==0
@ocn.gsub(/^(\d+|)$/,
- %{<label class="#{ocn_class}">&nbsp;</label>})
+ %{<label class="#{ocn_class}">#{$ep[:hsp]}</label>})
else
@ocn.gsub(/^(\d+|)$/,
%{<label class="#{ocn_class}"><a href="#o\\1" class="lnk#{ocn_class}">\\1</a></label>})
@@ -77,7 +77,7 @@ module SiSU_EPUB_Format
else
ocn_class='ocn_off'
@ocn.gsub(/^(\d+|)$/,
- %{<label class="#{ocn_class}">&nbsp;</label>})
+ %{<label class="#{ocn_class}">#{$ep[:hsp]}</label>})
end
end
def name
@@ -1220,6 +1220,7 @@ module SiSU_EPUB_Format
module SanitizeXML
def self.xml(x)
if x.is_a?(String)
+ x=x.gsub(/&nbsp;/,' ') if Ep[:alt]==:on
x.gsub(/&/,'&amp;').
gsub(/</,'&lt;').gsub(/>/,'&gt;').
#gsub(/</,'&#60;').gsub(/>/,'&#62;').
@@ -1246,8 +1247,6 @@ module SiSU_EPUB_Format
def doc_type_xhtml
<<-WOK
<?xml version='1.0' encoding='utf-8'?>
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
- "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
WOK
end
@@ -1305,25 +1304,25 @@ application/epub+zip
segfilename=dir_epub_cont + '/' + name
output_epub_cont_seg=File.new(segfilename,'w')
output_epub_cont_seg << %{#{doc_type}
-<head>
- <title>
- #{dob.obj} -
- #{@md.html_title}
- </title>
-<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
-#{@css.xhtml_epub}
-</head>
-#{@vz.color_body}
-<div class="content">
- <div class="substance">
- <label class="ocn"><a href="#o#{dob.ocn}" class="lnkocn">#{dob.ocn}</a></label>
- <h1 class="norm" id="o#{dob.ocn}">
- #{dob.obj}
- </h1>
- </div>
-</div>
-</body>
-</html>}
+ <head>
+ <title>
+ #{dob.obj} -
+ #{@md.html_title}
+ </title>
+ <meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
+ #{@css.xhtml_epub}
+ </head>
+ #{@vz.color_body}
+ <div class="content">
+ <div class="substance">
+ <label class="ocn"><a href="#o#{dob.ocn}" class="lnkocn">#{dob.ocn}</a></label>
+ <h1 class="norm" id="o#{dob.ocn}">
+ #{dob.obj}
+ </h1>
+ </div>
+ </div>
+ </body>
+ </html>}
output_epub_cont_seg.close
end
def toc_ncx #list of navigation points (like chapters), table of contents, listing each navigation point (chapters and such) under the navigation map
@@ -1341,9 +1340,7 @@ output_epub_cont_seg.close
end
def open
<<-WOK
-<?xml version="1.0"?>
-<!DOCTYPE ncx PUBLIC "-//NISO//DTD ncx 2005-1//EN"
- "http://www.daisy.org/z3986/2005/ncx-2005-1.dtd">
+<?xml version='1.0' encoding='utf-8'?>
<ncx xmlns="http://www.daisy.org/z3986/2005/ncx/" version="2005-1">
WOK
end
@@ -1404,12 +1401,12 @@ output_epub_cont_seg.close
? ''
: "-#{no}"
<<-WOK
- <navPoint id="navpoint#{id_u}" playOrder="#{no}">
- <navLabel>
- <text>Table of Contents</text>
- </navLabel>
- <content src="index#{Sfx[:epub_xhtml]}" />
- </navPoint>
+ <navPoint id="navpoint#{id_u}" playOrder="#{no}">
+ <navLabel>
+ <text>Table of Contents</text>
+ </navLabel>
+ <content src="index#{Sfx[:epub_xhtml]}" />
+ </navPoint>
WOK
end
def navpoint(dob,no,fn_base,hashtag=nil)
@@ -1419,16 +1416,16 @@ output_epub_cont_seg.close
? ''
: "-#{no}"
<<-WOK
- <navPoint id="navpoint#{id_u}" playOrder="#{no}">
- <navLabel>
- <text>#{dob.obj}</text>
- </navLabel>
- <content src="#{name}" />
+ <navPoint class="chapter" id="navpoint#{id_u}" playOrder="#{no}">
+ <navLabel>
+ <text>#{dob.obj}</text>
+ </navLabel>
+ <content src="#{name}" />
WOK
end
def navpoint_close
<<-WOK
- </navPoint>
+ </navPoint>
WOK
end
def navmap_close
@@ -1454,7 +1451,7 @@ output_epub_cont_seg.close
def package_open
<<-WOK
<?xml version='1.0' encoding='utf-8'?>
-<package xmlns="http://www.idpf.org/2007/opf" unique-identifier="EPB-UUID" version="2.0">
+<package xmlns="http://www.idpf.org/2007/opf" version="2.0" unique-identifier="EPB-UUID">
WOK
end
def package_close
@@ -1466,7 +1463,7 @@ output_epub_cont_seg.close
cover_image=if defined? @md.make.cover_image \
and @md.make.cover_image.is_a?(Hash) \
and @md.make.cover_image[:cover] =~/\S+/
- %{\n <meta name="cover" content="cover_image" />}
+ %{\n <#{$ep[:o]}meta name="cover" content="cover_image" />}
else ''
end
author=if defined? @md.creator.author \
@@ -1577,7 +1574,7 @@ output_epub_cont_seg.close
end
f=SiSU_Env::FileOp.new(@md)
<<-WOK
- <metadata xmlns:dc="http://purl.org/dc/elements/1.1/"
+ <#{$ep[:o]}metadata xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:opf="http://www.idpf.org/2007/opf"
unique-identifier="urn:uuid:#{@md.dgst[1]}" version="2.0">
<dc:title>#{@md.title.full}</dc:title>
@@ -1585,7 +1582,7 @@ output_epub_cont_seg.close
<dc:identifier opf:scheme="URI">#{f.output_path.epub.url}/#{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> -->
- </metadata>
+ </#{$ep[:o]}metadata>
WOK
end
def manifest_open
@@ -1608,7 +1605,7 @@ output_epub_cont_seg.close
and @md.make.cover_image.is_a?(Hash) \
and md.make.cover_image[:cover] =~/\S+/
<<-WOK
- <item id="cover_image_file" href="cover_image#{Sfx[:epub_xhtml]}" media-type="application/xhtml+xml" />
+ <item id="cover_image#{Sfx[:epub_xhtml]}" href="cover_image#{Sfx[:epub_xhtml]}" media-type="application/xhtml+xml" />
WOK
else ''
end
@@ -1646,7 +1643,7 @@ output_epub_cont_seg.close
end
def spine_cover_image
<<-WOK
- <itemref idref="cover_image_file" />
+ <itemref idref="cover_image#{Sfx[:epub_xhtml]}" />
WOK
end
def spine_sisu_toc
@@ -1674,7 +1671,7 @@ output_epub_cont_seg.close
end
def guide_cover_image
<<-WOK
- <reference type="cover" title="Cover of [book title]" href="cover_image#{Sfx[:epub_xhtml]}" />
+ <reference type="cover" title="Cover of #{SanitizeXML.xml(@md.title.full)}" href="cover_image#{Sfx[:epub_xhtml]}" />
WOK
end
def guide_sisu_toc
@@ -1727,20 +1724,20 @@ output_epub_cont_seg.close
end
def head
%{#{doc_type}
-<head>
-<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
-#{@css.xhtml_epub}
-</head>
-#{@vz.color_body}}
+ <head>
+ <meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
+ #{@css.xhtml_epub}
+ </head>
+ #{@vz.color_body}}
end
def concordance
if @md.concord_make
%{#{@vz.margin_css}
- <h4 class="toc">
- <a href="./#{@md.file.base_filename.html_concordance}">
- <i>Concordance</i>
- </a>
- </h4>
+ <h4 class="toc">
+ <a href="./#{@md.file.base_filename.html_concordance}">
+ <i>Concordance</i>
+ </a>
+ </h4>
#{@vz.table_close}}
else
%{#{@vz.margin_css}
@@ -1807,15 +1804,15 @@ output_epub_cont_seg.close
end
def head
%{#{doc_type}
-<head>
- <title>
- #{@seg_name_xhtml[@seg_name_xhtml_tracker]} -
- #{@md.html_title}
- </title>
-<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
-#{@css.xhtml_epub}
-</head>
-#{@vz.color_body}}
+ <head>
+ <title>
+ #{@seg_name_xhtml[@seg_name_xhtml_tracker]} -
+ #{@md.html_title}
+ </title>
+ <meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
+ #{@css.xhtml_epub}
+ </head>
+ #{@vz.color_body}}
end
def endnote_mark
%{
@@ -1833,7 +1830,7 @@ output_epub_cont_seg.close
<a href="#owner.details">
Owner Details
<font size="1" color="#777777">
- &nbsp;&nbsp;&nbsp;
+ #{$ep[:hsp]*3}
</font>
</a>
</font>
@@ -1914,7 +1911,7 @@ output_epub_cont_seg.close
def no_paranum
%{
<div class="substance">
- <label class="ocn">&nbsp;</label>
+ <label class="ocn">#{$ep[:hsp]}</label>
<p class="norm">
#{@txt}
</p>
@@ -2059,7 +2056,7 @@ output_epub_cont_seg.close
#{@txt}
</p>
#{@vz.margin_num_css}
- &nbsp;&nbsp;&nbsp;
+ #{$ep[:hsp]*3}
#{@vz.table_close}}
end
def bold_heading #unused
@@ -2069,7 +2066,7 @@ output_epub_cont_seg.close
#{@txt}
</p>
#{@vz.margin_num_css}
- &nbsp;&nbsp;&nbsp;
+ #{$ep[:hsp]*3}
#{@vz.table_close}}
end
def toc_head_copy_at
@@ -2123,8 +2120,8 @@ output_epub_cont_seg.close
note=$1
note=note.gsub(/[\n\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]+"[\n\s]+href="#note_ref\d+">&nbsp;<sup id="note\d+">\d+<\/sup>&nbsp;/m,'').
- gsub(/<a[\n\s]+"[\n\s]+href="#note_ref\d+">#{Mx[:nbsp]}<sup id="note\d+">\d+<\/sup>#{Mx[:nbsp]}/m,'') #remove
+ gsub(/<a[\n\s]+"[\n\s]+href="#note_ref\d+">#{$ep[:hsp]}<sup id="note\d+">\d+<\/sup>#{$ep[:hsp]}/m,'').
+ gsub(/<a[\n\s]+"[\n\s]+href="#note_ref\d+">#{$ep[:hsp]}<sup id="note\d+">\d+<\/sup>#{$ep[:hsp]}/m,'') #remove
end
%{<#{tag} class="#{attrib}">
<a href="#o#{@ocn}"><i>#{txt}</i></a> #{note}