Erik Hetzner avatar Erik Hetzner committed df5c452 Merge

merge

Comments (0)

Files changed (4)

sphinx/application.py

 
     def __init__(self, srcdir, confdir, outdir, doctreedir, buildername,
                  confoverrides=None, status=sys.stdout, warning=sys.stderr,
-                 freshenv=False, warningiserror=False, tags=None, verbosity=0):
+                 freshenv=False, warningiserror=False, tags=None, verbosity=0, extra_extensions=[]):
         self.verbosity = verbosity
         self.next_listener_id = 0
         self._extensions = {}
         # load all user-given extension modules
         for extension in self.config.extensions:
             self.setup_extension(extension)
+        for extension in extra_extensions:
+            self.setup_extension(extension)
         # the config file itself can be an extension
         if self.config.setup:
             self.config.setup(self)

sphinx/builders/epub.py

 import re
 import sys
 import time
+import uuid
 import codecs
 import zipfile
 from os import path
 from sphinx.builders.html import StandaloneHTMLBuilder
 from sphinx.util.osutil import ensuredir, EEXIST
 from sphinx.util.smartypants import sphinx_smarty_pants as ssp
-from sphinx.util.console import brown
+from sphinx.util.console import bold, brown
 
 
 # (Fragment) templates from which the metainfo files content.opf, toc.ncx,
                 result = self.get_refnodes(elem, result)
         return result
 
+    def get_title(self):
+        doc_md = self.env.metadata.get(self.config.master_doc)
+        if doc_md.has_key('title'):
+            return doc_md['title']
+        else:
+            return self.env.titles[self.config.master_doc].astext()
+
     def get_toc(self):
         """Get the total table of contents, containing the master_doc
         and pre and post files not managed by sphinx.
         self.add_visible_links(doctree)
         return StandaloneHTMLBuilder.write_doc(self, docname, doctree)
 
+    def finish(self):
+        self.info(bold('writing additional files...'), nonl=1)
+
+        # pages from extensions
+        for pagelist in self.app.emit('html-collect-pages'):
+            for pagename, context, template in pagelist:
+                self.handle_page(pagename, context, template)
+
+        # the global general index
+        if self.config.html_use_index:
+            self.write_genindex()
+
+        # the global domain-specific indices
+        self.write_domain_indices()
+
+        # additional pages from conf.py
+        for pagename, template in self.config.html_additional_pages.items():
+            self.info(' '+pagename, nonl=1)
+            self.handle_page(pagename, {}, template)
+
+        if self.config.html_use_opensearch and self.name != 'htmlhelp':
+            self.info(' opensearch', nonl=1)
+            fn = path.join(self.outdir, '_static', 'opensearch.xml')
+            self.handle_page('opensearch', {}, 'opensearch.xml', outfilename=fn)
+
+        self.info()
+
+        self.copy_image_files()
+        self.copy_download_files()
+        self.copy_static_files()
+        self.write_buildinfo()
+
+        # dump the search index
+        self.handle_finish()
+
     def fix_genindex(self, tree):
         """Fix href attributes for genindex pages."""
         # XXX: modifies tree inline
         file properly escaped.
         """
         metadata = {}
-        metadata['title'] = self.esc(self.config.epub_title)
-        metadata['author'] = self.esc(self.config.epub_author)
-        metadata['uid'] = self.esc(self.config.epub_uid)
-        metadata['lang'] = self.esc(self.config.epub_language)
-        metadata['publisher'] = self.esc(self.config.epub_publisher)
-        metadata['copyright'] = self.esc(self.config.epub_copyright)
-        metadata['scheme'] = self.esc(self.config.epub_scheme)
-        metadata['id'] = self.esc(self.config.epub_identifier)
-        metadata['date'] = self.esc(time.strftime('%Y-%m-%d'))
+        doc_md = self.env.metadata.get(self.config.master_doc)
+        metadata['title'] = self.esc(self.get_title())
+        metadata['author'] = self.esc(doc_md.get('author', self.config.epub_author))
+        metadata['uid'] = self.esc(doc_md.get('uid', self.config.epub_uid))
+        metadata['lang'] = self.esc(doc_md.get('lang', self.config.epub_language))
+        metadata['publisher'] = self.esc(doc_md.get('publisher', self.config.epub_publisher))
+        metadata['copyright'] = self.esc(doc_md.get('copyright', self.config.epub_copyright))
+        metadata['scheme'] = "UUID"
+        metadata['id'] = self.esc(uuid.uuid4().hex)
+        metadata['date'] = self.esc(doc_md.get('date', time.strftime('%Y-%m-%d')))
         metadata['files'] = files
         metadata['spine'] = spine
         metadata['guide'] = guide
         """
         metadata = {}
         metadata['uid'] = self.config.epub_uid
-        metadata['title'] = self.config.epub_title
+        metadata['title'] = self.get_title()
         metadata['level'] = level
         metadata['navpoints'] = navpoints
         return metadata

sphinx/ext/htmlmath.py

+# -*- coding: utf-8 -*-
+"""
+    sphinx.ext.htmlmath
+    ~~~~~~~~~~~~~~~~~
+
+    Simple HTML math.
+
+    :copyright: Copyright 2007-2011 by the Sphinx team, see AUTHORS.
+    :license: BSD, see LICENSE for details.
+"""
+
+from docutils import nodes
+from docutils.math.math2html import math2html
+from docutils.math import unichar2tex
+
+from sphinx.application import ExtensionError
+from sphinx.ext.mathbase import setup_math as mathbase_setup
+
+def html_visit_math(self, node):
+    self.body.append(math2html(node['latex'].translate(unichar2tex.uni2tex_table)))
+    raise nodes.SkipNode
+
+def html_visit_displaymath(self, node):
+    if node.get('label'):
+        self.add_anchor(node['label'], node)
+    if node['nowrap']:
+        self.body.append(self.starttag(node, 'div', CLASS='math'))
+        self.body.append(math2html(node['latex'].translate(unichar2tex.uni2tex_table)))
+        self.body.append('</div>')
+        raise nodes.SkipNode
+    for i, part in enumerate(node['latex'].split('\n\n')):
+        part = self.encode(part)
+        if i == 0:
+            # necessary to e.g. set the id property correctly
+            if node['number']:
+                self.body.append('<span class="eqno">(%s)</span>' %
+                                 node['number'])
+            self.body.append(self.starttag(node, 'div', CLASS='math'))
+        else:
+            # but only once!
+            self.body.append('<div class="math">')
+        self.body.append(math2html(part.translate(unichar2tex.uni2tex_table)))
+        self.body.append('</div>\n')
+    raise nodes.SkipNode
+
+def setup(app):
+    mathbase_setup(app, (html_visit_math, None), (html_visit_displaymath, None))

sphinx/jinja2glue.py

 
 from sphinx.application import TemplateBridge
 from sphinx.util.osutil import mtimes_of_files
-
-
+try:
+    import typogrify.templatetags.jinja_filters
+except ImportError:
+    typogrify = None
+    
 def _tobool(val):
     if isinstance(val, basestring):
         return val.lower() in ('true', '1', 'yes', 'on')
         self.environment.globals['debug'] = contextfunction(pformat)
         self.environment.globals['accesskey'] = contextfunction(accesskey)
         self.environment.globals['idgen'] = idgen
+        if typogrify:
+            typogrify.templatetags.jinja_filters.register(self.environment)
         if use_i18n:
             self.environment.install_gettext_translations(
                 builder.app.translator)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.