Georg Brandl avatar Georg Brandl committed cd69fd0 Merge

merge

Comments (0)

Files changed (2)

 
    Additional files that should be inserted before the text generated by
    Sphinx. It is a list of tuples containing the file name and the title.
-   Example::
+   If the title is empty, no entry is added to :file:`toc.ncx`.  Example::
 
       epub_pre_files = [
           ('index.html', 'Welcome'),
 
    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.  This option
-   can be used to add an appendix.  The default value is ``[]``.
+   can be used to add an appendix.  If the title is empty, no entry is added
+   to :file:`toc.ncx`.  The default value is ``[]``.
 
 .. confval:: epub_exclude_files
 

sphinx/builders/epub.py

 
 import os
 import re
+import time
 import codecs
 import zipfile
 from os import path
     <dc:publisher>%(publisher)s</dc:publisher>
     <dc:rights>%(copyright)s</dc:rights>
     <dc:identifier id="%(uid)s" opf:scheme="%(scheme)s">%(id)s</dc:identifier>
+    <dc:date>%(date)s</dc:date>
   </metadata>
   <manifest>
     <item id="ncx" href="toc.ncx" media-type="application/x-dtbncx+xml" />
         doctree = self.env.get_and_resolve_doctree(self.config.master_doc,
             self, prune_toctrees=False)
         self.refnodes = self.get_refnodes(doctree, [])
+        master_dir = os.path.dirname(self.config.master_doc)
+        if master_dir:
+            master_dir += '/' # XXX or os.sep?
+            for item in self.refnodes:
+                item['refuri'] = master_dir + item['refuri']
         self.refnodes.insert(0, {
             'level': 1,
             'refuri': self.esc(self.config.master_doc + '.html'),
                 'text': ssp(self.esc(text))
             })
 
-    def fix_fragment(self, match):
-        """Return a href attribute with colons replaced by hyphens.
+    def fix_fragment(self, prefix, fragment):
+        """Return a href/id attribute with colons replaced by hyphens.
         """
-        return match.group(1) + match.group(2).replace(':', '-')
+        return prefix + fragment.replace(':', '-')
 
     def fix_ids(self, tree):
         """Replace colons with hyphens in href and id attributes.
             if 'refuri' in node:
                 m = _refuri_re.match(node['refuri'])
                 if m:
-                    node['refuri'] = self.fix_fragment(m)
+                    node['refuri'] = self.fix_fragment(m.group(1), m.group(2))
             if 'refid' in node:
-                node['refid'] = node['refid'].replace(':', '-')
+                node['refid'] = self.fix_fragment('', node['refid'])
         for node in tree.traverse(addnodes.desc_signature):
             ids = node.attributes['ids']
             newids = []
             for id in ids:
-                newids.append(id.replace(':', '-'))
+                newids.append(self.fix_fragment('', id))
             node.attributes['ids'] = newids
 
     def add_visible_links(self, tree):
                 for (i, link) in enumerate(links):
                     m = _refuri_re.match(link)
                     if m:
-                        links[i] = self.fix_fragment(m)
+                        links[i] = self.fix_fragment(m.group(1), m.group(2))
                 for subentryname, subentrylinks in subitems:
                     for (i, link) in enumerate(subentrylinks):
                         m = _refuri_re.match(link)
                         if m:
-                            subentrylinks[i] = self.fix_fragment(m)
+                            subentrylinks[i] = \
+                                self.fix_fragment(m.group(1), m.group(2))
 
     def handle_page(self, pagename, addctx, templatename='page.html',
                     outfilename=None, event_arg=None):
         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'))
         metadata['files'] = files
         metadata['spine'] = spine
         return metadata
         level = 1
         lastnode = None
         for node in nodes:
+            if not node['text']:
+                continue
             file = node['refuri'].split('#')[0]
             if file in self.ignored_files:
                 continue
         epub.write(path.join(outdir, 'mimetype'), 'mimetype', \
             zipfile.ZIP_STORED)
         for file in projectfiles:
+            if isinstance(file, unicode):
+                file = file.encode('utf-8')
             epub.write(path.join(outdir, file), file, zipfile.ZIP_DEFLATED)
         epub.close()
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.