Commits

Takayuki Shimizukawa  committed 4ff0575

Fix: text builder breach max-witdh specificatoin if paragraph have prefixed text. ex: 'See also:'

  • Participants
  • Parent commits 98b5b1f

Comments (0)

Files changed (2)

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_multibyte_title_line(app):
     title = u'\u65e5\u672c\u8a9e'
     underline = u'=' * column_width(title)