diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2019-03-10 02:03:11 +0900 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2019-03-10 12:40:55 +0900 |
commit | fc9968710561582752d5038618dd0dbfce779734 (patch) | |
tree | c5d9de0ab881cb42cbe261ba4bed6563b7ad55f9 | |
parent | f57041ab000c6c2b1e672f3d963d849ecd3ee7ab (diff) | |
download | sphinx-git-fc9968710561582752d5038618dd0dbfce779734.tar.gz |
Fix #3859: manpage: code-block captions are not displayed correctly
-rw-r--r-- | CHANGES | 1 | ||||
-rw-r--r-- | sphinx/writers/manpage.py | 15 | ||||
-rw-r--r-- | tests/test_build_manpage.py | 21 |
3 files changed, 37 insertions, 0 deletions
@@ -30,6 +30,7 @@ Bugs fixed * #6136: ``:name:`` option for ``math`` directive causes a crash * #6139: intersphinx: ValueError on failure reporting * #6135: changes: Fix UnboundLocalError when any module found +* #3859: manpage: code-block captions are not displayed correctly Testing -------- diff --git a/sphinx/writers/manpage.py b/sphinx/writers/manpage.py index 9ce9f7293..20b1d07e1 100644 --- a/sphinx/writers/manpage.py +++ b/sphinx/writers/manpage.py @@ -463,6 +463,21 @@ class ManualPageTranslator(BaseTranslator): return self.depart_strong(node) # overwritten: handle section titles better than in 0.6 release + def visit_caption(self, node): + # type: (nodes.Element) -> None + if isinstance(node.parent, nodes.container) and node.parent.get('literal_block'): + self.body.append('.sp\n') + else: + BaseTranslator.visit_caption(self, node) + + def depart_caption(self, node): + # type: (nodes.Element) -> None + if isinstance(node.parent, nodes.container) and node.parent.get('literal_block'): + self.body.append('\n') + else: + BaseTranslator.depart_caption(self, node) + + # overwritten: handle section titles better than in 0.6 release def visit_title(self, node): # type: (nodes.Node) -> None if isinstance(node.parent, addnodes.seealso): diff --git a/tests/test_build_manpage.py b/tests/test_build_manpage.py index 0a22d3ab6..6596e83b6 100644 --- a/tests/test_build_manpage.py +++ b/tests/test_build_manpage.py @@ -25,3 +25,24 @@ def test_all(app, status, warning): # term of definition list including nodes.strong assert '\n.B term1\n' in content assert '\nterm2 (\\fBstronged partially\\fP)\n' in content + + +@pytest.mark.sphinx('man', testroot='directive-code') +def test_captioned_code_block(app, status, warning): + app.builder.build_all() + content = (app.outdir / 'python.1').text() + + assert ('.sp\n' + 'caption \\fItest\\fP rb\n' + '.INDENT 0.0\n' + '.INDENT 3.5\n' + '.sp\n' + '.nf\n' + '.ft C\n' + 'def ruby?\n' + ' false\n' + 'end\n' + '.ft P\n' + '.fi\n' + '.UNINDENT\n' + '.UNINDENT\n' in content) |