summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Liska <mliska@suse.cz>2021-06-16 09:21:46 +0200
committerMartin Liska <mliska@suse.cz>2021-06-16 09:30:08 +0200
commitb23eefa03b56717c4be973d5f89044517dca8f8c (patch)
tree65473d0538ffbfc7005aa3a344b6e1b0eeffd60f
parentf14561da80c263b867b51e27a75c4f9cdacfeb29 (diff)
downloadsphinx-git-b23eefa03b56717c4be973d5f89044517dca8f8c.tar.gz
Fix :samp:`{var}` in manual pages.
When a samp begins with a variable part, it is not unwrapped for manual pages. Fixes #1860.
-rw-r--r--sphinx/writers/manpage.py5
-rw-r--r--tests/roots/test-root/lists.txt7
-rw-r--r--tests/test_build_manpage.py5
3 files changed, 16 insertions, 1 deletions
diff --git a/sphinx/writers/manpage.py b/sphinx/writers/manpage.py
index 3f0eea5eb..95e0f5658 100644
--- a/sphinx/writers/manpage.py
+++ b/sphinx/writers/manpage.py
@@ -59,13 +59,16 @@ class NestedInlineTransform:
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):
diff --git a/tests/roots/test-root/lists.txt b/tests/roots/test-root/lists.txt
index 1fa2d11c5..0b5445461 100644
--- a/tests/roots/test-root/lists.txt
+++ b/tests/roots/test-root/lists.txt
@@ -61,3 +61,10 @@ term1
term2 (**stronged partially**)
description
+
+Samp tests
+----------
+
+:samp:`{variable_only}`
+:samp:`{variable} and text`
+:samp:`Show {variable} in the middle`
diff --git a/tests/test_build_manpage.py b/tests/test_build_manpage.py
index 0b7ce2396..3680d8651 100644
--- a/tests/test_build_manpage.py
+++ b/tests/test_build_manpage.py
@@ -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