Show More
@@ -0,0 +1,45 | |||
|
1 | {%- extends 'null.tpl' -%} | |
|
2 | ||
|
3 | {#display data priority#} | |
|
4 | ||
|
5 | ||
|
6 | {%- block data_priority scoped -%} | |
|
7 | {%- for type in output | filter_data_type -%} | |
|
8 | {%- if type in ['pdf']%} | |
|
9 | {%- block data_pdf -%} | |
|
10 | ||
|
11 | {%- endblock -%} | |
|
12 | {%- endif -%} | |
|
13 | {%- if type in ['svg']%} | |
|
14 | {%- block data_svg -%} | |
|
15 | ->> svg | |
|
16 | {%- endblock -%} | |
|
17 | {%- endif -%} | |
|
18 | {%- if type in ['png']%} | |
|
19 | {%- block data_png -%} | |
|
20 | ->> png | |
|
21 | {%- endblock -%} | |
|
22 | {%- endif -%} | |
|
23 | {%- if type in ['html']%} | |
|
24 | {%- block data_html -%} | |
|
25 | ->> html | |
|
26 | {%- endblock -%} | |
|
27 | {%- endif -%} | |
|
28 | {%- if type in ['jpeg']%} | |
|
29 | {%- block data_jpg -%} | |
|
30 | ->> jpg | |
|
31 | {%- endblock -%} | |
|
32 | {%- endif -%} | |
|
33 | {%- if type in ['text']%} | |
|
34 | {%- block data_text -%} | |
|
35 | ->> text | |
|
36 | {%- endblock -%} | |
|
37 | {%- endif -%} | |
|
38 | ||
|
39 | {%- if type in ['latex']%} | |
|
40 | {%- block data_latex -%} | |
|
41 | ->> latext | |
|
42 | {%- endblock -%} | |
|
43 | {%- endif -%} | |
|
44 | {%- endfor -%} | |
|
45 | {%- endblock data_priority -%} |
@@ -29,7 +29,10 import re | |||
|
29 | 29 | from types import FunctionType |
|
30 | 30 | |
|
31 | 31 | from jinja2 import Environment, PackageLoader, FileSystemLoader |
|
32 | env = Environment(loader=FileSystemLoader('./templates/')) | |
|
32 | env = Environment( | |
|
33 | loader=FileSystemLoader('./templates/'), | |
|
34 | extensions=['jinja2.ext.loopcontrols'] | |
|
35 | ) | |
|
33 | 36 | |
|
34 | 37 | # IPython imports |
|
35 | 38 | from IPython.nbformat import current as nbformat |
@@ -92,6 +95,14 def header_body(): | |||
|
92 | 95 | inlining= {} |
|
93 | 96 | inlining['css'] = header_body() |
|
94 | 97 | |
|
98 | ||
|
99 | def filter_data_type(output): | |
|
100 | for fmt in ['html', 'pdf', 'svg', 'latex','png', 'jpg','jpeg' , 'text']: | |
|
101 | if fmt in output: | |
|
102 | return [fmt] | |
|
103 | ||
|
104 | ||
|
105 | env.filters['filter_data_type'] = filter_data_type | |
|
95 | 106 | env.filters['pycomment'] = python_comment |
|
96 | 107 | env.filters['indent'] = indent |
|
97 | 108 | env.filters['rm_fake'] = rm_fake |
@@ -1,10 +1,11 | |||
|
1 | 1 | #!/usr/bin/env python |
|
2 | 2 | # coding: utf-8 |
|
3 | ||
|
3 | 4 | from __future__ import print_function |
|
4 | 5 | import sys |
|
5 | 6 | import io |
|
6 | 7 | from converters.template import * |
|
7 | 8 | C = ConverterTemplate(tplfile=sys.argv[1]) |
|
8 | C.read('tests/ipynbref/IntroNumPy.orig.ipynb') | |
|
9 | C.read(sys.argv[2]) | |
|
9 | 10 | |
|
10 | 11 | print(C.convert().encode('utf-8')) |
@@ -1,4 +1,4 | |||
|
1 |
{%- extends ' |
|
|
1 | {%- extends 'display_priority.tpl' -%} | |
|
2 | 2 | |
|
3 | 3 | |
|
4 | 4 | |
@@ -68,7 +68,7 unknown type {{cell.type}} | |||
|
68 | 68 | |
|
69 | 69 | {% block pyout -%} |
|
70 | 70 | <div class="output_subarea output_pyout"> |
|
71 | <pre>{{output.text | ansi2html}}</pre> | |
|
71 | {% block data_priority scoped %}{{ super()}}{% endblock %} | |
|
72 | 72 | </div> |
|
73 | 73 | {%- endblock pyout %} |
|
74 | 74 | |
@@ -78,13 +78,33 unknown type {{cell.type}} | |||
|
78 | 78 | </div> |
|
79 | 79 | {%- endblock stream %} |
|
80 | 80 | |
|
81 |
{% block |
|
|
82 | <div class="output_subarea output_display_data"> | |
|
81 | {% block data_svg -%} | |
|
83 | 82 | {{output.svg}} |
|
84 | 83 | </div> |
|
85 |
{%- endblock |
|
|
84 | {%- endblock data_svg %} | |
|
86 | 85 | |
|
87 | 86 | |
|
87 | {% block data_html %} | |
|
88 | {{output.html}} | |
|
89 | </div> | |
|
90 | {%- endblock data_html %} | |
|
91 | ||
|
92 | {% block data_png %} | |
|
93 | <img src="data:image/png;base64,{{output.png}}"></img> | |
|
94 | </div> | |
|
95 | {%- endblock data_png %} | |
|
96 | ||
|
97 | ||
|
98 | {% block data_jpg %} | |
|
99 | <img src="data:image/jpeg;base64,{{output.jpeg}}"></img> | |
|
100 | </div> | |
|
101 | {%- endblock data_jpg %} | |
|
102 | ||
|
103 | ||
|
104 | {% block data_latex %} | |
|
105 | {{output.latex}} | |
|
106 | {%- endblock data_latex %} | |
|
107 | ||
|
88 | 108 | {% block pyerr -%} |
|
89 | 109 | <div class="output_subarea output_pyerr"> |
|
90 | 110 | <pre>{{super()}}</pre> |
@@ -94,3 +114,8 unknown type {{cell.type}} | |||
|
94 | 114 | {%- block traceback_line %} |
|
95 | 115 | {{line| ansi2html}} |
|
96 | 116 | {%- endblock traceback_line %} |
|
117 | ||
|
118 | ||
|
119 | {%- block data_text %} | |
|
120 | <pre>{{output.text | ansi2html}}</pre> | |
|
121 | {%- endblock -%} |
@@ -43,7 +43,10 consider calling super even if block is leave block, we might insert more block | |||
|
43 | 43 | {%- elif output.output_type in ['stream'] -%} |
|
44 | 44 | {%- block stream scoped -%}{%- endblock stream -%} |
|
45 | 45 | {%- elif output.output_type in ['display_data'] -%} |
|
46 |
{%- block display_data scoped -%} |
|
|
46 | {%- block display_data scoped -%} | |
|
47 | {%- block data_priority scoped -%} | |
|
48 | {%- endblock data_priority -%} | |
|
49 | {%- endblock display_data -%} | |
|
47 | 50 | {%- elif output.output_type in ['pyerr'] -%} |
|
48 | 51 | {%- block pyerr scoped -%} |
|
49 | 52 | {%- for line in output.traceback -%} |
General Comments 0
You need to be logged in to leave comments.
Login now