Show More
@@ -68,7 +68,8 b' default_filters = {' | |||||
68 | 'strip_math_space': filters.strip_math_space, |
|
68 | 'strip_math_space': filters.strip_math_space, | |
69 | 'wrap_text': filters.wrap_text, |
|
69 | 'wrap_text': filters.wrap_text, | |
70 | 'escape_latex': filters.escape_latex, |
|
70 | 'escape_latex': filters.escape_latex, | |
71 | 'citation2latex': filters.citation2latex |
|
71 | 'citation2latex': filters.citation2latex, | |
|
72 | 'path2url': filters.path2url, | |||
72 | } |
|
73 | } | |
73 |
|
74 | |||
74 | #----------------------------------------------------------------------------- |
|
75 | #----------------------------------------------------------------------------- |
@@ -13,6 +13,7 b' Exporter that will export your ipynb to Markdown.' | |||||
13 | # Imports |
|
13 | # Imports | |
14 | #----------------------------------------------------------------------------- |
|
14 | #----------------------------------------------------------------------------- | |
15 |
|
15 | |||
|
16 | from IPython.config import Config | |||
16 | from IPython.utils.traitlets import Unicode |
|
17 | from IPython.utils.traitlets import Unicode | |
17 |
|
18 | |||
18 | from .exporter import Exporter |
|
19 | from .exporter import Exporter | |
@@ -29,3 +30,9 b' class MarkdownExporter(Exporter):' | |||||
29 | file_extension = Unicode( |
|
30 | file_extension = Unicode( | |
30 | 'md', config=True, |
|
31 | 'md', config=True, | |
31 | help="Extension of the file that should be written to disk") |
|
32 | help="Extension of the file that should be written to disk") | |
|
33 | ||||
|
34 | @property | |||
|
35 | def default_config(self): | |||
|
36 | c = Config({'ExtractOutputPreprocessor':{'enabled':True}}) | |||
|
37 | c.merge(super(MarkdownExporter,self).default_config) | |||
|
38 | return c |
@@ -19,6 +19,7 b' templates.' | |||||
19 | import os |
|
19 | import os | |
20 | import re |
|
20 | import re | |
21 | import textwrap |
|
21 | import textwrap | |
|
22 | from urllib2 import quote | |||
22 | from xml.etree import ElementTree |
|
23 | from xml.etree import ElementTree | |
23 |
|
24 | |||
24 | from IPython.core.interactiveshell import InteractiveShell |
|
25 | from IPython.core.interactiveshell import InteractiveShell | |
@@ -38,6 +39,7 b' __all__ = [' | |||||
38 | 'get_lines', |
|
39 | 'get_lines', | |
39 | 'ipython2python', |
|
40 | 'ipython2python', | |
40 | 'posix_path', |
|
41 | 'posix_path', | |
|
42 | 'path2url', | |||
41 | ] |
|
43 | ] | |
42 |
|
44 | |||
43 |
|
45 | |||
@@ -181,3 +183,8 b' def posix_path(path):' | |||||
181 | if os.path.sep != '/': |
|
183 | if os.path.sep != '/': | |
182 | return path.replace(os.path.sep, '/') |
|
184 | return path.replace(os.path.sep, '/') | |
183 | return path |
|
185 | return path | |
|
186 | ||||
|
187 | def path2url(path): | |||
|
188 | """Turn a file path into a URL""" | |||
|
189 | parts = path.split(os.path.sep) | |||
|
190 | return '/'.join(quote(part) for part in parts) |
@@ -362,7 +362,7 b' Note: For best display, use latex syntax highlighting. =))' | |||||
362 | ((*- endblock -*)) |
|
362 | ((*- endblock -*)) | |
363 |
|
363 | |||
364 | ((*- block data_jpg -*)) |
|
364 | ((*- block data_jpg -*)) | |
365 | ((( conditionally_center_output(insert_graphics(output.jpg_filename | posix_path)) ))) |
|
365 | ((( conditionally_center_output(insert_graphics(output.jpeg_filename | posix_path)) ))) | |
366 | ((*- endblock -*)) |
|
366 | ((*- endblock -*)) | |
367 |
|
367 | |||
368 | ((*- block data_svg -*)) |
|
368 | ((*- block data_svg -*)) |
@@ -2,19 +2,13 b'' | |||||
2 |
|
2 | |||
3 |
|
3 | |||
4 | {% block in_prompt %} |
|
4 | {% block in_prompt %} | |
5 | In[{{ cell.prompt_number if cell.prompt_number else ' ' }}]: |
|
|||
6 | {% endblock in_prompt %} |
|
5 | {% endblock in_prompt %} | |
7 |
|
6 | |||
8 | {% block output_prompt %} |
|
7 | {% block output_prompt %} | |
9 | {% if cell.haspyout %} |
|
|||
10 | Out[{{ cell.prompt_number }}]: |
|
|||
11 | {%- endif %} |
|
|||
12 | {%- endblock output_prompt %} |
|
8 | {%- endblock output_prompt %} | |
13 |
|
9 | |||
14 | {% block input %} |
|
10 | {% block input %} | |
15 | ``` |
|
11 | {{ cell.input | indent(4)}} | |
16 | {{ cell.input }} |
|
|||
17 | ``` |
|
|||
18 | {% endblock input %} |
|
12 | {% endblock input %} | |
19 |
|
13 | |||
20 | {% block pyerr %} |
|
14 | {% block pyerr %} | |
@@ -26,6 +20,7 b' Out[{{ cell.prompt_number }}]:' | |||||
26 | {% endblock traceback_line %} |
|
20 | {% endblock traceback_line %} | |
27 |
|
21 | |||
28 | {% block pyout %} |
|
22 | {% block pyout %} | |
|
23 | ||||
29 | {% block data_priority scoped %} |
|
24 | {% block data_priority scoped %} | |
30 | {{ super() }} |
|
25 | {{ super() }} | |
31 | {% endblock %} |
|
26 | {% endblock %} | |
@@ -36,23 +31,25 b' Out[{{ cell.prompt_number }}]:' | |||||
36 | {% endblock stream %} |
|
31 | {% endblock stream %} | |
37 |
|
32 | |||
38 | {% block data_svg %} |
|
33 | {% block data_svg %} | |
39 |
|
|
34 | ![svg]({{ output.svg_filename | path2url }}) | |
40 | {% endblock data_svg %} |
|
35 | {% endblock data_svg %} | |
41 |
|
36 | |||
42 | {% block data_png %} |
|
37 | {% block data_png %} | |
43 |
|
|
38 | ![png]({{ output.png_filename | path2url }}) | |
44 | {% endblock data_png %} |
|
39 | {% endblock data_png %} | |
45 |
|
40 | |||
46 | {% block data_jpg %} |
|
41 | {% block data_jpg %} | |
47 |
|
|
42 | ![jpeg]({{ output.jpeg_filename | path2url }}) | |
48 | {% endblock data_jpg %} |
|
43 | {% endblock data_jpg %} | |
49 |
|
44 | |||
50 | {% block data_latex %} |
|
45 | {% block data_latex %} | |
51 | $$ |
|
|||
52 | {{ output.latex }} |
|
46 | {{ output.latex }} | |
53 | $$ |
|
|||
54 | {% endblock data_latex %} |
|
47 | {% endblock data_latex %} | |
55 |
|
48 | |||
|
49 | {% block data_html scoped %} | |||
|
50 | {{ output.html }} | |||
|
51 | {% endblock data_html %} | |||
|
52 | ||||
56 | {% block data_text scoped %} |
|
53 | {% block data_text scoped %} | |
57 | {{ output.text | indent }} |
|
54 | {{ output.text | indent }} | |
58 | {% endblock data_text %} |
|
55 | {% endblock data_text %} | |
@@ -61,6 +58,7 b' $$' | |||||
61 | {{ cell.source | wrap_text(80) }} |
|
58 | {{ cell.source | wrap_text(80) }} | |
62 | {% endblock markdowncell %} |
|
59 | {% endblock markdowncell %} | |
63 |
|
60 | |||
|
61 | ||||
64 | {% block headingcell scoped %} |
|
62 | {% block headingcell scoped %} | |
65 | {{ '#' * cell.level }} {{ cell.source | replace('\n', ' ') }} |
|
63 | {{ '#' * cell.level }} {{ cell.source | replace('\n', ' ') }} | |
66 | {% endblock headingcell %} |
|
64 | {% endblock headingcell %} |
@@ -2,25 +2,22 b'' | |||||
2 |
|
2 | |||
3 |
|
3 | |||
4 | {% block in_prompt %} |
|
4 | {% block in_prompt %} | |
5 |
|
||||
6 | In[{{ cell.prompt_number if cell.prompt_number else ' ' }}]: |
|
|||
7 |
|
||||
8 | .. code:: python |
|
|||
9 |
|
||||
10 | {% endblock in_prompt %} |
|
5 | {% endblock in_prompt %} | |
11 |
|
6 | |||
12 | {% block output_prompt %} |
|
7 | {% block output_prompt %} | |
13 | {% if cell.haspyout -%} |
|
|||
14 | Out[{{ cell.prompt_number }}]: |
|
|||
15 | {% endif %} |
|
|||
16 | {% endblock output_prompt %} |
|
8 | {% endblock output_prompt %} | |
17 |
|
9 | |||
18 | {% block input %} |
|
10 | {% block input %} | |
|
11 | {%- if not cell.input.isspace() -%} | |||
|
12 | .. code:: python | |||
|
13 | ||||
19 | {{ cell.input | indent}} |
|
14 | {{ cell.input | indent}} | |
|
15 | {%- endif -%} | |||
20 | {% endblock input %} |
|
16 | {% endblock input %} | |
21 |
|
17 | |||
22 | {% block pyerr %} |
|
18 | {% block pyerr %} | |
23 | :: |
|
19 | :: | |
|
20 | ||||
24 | {{ super() }} |
|
21 | {{ super() }} | |
25 | {% endblock pyerr %} |
|
22 | {% endblock pyerr %} | |
26 |
|
23 | |||
@@ -49,19 +46,27 b" In[{{ cell.prompt_number if cell.prompt_number else ' ' }}]:" | |||||
49 | {% endblock data_png %} |
|
46 | {% endblock data_png %} | |
50 |
|
47 | |||
51 | {% block data_jpg %} |
|
48 | {% block data_jpg %} | |
52 |
.. |
|
49 | .. image:: {{ output.jpeg_filename }} | |
53 | {% endblock data_jpg %} |
|
50 | {% endblock data_jpg %} | |
54 |
|
51 | |||
55 | {% block data_latex %} |
|
52 | {% block data_latex %} | |
56 | .. math:: |
|
53 | .. math:: | |
57 | {{ output.latex | indent }} |
|
54 | ||
|
55 | {{ output.latex | strip_dollars | indent }} | |||
58 | {% endblock data_latex %} |
|
56 | {% endblock data_latex %} | |
59 |
|
57 | |||
60 | {% block data_text scoped %} |
|
58 | {% block data_text scoped %} | |
61 | .. parsed-literal:: |
|
59 | .. parsed-literal:: | |
|
60 | ||||
62 | {{ output.text | indent }} |
|
61 | {{ output.text | indent }} | |
63 | {% endblock data_text %} |
|
62 | {% endblock data_text %} | |
64 |
|
63 | |||
|
64 | {% block data_html scoped %} | |||
|
65 | .. raw:: html | |||
|
66 | ||||
|
67 | {{ output.html | indent }} | |||
|
68 | {% endblock data_html %} | |||
|
69 | ||||
65 | {% block markdowncell scoped %} |
|
70 | {% block markdowncell scoped %} | |
66 | {{ cell.source | markdown2rst }} |
|
71 | {{ cell.source | markdown2rst }} | |
67 | {% endblock markdowncell %} |
|
72 | {% endblock markdowncell %} |
General Comments 0
You need to be logged in to leave comments.
Login now