Show More
@@ -54,6 +54,7 b' default_filters = {' | |||||
54 | 'get_lines': filters.get_lines, |
|
54 | 'get_lines': filters.get_lines, | |
55 | 'highlight2html': filters.highlight2html, |
|
55 | 'highlight2html': filters.highlight2html, | |
56 | 'highlight2latex': filters.highlight2latex, |
|
56 | 'highlight2latex': filters.highlight2latex, | |
|
57 | 'ipython2python': filters.ipython2python, | |||
57 | 'markdown2latex': filters.markdown2latex, |
|
58 | 'markdown2latex': filters.markdown2latex, | |
58 | 'markdown2rst': filters.markdown2rst, |
|
59 | 'markdown2rst': filters.markdown2rst, | |
59 | 'comment_lines': filters.comment_lines, |
|
60 | 'comment_lines': filters.comment_lines, |
@@ -19,6 +19,8 b' templates.' | |||||
19 | import re |
|
19 | import re | |
20 | import textwrap |
|
20 | import textwrap | |
21 | from xml.etree import ElementTree |
|
21 | from xml.etree import ElementTree | |
|
22 | ||||
|
23 | from IPython.core.interactiveshell import InteractiveShell | |||
22 | from IPython.utils import py3compat |
|
24 | from IPython.utils import py3compat | |
23 |
|
25 | |||
24 | #----------------------------------------------------------------------------- |
|
26 | #----------------------------------------------------------------------------- | |
@@ -32,7 +34,8 b' __all__ = [' | |||||
32 | 'strip_dollars', |
|
34 | 'strip_dollars', | |
33 | 'strip_files_prefix', |
|
35 | 'strip_files_prefix', | |
34 | 'comment_lines', |
|
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 | # Return the right lines. |
|
154 | # Return the right lines. | |
152 | return "\n".join(lines[start:end]) #re-join |
|
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 | {% block output_prompt %} |
|
7 | {% block output_prompt %} | |
8 | # Out[{{cell.prompt_number}}]:{% endblock output_prompt %} |
|
8 | # Out[{{cell.prompt_number}}]:{% endblock output_prompt %} | |
9 |
|
9 | |||
10 | {% block input %}{{ cell.input }} |
|
10 | {% block input %}{{ cell.input | ipython2python }} | |
11 | {% endblock input %} |
|
11 | {% endblock input %} | |
12 |
|
12 | |||
13 |
|
13 |
General Comments 0
You need to be logged in to leave comments.
Login now