Commits

Meera Ghumalia  committed 1a519e1 Merge

Merged incoming

  • Participants
  • Parent commits 39a9abc, 33577a5

Comments (0)

Files changed (12)

 Release 1.2 (in development)
 ============================
 
+* PR#123, #1106: Add epub_use_index configuration value.
+  If provided, it will be used instead of html_use_index for epub builder.
+
 * #1111: Fix uppercase word is not found in search when
   html_search_language='ja'. Thanks to tomo saito.
 
 epub_fix_images = False
 epub_max_image_width = 0
 epub_show_urls = 'inline'
+epub_use_index = False
 
 latex_documents = [('contents', 'sphinx.tex', 'Sphinx Documentation',
                     'Georg Brandl', 'manual', 1)]

File doc/config.rst

 
    .. versionadded:: 1.2
 
+.. confval:: epub_use_index
+
+   If true, add an index to the epub document.  It defaults to the
+   :confval:`html_use_index` option but can be set independently for epub
+   creation.
 
 .. _latex-options:
 
 
    .. versionadded:: 0.6
 
+   .. versionchanged:: 1.2
+      This overrides the files which is provided from Sphinx such as sphinx.sty.
+
 .. confval:: latex_preamble
 
    Additional LaTeX markup for the preamble.

File sphinx/builders/__init__.py

         """
         pass
 
+    def get_builder_config(self, option, default):
+        """Return a builder specific option.
+
+        This method allows customization of common builder settings by
+        inserting the name of the current builder in the option key.
+        If the key does not exist, use default as builder name.
+        """
+        # At the moment, only XXX_use_index is looked up this way.
+        # Every new builder variant must be registered in Config.config_values.
+        try:
+            optname = '%s_%s' % (self.name, option)
+            return getattr(self.config, optname)
+        except AttributeError:
+            optname = '%s_%s' % (default, option)
+            return getattr(self.config, optname)
 
 BUILTIN_BUILDERS = {
     'html':       ('html', 'StandaloneHTMLBuilder'),

File sphinx/builders/epub.py

             spine.append(_spine_template % {
                 'idref': self.esc(self.make_id(info[0] + self.out_suffix))
             })
-        if self.config.html_use_index:
+        if self.get_builder_config('use_index', 'epub'):
             spine.append(_spine_template % {
                 'idref': self.esc(self.make_id('genindex' + self.out_suffix))
             })

File sphinx/builders/html.py

         self.relations = self.env.collect_relations()
 
         rellinks = []
-        if self.config.html_use_index:
+        if self.get_builder_config('use_index', 'html'):
             rellinks.append(('genindex', _('General Index'), 'I', _('index')))
         for indexname, indexcls, content, collapse in self.domain_indices:
             # if it has a short name
                 self.handle_page(pagename, context, template)
 
         # the global general index
-        if self.config.html_use_index:
+        if self.get_builder_config('use_index', 'html'):
             self.write_genindex()
 
         # the global domain-specific indices

File sphinx/builders/latex.py

File contents unchanged.

File sphinx/config.py

         epub_fix_images = (False, 'env'),
         epub_max_image_width = (0, 'env'),
         epub_show_urls = ('inline', 'html'),
+        epub_use_index = (lambda self: self.html_use_index, 'html'),
 
         # LaTeX options
         latex_documents = (lambda self: [(self.master_doc,

File sphinx/directives/code.py

 
         encoding = self.options.get('encoding', env.config.source_encoding)
         codec_info = codecs.lookup(encoding)
+        f = None
         try:
             f = codecs.StreamReaderWriter(open(filename, 'rb'),
                     codec_info[2], codec_info[3], 'strict')
             lines = f.readlines()
-            f.close()
         except (IOError, OSError):
             return [document.reporter.warning(
                 'Include file %r not found or reading it failed' % filename,
                 'Encoding %r used for reading included file %r seems to '
                 'be wrong, try giving an :encoding: option' %
                 (encoding, filename))]
+        finally:
+            if f is not None:
+                f.close()
 
         objectname = self.options.get('pyobject')
         if objectname is not None:

File sphinx/quickstart.py

 
 # If 'no', URL addresses will not be shown.
 #epub_show_urls = 'inline'
+
+# If false, no index is generated.
+#epub_use_index = True
 '''
 
 INTERSPHINX_CONFIG = u'''

File sphinx/writers/text.py

         do_format()
         if first is not None and result:
             itemindent, item = result[0]
+            result_rest, result = result[1:], []
             if item:
-                result.insert(0, (itemindent - indent, [first + item[0]]))
-                result[1] = (itemindent, item[1:])
+                toformat = [first + ' '.join(item)]
+                do_format()  #re-create `result` from `toformat`
+                _dummy, new_item = result[0]
+                result.insert(0, (itemindent - indent, [new_item[0]]))
+                result[1] = (itemindent, new_item[1:])
+                result.extend(result_rest)
         self.states[-1].extend(result)
 
     def visit_document(self, node):
             self.new_state(len(str(self.list_counter[-1])) + 2)
     def depart_list_item(self, node):
         if self.list_counter[-1] == -1:
-            self.end_state(first='* ', end=None)
+            self.end_state(first='* ')
         elif self.list_counter[-1] == -2:
             pass
         else:
-            self.end_state(first='%s. ' % self.list_counter[-1], end=None)
+            self.end_state(first='%s. ' % self.list_counter[-1])
 
     def visit_definition_list_item(self, node):
         self._li_has_classifier = len(node) >= 2 and \

File tests/test_build_text.py

 
 
 @with_text_app()
+def test_maxwitdh_with_prefix(app):
+    long_string = u' '.join([u"ham"] * 30)
+    contents = (
+            u".. seealso:: %(long_string)s\n\n"
+            u"* %(long_string)s\n"
+            u"* %(long_string)s\n"
+            u"\nspam egg\n"
+            ) % locals()
+
+    (app.srcdir / 'contents.rst').write_text(contents, encoding='utf-8')
+    app.builder.build_all()
+    result = (app.outdir / 'contents.txt').text(encoding='utf-8')
+
+    lines = result.splitlines()
+    line_widths = [column_width(line) for line in lines]
+    assert max(line_widths) < MAXWIDTH
+    assert lines[0].startswith('See also: ham')
+    assert lines[1].startswith('  ham')
+    assert lines[2] == ''
+    assert lines[3].startswith('* ham')
+    assert lines[4].startswith('  ham')
+    assert lines[5] == ''
+    assert lines[6].startswith('* ham')
+    assert lines[7].startswith('  ham')
+    assert lines[8] == ''
+    assert lines[9].startswith('spam egg')
+
+
+@with_text_app()
+def test_lineblock(app):
+    # regression test for #1109: need empty line after line block
+    contents = (
+            u"* one\n"
+            u"\n"
+            u"  | line-block 1\n"
+            u"  | line-block 2\n"
+            u"\n"
+            u"followed paragraph.\n"
+            )
+
+    (app.srcdir / 'contents.rst').write_text(contents, encoding='utf-8')
+    app.builder.build_all()
+    result = (app.outdir / 'contents.txt').text(encoding='utf-8')
+
+    expect = (
+            u"* one\n"
+            u"\n"
+            u"     line-block 1\n"
+            u"     line-block 2\n"
+            u"\n"
+            u"followed paragraph.\n"
+            )
+
+    assert result == expect
+
+
+@with_text_app()
 def test_multibyte_title_line(app):
     title = u'\u65e5\u672c\u8a9e'
     underline = u'=' * column_width(title)