mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix: text builder breach max-witdh specificatoin if paragraph have prefixed text. ex: 'See also:'
This commit is contained in:
parent
fea035ebe0
commit
f6fca7a8ac
@ -199,9 +199,14 @@ class TextTranslator(nodes.NodeVisitor):
|
||||
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):
|
||||
@ -572,11 +577,11 @@ class TextTranslator(nodes.NodeVisitor):
|
||||
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 \
|
||||
|
@ -30,6 +30,35 @@ def with_text_app(*args, **kw):
|
||||
return with_app(*args, **default_kw)
|
||||
|
||||
|
||||
@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'
|
||||
|
Loading…
Reference in New Issue
Block a user