lyhcode avatar lyhcode committed df09b67

add mobi support (refer https://bitbucket.org/charlax/sphinx/)

Comments (0)

Files changed (7)

sphinx/builders/__init__.py

     'devhelp':    ('devhelp', 'DevhelpBuilder'),
     'qthelp':     ('qthelp', 'QtHelpBuilder'),
     'epub':       ('epub', 'EpubBuilder'),
+    'mobi':       ('mobi', 'MobiBuilder'),
     'latex':      ('latex', 'LaTeXBuilder'),
     'text':       ('text', 'TextBuilder'),
     'man':        ('manpage', 'ManualPageBuilder'),

sphinx/builders/epub.py

         metadata['spine'] = spine
         return metadata
 
-    def build_content(self, outdir, outname):
+    def build_content(self, outdir, outname, content_template=None):
         """Write the metainfo file content.opf It contains bibliographic data,
         a file list and the spine (the reading order).
         """
                 'idref': self.esc(self.make_id('genindex' + self.out_suffix))
             })
 
+        if content_template:
+            content_tmpl = content_template
+        else:
+            content_tmpl = _content_template
+
         # add the optional cover
-        content_tmpl = _content_template
+        #content_tmpl = _content_template
         if self.config.epub_cover:
             image, tmpl = self.config.epub_cover
             mpos = content_tmpl.rfind('</metadata>')

sphinx/builders/mobi.py

+# -*- coding: utf-8 -*-
+"""
+    sphinx.builders.mobi
+    ~~~~~~~~~~~~~~~~~~~~
+
+    Build epub files.
+    Originally derived from epub.py.
+
+    :copyright: Copyright 2007-2011 by the Sphinx team, see AUTHORS.
+    :license: BSD, see LICENSE for details.
+"""
+
+import os
+
+from sphinx.builders.epub import EpubBuilder
+
+_content_template = u'''\
+<?xml version="1.0" encoding="UTF-8"?>
+<package xmlns="http://www.idpf.org/2007/opf" version="2.0"
+      unique-identifier="%(uid)s">
+  <metadata xmlns:opf="http://www.idpf.org/2007/opf"
+        xmlns:dc="http://purl.org/dc/elements/1.1/">
+    <dc:language>%(lang)s</dc:language>
+    <dc:title>%(title)s</dc:title>
+    <dc:creator opf:role="aut">%(author)s</dc:creator>
+    <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" />
+%(files)s
+  </manifest>
+  <spine toc="ncx">
+%(spine)s
+  </spine>
+  <guide>
+    <reference type="toc" title="Table of Contents" href="contents.html" />
+    <reference type="text" title="Overview" href="index.html" />
+  </guide>
+</package>
+'''
+
+_mimetype_template = 'application/x-mobipocket-ebook'
+
+class MobiBuilder(EpubBuilder):
+    """
+    Builder that outputs mobi files.
+
+    It creates the metainfo files container.opf, toc.ncx, mimetype, and
+    META-INF/container.xml.  Afterwards, the kindlegen utility is used
+    to generate the mobi file.
+    """
+    name = 'mobi'
+    
+    def init(self):
+        EpubBuilder.init(self)
+    
+    # Finish by building the mobi file
+    def handle_finish(self):
+        """Create the metainfo files and finally the mobi."""
+        EpubBuilder.handle_finish(self)
+        os.system("kindlegen -c1 -rebuild -verbose %s" % os.path.join(self.outdir, 
+            self.config.epub_basename + '.epub'))
+    
+    def get_theme_config(self):
+        return self.config.mobi_theme, {}
+    
+    def build_content(self, outdir, outname):
+        """Write the metainfo file content.opf It contains bibliographic data,
+        a file list, the spine (the reading order) and the guide (first page
+        and html version of the toc).
+        """
+        
+        EpubBuilder.build_content(self, outdir, outname,
+            content_template=_content_template)
         epub_tocdepth = (3, 'env'),
         epub_tocdup = (True, 'env'),
 
+        # Mobi options
+        mobi_theme = ('mobi', 'html'),
+
         # LaTeX options
         latex_documents = ([], None),
         latex_logo = (None, None),

sphinx/themes/mobi/layout.html

+{#
+    mobi/layout.html
+    ~~~~~~~~~~~~~~~~
+
+    Sphinx layout template for the mobi theme.
+
+    :copyright: Copyright 2007-2011 by the Sphinx team, see AUTHORS.
+    :license: BSD, see LICENSE for details.
+#}
+{% extends "basic/layout.html" %}
+
+{# add only basic navigation links #}
+{% block sidebar1 %}{% endblock %}
+{% block sidebar2 %}{% endblock %}
+{% block relbar1 %}{% endblock %}
+{% block relbar2 %}{% endblock %}
+{% block linktags %}{% endblock %}

sphinx/themes/mobi/static/mobi.css

+/*
+ * mobi.css_t
+ * ~~~~~~~~~~
+ *
+ * Sphinx stylesheet -- mobi theme.
+ *
+ * :copyright: Copyright 2007-2011 by the Sphinx team, see AUTHORS.
+ * :license: BSD, see LICENSE for details.
+ *
+ */
+
+/* -- main layout ----------------------------------------------------------- */
+
+div.clearer {
+    clear: both;
+}
+
+a:link, a:visited {
+    color: #3333ff;
+    text-decoration: underline;
+}
+
+img {
+    border: 0;
+}
+
+/* -- relbar ---------------------------------------------------------------- */
+
+div.related {
+    width: 100%;
+    font-family: sans-serif;
+    font-size: 90%;
+}
+
+div.related h3 {
+    display: none;
+}
+
+div.related ul {
+    margin: 0;
+    padding: 0 0 0 10px;
+    list-style: none;
+}
+
+div.related li {
+    display: inline;
+}
+
+div.related li.right {
+    float: right;
+    margin-right: 5px;
+}
+
+/* -- sidebar --------------------------------------------------------------- */
+
+div.sphinxsidebarwrapper {
+    padding: 10px 5px 0 10px;
+}
+
+div.sphinxsidebar {
+    float: left;
+    width: 230px;
+    margin-left: -100%;
+    font-size: 90%;
+}
+
+div.sphinxsidebar ul {
+    list-style: none;
+}
+
+div.sphinxsidebar ul ul,
+div.sphinxsidebar ul.want-points {
+    margin-left: 20px;
+    list-style: square;
+}
+
+div.sphinxsidebar ul ul {
+    margin-top: 0;
+    margin-bottom: 0;
+}
+
+div.sphinxsidebar form {
+    margin-top: 10px;
+}
+
+div.sphinxsidebar input {
+    border: 1px solid #98dbcc;
+    font-family: sans-serif;
+    font-size: 100%;
+}
+
+img {
+    border: 0;
+}
+
+/* -- search page ----------------------------------------------------------- */
+
+ul.search {
+    margin: 10px 0 0 20px;
+    padding: 0;
+}
+
+ul.search li {
+    padding: 5px 0 5px 20px;
+    background-image: url(file.png);
+    background-repeat: no-repeat;
+    background-position: 0 7px;
+}
+
+ul.search li a {
+    font-weight: bold;
+}
+
+ul.search li div.context {
+    color: #888;
+    margin: 2px 0 0 30px;
+    text-align: left;
+}
+
+ul.keywordmatches li.goodmatch a {
+    font-weight: bold;
+}
+
+/* -- index page ------------------------------------------------------------ */
+
+table.contentstable {
+    width: 90%;
+}
+
+table.contentstable p.biglink {
+    line-height: 150%;
+}
+
+a.biglink {
+    font-size: 130%;
+}
+
+span.linkdescr {
+    font-style: italic;
+    padding-top: 5px;
+    font-size: 90%;
+}
+
+/* -- general index --------------------------------------------------------- */
+
+table.indextable td {
+    text-align: left;
+    vertical-align: top;
+}
+
+table.indextable dl, table.indextable dd {
+    margin-top: 0;
+    margin-bottom: 0;
+}
+
+table.indextable tr.pcap {
+    height: 10px;
+}
+
+table.indextable tr.cap {
+    margin-top: 10px;
+    background-color: #f2f2f2;
+}
+
+img.toggler {
+    margin-right: 3px;
+    margin-top: 3px;
+    cursor: pointer;
+}
+
+/* -- general body styles --------------------------------------------------- */
+
+a.headerlink {
+    visibility: hidden;
+}
+
+div.body p.caption {
+    text-align: inherit;
+}
+
+div.body td {
+    text-align: left;
+}
+
+.field-list ul {
+    padding-left: 100%;
+}
+
+.first {
+    margin-top: 0 !important;
+}
+
+p.rubric {
+    margin-top: 30px;
+    font-weight: bold;
+}
+
+/* -- sidebars -------------------------------------------------------------- */
+
+div.sidebar {
+    margin: 0 0 0.5em 1em;
+    border: 1px solid #ddb;
+    padding: 7px 7px 0 7px;
+    background-color: #ffe;
+    width: 40%;
+    float: right;
+}
+
+p.sidebar-title {
+    font-weight: bold;
+}
+
+/* -- topics ---------------------------------------------------------------- */
+
+div.topic {
+    border: 1px solid #ccc;
+    padding: 7px 7px 0 7px;
+    margin: 10px 0 10px 0;
+}
+
+p.topic-title {
+    font-size: 110%;
+    font-weight: bold;
+    margin-top: 10px;
+}
+
+/* -- admonitions ----------------------------------------------------------- */
+
+div.admonition {
+    margin-top: 10px;
+    margin-bottom: 10px;
+    padding: 7px;
+}
+
+div.admonition dt {
+    font-weight: bold;
+}
+
+div.admonition dl {
+    margin-bottom: 0;
+}
+
+p.admonition-title {
+    margin: 0px 10px 5px 0px;
+    font-weight: bold;
+}
+
+
+/* -- tables ---------------------------------------------------------------- */
+
+table.docutils {
+    border: 0;
+    border-collapse: collapse;
+}
+
+table.docutils td, table.docutils th {
+    padding: 1px 8px 1px 5px;
+    border-top: 0;
+    border-left: 0;
+    border-right: 0;
+    border-bottom: 1px solid #aaa;
+}
+
+table.field-list td, table.field-list th {
+    border: 0 !important;
+}
+
+table.footnote td, table.footnote th {
+    border: 0 !important;
+}
+
+th {
+    text-align: left;
+    padding-right: 5px;
+}
+
+/* -- other body styles ----------------------------------------------------- */
+
+dl {
+    margin-bottom: 15px;
+}
+
+dd p {
+    margin-top: 0px;
+}
+
+dd ul, dd table {
+    margin-bottom: 10px;
+}
+
+dd {
+    margin-top: 3px;
+    margin-bottom: 10px;
+    margin-left: 30px;
+}
+
+dt:target, .highlighted {
+    background-color: #ddd;
+}
+
+dl.glossary dt {
+    font-weight: bold;
+    font-size: 110%;
+}
+
+.field-list ul {
+    margin: 0;
+    padding-left: 1em;
+}
+
+.field-list p {
+    margin: 0;
+}
+
+.refcount {
+    color: #060;
+}
+
+.optional {
+    font-size: 130%;
+}
+
+.versionmodified {
+    font-style: italic;
+}
+
+.system-message {
+    background-color: #fda;
+    padding: 5px;
+    border: 3px solid red;
+}
+
+.footnote:target  {
+    background-color: #dddddd;
+}
+
+/* -- code displays --------------------------------------------------------- */
+
+pre {
+    font-family: "LiberationNarrow", monospace;
+    overflow: auto;
+    overflow-y: hidden;
+}
+
+td.linenos pre {
+    padding: 5px 0px;
+    border: 0;
+    background-color: transparent;
+    color: #aaa;
+}
+
+table.highlighttable {
+    margin-left: 0.5em;
+}
+
+table.highlighttable td {
+    padding: 0 0.5em 0 0.5em;
+}
+
+tt {
+    font-family: "LiberationNarrow", monospace;
+}
+
+tt.descname {
+    background-color: transparent;
+    font-weight: bold;
+    font-size: 1.2em;
+}
+
+tt.descclassname {
+    background-color: transparent;
+}
+
+tt.xref, a tt {
+    background-color: transparent;
+    font-weight: bold;
+}
+
+h1 tt, h2 tt, h3 tt, h4 tt, h5 tt, h6 tt {
+    background-color: transparent;
+}
+
+/* -- math display ---------------------------------------------------------- */
+
+img.math {
+    vertical-align: middle;
+}
+
+span.eqno {
+    float: right;
+}
+
+/* -- special divs  --------------------------------------------------------- */
+
+div.quotebar {
+    background-color: #e3eff1;
+    max-width: 250px;
+    float: right;
+    font-family: sans-serif;
+    padding: 7px 7px;
+    border: 1px solid #ccc;
+}
+div.footer {
+    background-color: #e3eff1;
+    padding: 3px 8px 3px 0;
+    clear: both;
+    font-family: sans-serif;
+    font-size: 80%;
+    text-align: right;
+}
+
+div.footer a {
+    text-decoration: underline;
+}
+
+/* -- link-target ----------------------------------------------------------- */
+
+.link-target {
+    font-size: 80%;
+}
+
+table .link-target {
+    /* Do not show links in tables, there is not enough space */
+    display: none;
+}

sphinx/themes/mobi/theme.conf

+[theme]
+inherit = epub
+stylesheet = mobi.css
+pygments_style = none
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.