lib/softcover/builders/epub.rb in softcover-0.7.11 vs lib/softcover/builders/epub.rb in softcover-0.8.0

- old
+ new

@@ -3,11 +3,11 @@ class Epub < Builder include Softcover::Output def build!(options={}) @preview = options[:preview] - Softcover::Builders::Html.new.build!(preserve_tex: true) + Softcover::Builders::Html.new.build! if manifest.markdown? self.manifest = Softcover::BookManifest.new(source: :polytex, origin: :markdown) end remove_html @@ -30,11 +30,11 @@ end # Removes HTML. # All the HTML is generated, so this clears out any unused files. def remove_html - FileUtils.rm(Dir.glob(path('epub/OEBPS/html/*.html'))) + FileUtils.rm(Dir.glob(path('epub/OEBPS/*.html'))) end def create_directories mkdir('epub') mkdir(path('epub/OEBPS')) @@ -216,23 +216,30 @@ def create_style_files html_styles = File.join('html', 'stylesheets') epub_styles = File.join('epub', 'OEBPS', 'styles') FileUtils.cp(File.join(html_styles, 'pygments.css'), epub_styles) + File.write(File.join(epub_styles, 'softcover.css'), + clean_book_id(path("#{html_styles}/softcover.css"))) # Copy over the EPUB-specific CSS. template_dir = File.join(File.dirname(__FILE__), '..', 'template') - epub_css = File.join(template_dir, epub_styles, 'epub.css') + epub_css = File.join(template_dir, epub_styles, 'epub.css') FileUtils.cp(epub_css, epub_styles) - # For some reason, EPUB books hate the #book ids in the stylesheet - # (i.e., such books fail to validate), so remove them. - polytexnic_css = File.read(File.join(html_styles, 'softcover.css')) - polytexnic_css.gsub!(/\s*#book\s+/, '') - File.write(File.join(epub_styles, 'softcover.css'), polytexnic_css) + # Copy over custom CSS. + File.write(File.join(epub_styles, 'custom.css'), + clean_book_id(path("#{html_styles}/custom.css"))) end + # Removes the '#book' CSS id. + # For some reason, EPUB books hate the #book ids in the stylesheet + # (i.e., such books fail to validate), so remove them. + def clean_book_id(filename) + File.read(filename).gsub(/#book/, '') + end + # Copies the image files from the HTML version of the document. # We remove PDF images, which are valid in PDF documents but not in EPUB. def copy_image_files FileUtils.cp_r(File.join('html', 'images'), File.join('epub', 'OEBPS')) @@ -332,10 +339,11 @@ <item id="ncx" href="toc.ncx" media-type="application/x-dtbncx+xml"/> <item id="page-template.xpgt" href="styles/page-template.xpgt" media-type="application/vnd.adobe-page-template+xml"/> <item id="pygments.css" href="styles/pygments.css" media-type="text/css"/> <item id="softcover.css" href="styles/softcover.css" media-type="text/css"/> <item id="epub.css" href="styles/epub.css" media-type="text/css"/> + <item id="custom.css" href="styles/custom.css" media-type="text/css"/> <item id="cover" href="cover.html" media-type="application/xhtml+xml"/> #{man_ch.join("\n")} #{images.join("\n")} </manifest> <spine toc="ncx"> @@ -429,9 +437,10 @@ <head> <title>#{title}</title> <link rel="stylesheet" href="styles/pygments.css" type="text/css" /> <link rel="stylesheet" href="styles/softcover.css" type="text/css" /> <link rel="stylesheet" href="styles/epub.css" type="text/css" /> + <link rel="stylesheet" href="styles/custom.css" type="text/css"/> <link rel="stylesheet" type="application/vnd.adobe-page-template+xml" href="styles/page-template.xpgt" /> </head> <body> #{content} \ No newline at end of file