mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
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:
commit
0d80cff43c
2
CHANGES
2
CHANGES
@ -11,6 +11,7 @@ Incompatible changes
|
|||||||
match the first line of the code block.
|
match the first line of the code block.
|
||||||
* #1331: Change default User-Agent header to ``"Sphinx/X.Y.Z requests/X.Y.Z
|
* #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`.
|
python/X.Y.Z"``. It can be changed via :confval:`user_agent`.
|
||||||
|
* #6867: text: content of admonitions starts after a blank line
|
||||||
|
|
||||||
Deprecated
|
Deprecated
|
||||||
----------
|
----------
|
||||||
@ -78,6 +79,7 @@ Bugs fixed
|
|||||||
fully matched in a text paragraph on the same page, the search does not
|
fully matched in a text paragraph on the same page, the search does not
|
||||||
include this match.
|
include this match.
|
||||||
* #6848: config.py shouldn't pop extensions from overrides
|
* #6848: config.py shouldn't pop extensions from overrides
|
||||||
|
* #6867: text: extra spaces are inserted to hyphenated words on folding lines
|
||||||
|
|
||||||
Testing
|
Testing
|
||||||
--------
|
--------
|
||||||
|
@ -440,15 +440,14 @@ class TextTranslator(SphinxTranslator):
|
|||||||
toformat = []
|
toformat = []
|
||||||
do_format()
|
do_format()
|
||||||
if first is not None and result:
|
if first is not None and result:
|
||||||
itemindent, item = result[0]
|
# insert prefix into first line (ex. *, [1], See also, etc.)
|
||||||
result_rest, result = result[1:], []
|
newindent = result[0][0] - indent
|
||||||
if item:
|
if result[0][1] == ['']:
|
||||||
toformat = [first + ' '.join(item)]
|
result.insert(0, (newindent, [first]))
|
||||||
do_format() # re-create `result` from `toformat`
|
else:
|
||||||
_dummy, new_item = result[0]
|
text = first + result[0][1].pop(0)
|
||||||
result.insert(0, (itemindent - indent, [new_item[0]]))
|
result.insert(0, (newindent, [text]))
|
||||||
result[1] = (itemindent, new_item[1:])
|
|
||||||
result.extend(result_rest)
|
|
||||||
self.states[-1].extend(result)
|
self.states[-1].extend(result)
|
||||||
|
|
||||||
def visit_document(self, node: Element) -> None:
|
def visit_document(self, node: Element) -> None:
|
||||||
@ -916,12 +915,20 @@ class TextTranslator(SphinxTranslator):
|
|||||||
def _visit_admonition(self, node: Element) -> None:
|
def _visit_admonition(self, node: Element) -> None:
|
||||||
self.new_state(2)
|
self.new_state(2)
|
||||||
|
|
||||||
if isinstance(node.children[0], nodes.Sequential):
|
|
||||||
self.add_text(self.nl)
|
|
||||||
|
|
||||||
def _depart_admonition(self, node: Element) -> None:
|
def _depart_admonition(self, node: Element) -> None:
|
||||||
label = admonitionlabels[node.tagname]
|
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
|
visit_attention = _visit_admonition
|
||||||
depart_attention = _depart_admonition
|
depart_attention = _depart_admonition
|
||||||
|
@ -31,16 +31,18 @@ def test_maxwitdh_with_prefix(app, status, warning):
|
|||||||
lines = result.splitlines()
|
lines = result.splitlines()
|
||||||
line_widths = [column_width(line) for line in lines]
|
line_widths = [column_width(line) for line in lines]
|
||||||
assert max(line_widths) < MAXWIDTH
|
assert max(line_widths) < MAXWIDTH
|
||||||
assert lines[0].startswith('See also: ham')
|
assert lines[0].startswith('See also:')
|
||||||
assert lines[1].startswith(' ham')
|
assert lines[1].startswith('')
|
||||||
assert lines[2] == ''
|
assert lines[2].startswith(' ham')
|
||||||
assert lines[3].startswith('* ham')
|
assert lines[3].startswith(' ham')
|
||||||
assert lines[4].startswith(' ham')
|
assert lines[4] == ''
|
||||||
assert lines[5] == ''
|
assert lines[5].startswith('* ham')
|
||||||
assert lines[6].startswith('* ham')
|
assert lines[6].startswith(' ham')
|
||||||
assert lines[7].startswith(' ham')
|
assert lines[7] == ''
|
||||||
assert lines[8] == ''
|
assert lines[8].startswith('* ham')
|
||||||
assert lines[9].startswith('spam egg')
|
assert lines[9].startswith(' ham')
|
||||||
|
assert lines[10] == ''
|
||||||
|
assert lines[11].startswith('spam egg')
|
||||||
|
|
||||||
|
|
||||||
@with_text_app()
|
@with_text_app()
|
||||||
|
@ -315,7 +315,8 @@ def test_text_seealso(app):
|
|||||||
"\n*********************\n"
|
"\n*********************\n"
|
||||||
"\nSee also: SHORT TEXT 1\n"
|
"\nSee also: SHORT TEXT 1\n"
|
||||||
"\nSee also: LONG 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")
|
"\n LONG TEXT 2\n")
|
||||||
assert result == expect
|
assert result == expect
|
||||||
|
|
||||||
@ -356,7 +357,9 @@ def test_text_figure_captions(app):
|
|||||||
"14.4. IMAGE UNDER NOTE\n"
|
"14.4. IMAGE UNDER NOTE\n"
|
||||||
"======================\n"
|
"======================\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Note: [image: i18n under note][image]\n"
|
"Note:\n"
|
||||||
|
"\n"
|
||||||
|
" [image: i18n under note][image]\n"
|
||||||
"\n"
|
"\n"
|
||||||
" [image: img under note][image]\n")
|
" [image: img under note][image]\n")
|
||||||
assert result == expect
|
assert result == expect
|
||||||
|
Loading…
Reference in New Issue
Block a user