Skip to content

Commit

Permalink
Fix sphinx-doc#3859: manpage: code-block captions are not displayed c…
Browse files Browse the repository at this point in the history
…orrectly
  • Loading branch information
tk0miya committed Mar 10, 2019
1 parent f57041a commit 6fa92ff
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES
Expand Up @@ -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
--------
Expand Down
15 changes: 15 additions & 0 deletions sphinx/writers/manpage.py
Expand Up @@ -462,6 +462,21 @@ def depart_manpage(self, node):
# type: (nodes.Node) -> None
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:
super(ManualPageTranslator, self).visit_caption(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:
super(ManualPageTranslator, self).depart_caption(node)

# overwritten: handle section titles better than in 0.6 release
def visit_title(self, node):
# type: (nodes.Node) -> None
Expand Down
21 changes: 21 additions & 0 deletions tests/test_build_manpage.py
Expand Up @@ -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)

0 comments on commit 6fa92ff

Please sign in to comment.