From 56406e00d5d4b50752618647efa4767812fb56b5 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 26 May 2017 00:08:46 +0530 Subject: [PATCH] Update for sphinx 1.6 --- manual/conf.py | 17 ++++++++--------- manual/docutils.conf | 2 ++ manual/epub.py | 26 +++++++++++++------------- 3 files changed, 23 insertions(+), 22 deletions(-) create mode 100644 manual/docutils.conf diff --git a/manual/conf.py b/manual/conf.py index e56bebe781..f1679b072f 100644 --- a/manual/conf.py +++ b/manual/conf.py @@ -12,6 +12,7 @@ # serve to show the default value. import sys, os +from datetime import date # If your extensions are in another directory, add it here. sys.path.append(os.path.abspath('.')) @@ -141,10 +142,6 @@ html_static_path = ['resources', '../icons/favicon.ico'] # using the given strftime format. html_last_updated_fmt = '%b %d, %Y' -# If true, SmartyPants will be used to convert quotes and dashes to -# typographically correct entities. -html_use_smartypants = True - # Overall title of the documentation # html_title = title html_short_title = _('Start') @@ -166,11 +163,13 @@ def sort_languages(x): html_context['other_languages'].sort(key=sort_languages) del sort_languages, get_language -epub_author = 'Kovid Goyal' -epub_publisher = 'Kovid Goyal' -epub_identifier = 'https://manual.calibre-ebook.com' -epub_scheme = 'url' -epub_uid = 'S54a88f8e9d42455e9c6db000e989225f' +epub_author = u'Kovid Goyal' +epub_publisher = u'Kovid Goyal' +epub_copyright = u'© {} Kovid Goyal'.format(date.today().year) +epub_description = u'Comprehensive documentation for calibre' +epub_identifier = u'https://manual.calibre-ebook.com' +epub_scheme = u'url' +epub_uid = u'S54a88f8e9d42455e9c6db000e989225f' epub_tocdepth = 4 epub_tocdup = True epub_cover = ('epub_cover.jpg', 'epub_cover_template.html') diff --git a/manual/docutils.conf b/manual/docutils.conf new file mode 100644 index 0000000000..8583cfbdd8 --- /dev/null +++ b/manual/docutils.conf @@ -0,0 +1,2 @@ +[parsers] +smart_quotes: on diff --git a/manual/epub.py b/manual/epub.py index 3692f349c7..f16652b56d 100644 --- a/manual/epub.py +++ b/manual/epub.py @@ -8,14 +8,15 @@ __docformat__ = 'restructuredtext en' import os -from sphinx.builders.epub import EpubBuilder +from sphinx.builders.epub3 import Epub3Builder as EpubBuilder -from calibre.ebooks.oeb.base import OPF, DC +from calibre.ebooks.oeb.base import OPF from calibre.ebooks.oeb.polish.container import get_container, OEB_DOCS from calibre.ebooks.oeb.polish.check.links import check_links, UnreferencedResource from calibre.ebooks.oeb.polish.pretty import pretty_html_tree, pretty_opf from calibre.utils.imghdr import identify + class EPUBHelpBuilder(EpubBuilder): name = 'myepub' @@ -62,18 +63,18 @@ class EPUBHelpBuilder(EpubBuilder): container.remove_from_xml(item) seen.add(name) - # Ensure that the meta cover tag is correct + # Remove the which is not needed in EPUB 3 + for guide in container.opf_xpath('//*[local-name()="guide"]'): + guide.getparent().remove(guide) + + # Ensure that the cover-image property is set cover_id = rmap['_static/' + self.config.epub_cover[0]] + for item in container.opf_xpath('//opf:item[@id="{}"]'.format(cover_id)): + item.set('properties', 'cover-image') + + # Remove any tag as it is not needed in epub 3 for meta in container.opf_xpath('//opf:meta[@name="cover"]'): - meta.set('content', cover_id) - - # Add description metadata - metadata = container.opf_xpath('//opf:metadata')[0] - container.insert_into_xml(metadata, metadata.makeelement(DC('description'))) - metadata[-1].text = 'Comprehensive documentation for calibre' - - # Remove search.html since it is useless in EPUB - container.remove_item('search.html') + meta.getparent().remove(meta) # Remove unreferenced files for error in check_links(container): @@ -83,4 +84,3 @@ class EPUBHelpBuilder(EpubBuilder): # Pretty print the OPF pretty_opf(container.parsed(container.opf_name)) container.dirty(container.opf_name) -