From 43407189207a06ee11ce55ce80de0bbe1f72d491 Mon Sep 17 00:00:00 2001 From: Roland Meister Date: Thu, 3 Jun 2010 15:14:08 +0200 Subject: [PATCH 1/8] Remove external refuris from toc.ncx. --- sphinx/builders/epub.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sphinx/builders/epub.py b/sphinx/builders/epub.py index 9767391e0..f99012bdd 100644 --- a/sphinx/builders/epub.py +++ b/sphinx/builders/epub.py @@ -195,6 +195,10 @@ class EpubBuilder(StandaloneHTMLBuilder): # XXX: is there a better way than checking the attribute # toctree-l[1-8] on the parent node? if isinstance(doctree, nodes.reference): + refuri = doctree['refuri'] + if refuri.startswith('http://') or refuri.startswith('https://') \ + or refuri.startswith('irc:') or refuri.startswith('mailto:'): + return result classes = doctree.parent.attributes['classes'] level = 1 for l in range(8, 0, -1): # or range(1, 8)? @@ -202,7 +206,7 @@ class EpubBuilder(StandaloneHTMLBuilder): level = l result.append({ 'level': level, - 'refuri': self.esc(doctree['refuri']), + 'refuri': self.esc(refuri), 'text': self.esc(doctree.astext()) }) else: From 55e322e22585b86ea8641d939e7019369f53ec9f Mon Sep 17 00:00:00 2001 From: Roland Meister Date: Thu, 3 Jun 2010 15:32:46 +0200 Subject: [PATCH 2/8] Use smartypants for toc entries. --- sphinx/builders/epub.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/sphinx/builders/epub.py b/sphinx/builders/epub.py index f99012bdd..db6ce05ad 100644 --- a/sphinx/builders/epub.py +++ b/sphinx/builders/epub.py @@ -20,6 +20,7 @@ from docutils.transforms import Transform from sphinx.builders.html import StandaloneHTMLBuilder from sphinx.util.osutil import EEXIST +from sphinx.util.smartypants import sphinx_smarty_pants as ssp # (Fragment) templates from which the metainfo files content.opf, toc.ncx, @@ -207,7 +208,7 @@ class EpubBuilder(StandaloneHTMLBuilder): result.append({ 'level': level, 'refuri': self.esc(refuri), - 'text': self.esc(doctree.astext()) + 'text': ssp(self.esc(doctree.astext())) }) else: for elem in doctree.children: @@ -224,19 +225,20 @@ class EpubBuilder(StandaloneHTMLBuilder): self.refnodes.insert(0, { 'level': 1, 'refuri': self.esc(self.config.master_doc + '.html'), - 'text': self.esc(self.env.titles[self.config.master_doc].astext()) + 'text': ssp(self.esc( + self.env.titles[self.config.master_doc].astext())) }) for file, text in reversed(self.config.epub_pre_files): self.refnodes.insert(0, { 'level': 1, 'refuri': self.esc(file + '.html'), - 'text': self.esc(text) + 'text': ssp(self.esc(text)) }) for file, text in self.config.epub_post_files: self.refnodes.append({ 'level': 1, 'refuri': self.esc(file + '.html'), - 'text': self.esc(text) + 'text': ssp(self.esc(text)) }) From ef63485c6e6813b4cfd9ef74856c17b07919326c Mon Sep 17 00:00:00 2001 From: Roland Meister Date: Thu, 3 Jun 2010 15:39:24 +0200 Subject: [PATCH 3/8] Added one more epub_exclude_file. --- doc/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/conf.py b/doc/conf.py index b268a13f0..e102c155d 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -36,7 +36,7 @@ epub_scheme = 'url' epub_identifier = epub_publisher epub_pre_files = [('index', 'Welcome')] epub_exclude_files = ['_static/opensearch.xml', '_static/doctools.js', - '_static/jquery.js', '_static/searchtools.js', + '_static/jquery.js', '_static/searchtools.js', '_static/underscore.js', '_static/basic.css', 'search.html'] latex_documents = [('contents', 'sphinx.tex', 'Sphinx Documentation', From 87c3052bb4045fd9302ee469ccc09b818e3e7abd Mon Sep 17 00:00:00 2001 From: Roland Meister Date: Thu, 3 Jun 2010 15:57:38 +0200 Subject: [PATCH 4/8] Added note for large floating divs to the documentation. --- doc/faq.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/doc/faq.rst b/doc/faq.rst index 613283c5d..ff08c486d 100644 --- a/doc/faq.rst +++ b/doc/faq.rst @@ -134,6 +134,12 @@ some notes: and Bookworm_. For bookworm you can download the source from http://code.google.com/p/threepress/ and run your own local server. +* Large floating divs are not displayed properly. + If they cover more than one page, the div is only shown on the first page. + In that case you can copy the :file:`epub.css` from the + ``sphinx/themes/epub/static/`` directory to your local ``_static/`` + directory and remove the float settings. + .. _Epubcheck: http://code.google.com/p/epubcheck/ .. _Calibre: http://calibre-ebook.com/ .. _FBreader: http://www.fbreader.org/ From d54377153a8d2942dc9a9baf171dd8f5c40f2ff4 Mon Sep 17 00:00:00 2001 From: Roland Meister Date: Mon, 7 Jun 2010 22:27:13 +0200 Subject: [PATCH 5/8] Only add refnodes with a class of 'toctree-l%d' to the toc.ncx file --- doc/config.rst | 4 ++-- doc/faq.rst | 4 ++++ sphinx/builders/epub.py | 17 ++++++++--------- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/doc/config.rst b/doc/config.rst index d968ce551..e9c98f1c2 100644 --- a/doc/config.rst +++ b/doc/config.rst @@ -766,8 +766,8 @@ the `Dublin Core metadata `_. .. confval:: epub_post_files Additional files that should be inserted after the text generated by Sphinx. - It is a list of tuples containing the file name and the title. The default - value is ``[]``. + It is a list of tuples containing the file name and the title. This option + can be used to add an appendix. The default value is ``[]``. .. confval:: epub_exclude_files diff --git a/doc/faq.rst b/doc/faq.rst index ff08c486d..5869e3af8 100644 --- a/doc/faq.rst +++ b/doc/faq.rst @@ -140,6 +140,10 @@ some notes: ``sphinx/themes/epub/static/`` directory to your local ``_static/`` directory and remove the float settings. +* Files that are inserted outside of the ``toctree`` directive must be manually + included. This sometimes applies to appendixes, e.g. the glossary or + the indices. You can add them with the :confval:`epub_post_files` option. + .. _Epubcheck: http://code.google.com/p/epubcheck/ .. _Calibre: http://calibre-ebook.com/ .. _FBreader: http://www.fbreader.org/ diff --git a/sphinx/builders/epub.py b/sphinx/builders/epub.py index db6ce05ad..47984be6b 100644 --- a/sphinx/builders/epub.py +++ b/sphinx/builders/epub.py @@ -201,15 +201,14 @@ class EpubBuilder(StandaloneHTMLBuilder): or refuri.startswith('irc:') or refuri.startswith('mailto:'): return result classes = doctree.parent.attributes['classes'] - level = 1 - for l in range(8, 0, -1): # or range(1, 8)? - if (_toctree_template % l) in classes: - level = l - result.append({ - 'level': level, - 'refuri': self.esc(refuri), - 'text': ssp(self.esc(doctree.astext())) - }) + for level in range(8, 0, -1): # or range(1, 8)? + if (_toctree_template % level) in classes: + result.append({ + 'level': level, + 'refuri': self.esc(refuri), + 'text': ssp(self.esc(doctree.astext())) + }) + break else: for elem in doctree.children: result = self.get_refnodes(elem, result) From 13adb67063b12d4960f368e5247ae3423c22654a Mon Sep 17 00:00:00 2001 From: Roland Meister Date: Mon, 7 Jun 2010 22:28:48 +0200 Subject: [PATCH 6/8] Correct handling of extensions for extra files --- doc/conf.py | 2 +- sphinx/builders/epub.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/conf.py b/doc/conf.py index e102c155d..299f321ac 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -34,7 +34,7 @@ epub_author = 'Georg Brandl' epub_publisher = 'http://sphinx.pocoo.org/' epub_scheme = 'url' epub_identifier = epub_publisher -epub_pre_files = [('index', 'Welcome')] +epub_pre_files = [('index.html', 'Welcome')] epub_exclude_files = ['_static/opensearch.xml', '_static/doctools.js', '_static/jquery.js', '_static/searchtools.js', '_static/underscore.js', '_static/basic.css', 'search.html'] diff --git a/sphinx/builders/epub.py b/sphinx/builders/epub.py index 47984be6b..fdfab7190 100644 --- a/sphinx/builders/epub.py +++ b/sphinx/builders/epub.py @@ -230,13 +230,13 @@ class EpubBuilder(StandaloneHTMLBuilder): for file, text in reversed(self.config.epub_pre_files): self.refnodes.insert(0, { 'level': 1, - 'refuri': self.esc(file + '.html'), + 'refuri': self.esc(file), 'text': ssp(self.esc(text)) }) for file, text in self.config.epub_post_files: self.refnodes.append({ 'level': 1, - 'refuri': self.esc(file + '.html'), + 'refuri': self.esc(file), 'text': ssp(self.esc(text)) }) From eb86c504b3a807e79badd2239297b44016b911f2 Mon Sep 17 00:00:00 2001 From: Roland Meister Date: Mon, 7 Jun 2010 22:37:01 +0200 Subject: [PATCH 7/8] Disable VisibleLinksTransform because it may leak into the HTML generation. --- sphinx/builders/epub.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/sphinx/builders/epub.py b/sphinx/builders/epub.py index fdfab7190..74c328ea7 100644 --- a/sphinx/builders/epub.py +++ b/sphinx/builders/epub.py @@ -125,7 +125,7 @@ _media_types = { class VisibleLinksTransform(Transform): """ - Add the link target of referances to the text, unless it is already + Add the link target of references to the text, unless it is already present in the description. """ @@ -171,7 +171,10 @@ class EpubBuilder(StandaloneHTMLBuilder): # the output files for epub must be .html only self.out_suffix = '.html' self.playorder = 0 - self.app.add_transform(VisibleLinksTransform) + # Disable transform until the issue with cached doctrees is solved. + # Building the html file after the epub file shows the + # visible links also in the HTML output. + #self.app.add_transform(VisibleLinksTransform) def get_theme_config(self): return self.config.epub_theme, {} From b2a237b8b4e613904965295129621d621cf28ecc Mon Sep 17 00:00:00 2001 From: Roland Meister Date: Wed, 30 Jun 2010 21:32:18 +0200 Subject: [PATCH 8/8] Omit nodes without refuri attribute from toc.ncx. This fixes bug report on sphinx-dev. --- sphinx/builders/epub.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sphinx/builders/epub.py b/sphinx/builders/epub.py index 74c328ea7..a5f7a84d0 100644 --- a/sphinx/builders/epub.py +++ b/sphinx/builders/epub.py @@ -198,7 +198,7 @@ class EpubBuilder(StandaloneHTMLBuilder): """Collect section titles, their depth in the toc and the refuri.""" # XXX: is there a better way than checking the attribute # toctree-l[1-8] on the parent node? - if isinstance(doctree, nodes.reference): + if isinstance(doctree, nodes.reference) and hasattr(doctree, 'refuri'): refuri = doctree['refuri'] if refuri.startswith('http://') or refuri.startswith('https://') \ or refuri.startswith('irc:') or refuri.startswith('mailto:'):