Merge pull request #6869 from tk0miya/6867_extra_spaces_on_folding

Fix #6867: text: extra spaces are inserted to hyphenated words on folding lines
This commit is contained in:
Takeshi KOMIYA 2019-11-30 22:59:18 +09:00 committed by GitHub
commit 0d80cff43c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 25 deletions

View File

@ -11,6 +11,7 @@ Incompatible changes
match the first line of the code block.
* #1331: Change default User-Agent header to ``"Sphinx/X.Y.Z requests/X.Y.Z
python/X.Y.Z"``. It can be changed via :confval:`user_agent`.
* #6867: text: content of admonitions starts after a blank line
Deprecated
----------
@ -78,6 +79,7 @@ Bugs fixed
fully matched in a text paragraph on the same page, the search does not
include this match.
* #6848: config.py shouldn't pop extensions from overrides
* #6867: text: extra spaces are inserted to hyphenated words on folding lines
Testing
--------

View File

@ -440,15 +440,14 @@ class TextTranslator(SphinxTranslator):
toformat = []
do_format()
if first is not None and result:
itemindent, item = result[0]
result_rest, result = result[1:], []
if item:
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)
# insert prefix into first line (ex. *, [1], See also, etc.)
newindent = result[0][0] - indent
if result[0][1] == ['']:
result.insert(0, (newindent, [first]))
else:
text = first + result[0][1].pop(0)
result.insert(0, (newindent, [text]))
self.states[-1].extend(result)
def visit_document(self, node: Element) -> None:
@ -916,12 +915,20 @@ class TextTranslator(SphinxTranslator):
def _visit_admonition(self, node: Element) -> None:
self.new_state(2)
if isinstance(node.children[0], nodes.Sequential):
self.add_text(self.nl)
def _depart_admonition(self, node: Element) -> None:
label = admonitionlabels[node.tagname]
self.end_state(first=label + ': ')
indent = sum(self.stateindent) + len(label)
print(self.states[-1])
if (len(self.states[-1]) == 1 and
self.states[-1][0][0] == 0 and
MAXWIDTH - indent >= sum(len(s) for s in self.states[-1][0][1])):
# short text: append text after admonition label
self.stateindent[-1] += len(label)
self.end_state(first=label + ': ')
else:
# long text: append label before the block
self.states[-1].insert(0, (0, [self.nl]))
self.end_state(first=label + ':')
visit_attention = _visit_admonition
depart_attention = _depart_admonition

View File

@ -31,16 +31,18 @@ def test_maxwitdh_with_prefix(app, status, warning):
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')
assert lines[0].startswith('See also:')
assert lines[1].startswith('')
assert lines[2].startswith(' ham')
assert lines[3].startswith(' ham')
assert lines[4] == ''
assert lines[5].startswith('* ham')
assert lines[6].startswith(' ham')
assert lines[7] == ''
assert lines[8].startswith('* ham')
assert lines[9].startswith(' ham')
assert lines[10] == ''
assert lines[11].startswith('spam egg')
@with_text_app()

View File

@ -315,7 +315,8 @@ def test_text_seealso(app):
"\n*********************\n"
"\nSee also: SHORT TEXT 1\n"
"\nSee also: LONG TEXT 1\n"
"\nSee also: SHORT TEXT 2\n"
"\nSee also:\n"
"\n SHORT TEXT 2\n"
"\n LONG TEXT 2\n")
assert result == expect
@ -356,7 +357,9 @@ def test_text_figure_captions(app):
"14.4. IMAGE UNDER NOTE\n"
"======================\n"
"\n"
"Note: [image: i18n under note][image]\n"
"Note:\n"
"\n"
" [image: i18n under note][image]\n"
"\n"
" [image: img under note][image]\n")
assert result == expect