diff --git a/CHANGES b/CHANGES index bfa438378..3b78d6e44 100644 --- a/CHANGES +++ b/CHANGES @@ -43,6 +43,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 ---------- @@ -110,6 +111,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 -------- diff --git a/setup.py b/setup.py index 202523fe0..df34d4fa8 100644 --- a/setup.py +++ b/setup.py @@ -47,7 +47,7 @@ extras_require = { 'html5lib', 'flake8>=3.5.0', 'flake8-import-order', - 'mypy>=0.740', + 'mypy>=0.750', 'docutils-stubs', ], } diff --git a/sphinx/pycode/parser.py b/sphinx/pycode/parser.py index cbae86c9e..4233089ff 100644 --- a/sphinx/pycode/parser.py +++ b/sphinx/pycode/parser.py @@ -129,7 +129,7 @@ class TokenProcessor: def __init__(self, buffers: List[str]) -> None: lines = iter(buffers) self.buffers = buffers - self.tokens = tokenize.generate_tokens(lambda: next(lines)) + self.tokens = tokenize.generate_tokens(lambda: next(lines)) # type: ignore self.current = None # type: Token self.previous = None # type: Token diff --git a/sphinx/writers/text.py b/sphinx/writers/text.py index de17075fc..326ef9f90 100644 --- a/sphinx/writers/text.py +++ b/sphinx/writers/text.py @@ -438,15 +438,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: @@ -914,12 +913,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 diff --git a/tests/test_build_text.py b/tests/test_build_text.py index 5b19f43ef..efdc0f5eb 100644 --- a/tests/test_build_text.py +++ b/tests/test_build_text.py @@ -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() diff --git a/tests/test_intl.py b/tests/test_intl.py index a6bd17512..080ee9221 100644 --- a/tests/test_intl.py +++ b/tests/test_intl.py @@ -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