Skip to content

Commit

Permalink
Merge pull request #9350 from marxin/fix-samp-with-braces
Browse files Browse the repository at this point in the history
Fix :samp:`{var}` in manual pages.
  • Loading branch information
tk0miya committed Jun 20, 2021
2 parents 804a552 + b23eefa commit 42c0420
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
5 changes: 4 additions & 1 deletion sphinx/writers/manpage.py
Expand Up @@ -59,13 +59,16 @@ def apply(self, **kwargs: Any) -> None:
for node in self.document.traverse(matcher): # type: TextElement
if any(matcher(subnode) for subnode in node):
pos = node.parent.index(node)
for subnode in reversed(node[1:]):
for subnode in reversed(list(node)):
node.remove(subnode)
if matcher(subnode):
node.parent.insert(pos + 1, subnode)
else:
newnode = node.__class__('', '', subnode, **node.attributes)
node.parent.insert(pos + 1, newnode)
# move node if all children became siblings of the node
if not len(node):
node.parent.remove(node)


class ManualPageTranslator(SphinxTranslator, BaseTranslator):
Expand Down
7 changes: 7 additions & 0 deletions tests/roots/test-root/lists.txt
Expand Up @@ -61,3 +61,10 @@ term1

term2 (**stronged partially**)
description

Samp tests
----------

:samp:`{variable_only}`
:samp:`{variable} and text`
:samp:`Show {variable} in the middle`
5 changes: 5 additions & 0 deletions tests/test_build_manpage.py
Expand Up @@ -27,6 +27,11 @@ def test_all(app, status, warning):
assert '\n.B term1\n' in content
assert '\nterm2 (\\fBstronged partially\\fP)\n' in content

# test samp with braces
assert '\n\\fIvariable_only\\fP\n' in content
assert '\n\\fIvariable\\fP\\fB and text\\fP\n' in content
assert '\n\\fBShow \\fP\\fIvariable\\fP\\fB in the middle\\fP\n' in content

assert 'Footnotes' not in content


Expand Down

0 comments on commit 42c0420

Please sign in to comment.