Skip to content

Commit

Permalink
LaTeX: Use pushbody()/popbody()
Browse files Browse the repository at this point in the history
  • Loading branch information
mgeier committed Dec 16, 2016
1 parent 057ad47 commit 88da075
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions nbsphinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -1144,11 +1144,13 @@ def depart_code_html(self, node):
def visit_code_latex(self, node):
"""Avoid creating a separate prompt node.
The prompt will be pre-pended in the main code node.
The prompt (which is stored in the "latex_prompt" attribute) will be
pre-pended in the main code node.
"""
if 'latex_prompt' not in node.attributes:
raise docutils.nodes.SkipNode()
self.pushbody([]) # See popbody() below


def depart_code_latex(self, node):
Expand All @@ -1159,7 +1161,7 @@ def depart_code_latex(self, node):
* Add prompt to the first line, empty space to the following lines
"""
lines = self.body[-1].split('\n')
lines = ''.join(self.popbody()).split('\n')
out = []
assert lines[0] == ''
out.append(lines[0])
Expand Down Expand Up @@ -1190,7 +1192,7 @@ def depart_code_latex(self, node):
assert False
assert lines[-1] == ''
out.append(lines[-1])
self.body[-1] = '\n'.join(out)
self.body.append('\n'.join(out))


def visit_admonition_html(self, node):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
'nbconvert',
'traitlets',
'nbformat',
'sphinx',
'sphinx>=1.3.2',
],
author='Matthias Geier',
author_email='[email protected]',
Expand Down

0 comments on commit 88da075

Please sign in to comment.