##// END OF EJS Templates
convert IPython syntax to Python syntax in nbconvert python template...
MinRK -
Show More
@@ -54,6 +54,7 b' default_filters = {'
54 54 'get_lines': filters.get_lines,
55 55 'highlight2html': filters.highlight2html,
56 56 'highlight2latex': filters.highlight2latex,
57 'ipython2python': filters.ipython2python,
57 58 'markdown2latex': filters.markdown2latex,
58 59 'markdown2rst': filters.markdown2rst,
59 60 'comment_lines': filters.comment_lines,
@@ -19,6 +19,8 b' templates.'
19 19 import re
20 20 import textwrap
21 21 from xml.etree import ElementTree
22
23 from IPython.core.interactiveshell import InteractiveShell
22 24 from IPython.utils import py3compat
23 25
24 26 #-----------------------------------------------------------------------------
@@ -32,7 +34,8 b' __all__ = ['
32 34 'strip_dollars',
33 35 'strip_files_prefix',
34 36 'comment_lines',
35 'get_lines'
37 'get_lines',
38 'ipython2python',
36 39 ]
37 40
38 41
@@ -150,3 +153,15 b' def get_lines(text, start=None,end=None):'
150 153
151 154 # Return the right lines.
152 155 return "\n".join(lines[start:end]) #re-join
156
157 def ipython2python(code):
158 """Transform IPython syntax to pure Python syntax
159
160 Parameters
161 ----------
162
163 code : str
164 IPython code, to be transformed to pure Python
165 """
166 shell = InteractiveShell.instance()
167 return shell.input_transformer_manager.transform_cell(code)
@@ -7,7 +7,7 b''
7 7 {% block output_prompt %}
8 8 # Out[{{cell.prompt_number}}]:{% endblock output_prompt %}
9 9
10 {% block input %}{{ cell.input }}
10 {% block input %}{{ cell.input | ipython2python }}
11 11 {% endblock input %}
12 12
13 13
General Comments 0
You need to be logged in to leave comments. Login now