##// END OF EJS Templates
try to play with data display priority
Matthias BUSSONNIER -
Show More
@@ -0,0 +1,45 b''
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 ->> pdf
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 b' import re'
29 from types import FunctionType
29 from types import FunctionType
30
30
31 from jinja2 import Environment, PackageLoader, FileSystemLoader
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 # IPython imports
37 # IPython imports
35 from IPython.nbformat import current as nbformat
38 from IPython.nbformat import current as nbformat
@@ -92,6 +95,14 b' def header_body():'
92 inlining= {}
95 inlining= {}
93 inlining['css'] = header_body()
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 env.filters['pycomment'] = python_comment
106 env.filters['pycomment'] = python_comment
96 env.filters['indent'] = indent
107 env.filters['indent'] = indent
97 env.filters['rm_fake'] = rm_fake
108 env.filters['rm_fake'] = rm_fake
@@ -1,10 +1,11 b''
1 #!/usr/bin/env python
1 #!/usr/bin/env python
2 # coding: utf-8
2 # coding: utf-8
3
3 from __future__ import print_function
4 from __future__ import print_function
4 import sys
5 import sys
5 import io
6 import io
6 from converters.template import *
7 from converters.template import *
7 C = ConverterTemplate(tplfile=sys.argv[1])
8 C = ConverterTemplate(tplfile=sys.argv[1])
8 C.read('tests/ipynbref/IntroNumPy.orig.ipynb')
9 C.read(sys.argv[2])
9
10
10 print(C.convert().encode('utf-8'))
11 print(C.convert().encode('utf-8'))
@@ -1,4 +1,4 b''
1 {%- extends 'null.tpl' -%}
1 {%- extends 'display_priority.tpl' -%}
2
2
3
3
4
4
@@ -68,7 +68,7 b' unknown type {{cell.type}}'
68
68
69 {% block pyout -%}
69 {% block pyout -%}
70 <div class="output_subarea output_pyout">
70 <div class="output_subarea output_pyout">
71 <pre>{{output.text | ansi2html}}</pre>
71 {% block data_priority scoped %}{{ super()}}{% endblock %}
72 </div>
72 </div>
73 {%- endblock pyout %}
73 {%- endblock pyout %}
74
74
@@ -78,13 +78,33 b' unknown type {{cell.type}}'
78 </div>
78 </div>
79 {%- endblock stream %}
79 {%- endblock stream %}
80
80
81 {% block display_data -%}
81 {% block data_svg -%}
82 <div class="output_subarea output_display_data">
83 {{output.svg}}
82 {{output.svg}}
84 </div>
83 </div>
85 {%- endblock display_data %}
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 {% block pyerr -%}
108 {% block pyerr -%}
89 <div class="output_subarea output_pyerr">
109 <div class="output_subarea output_pyerr">
90 <pre>{{super()}}</pre>
110 <pre>{{super()}}</pre>
@@ -94,3 +114,8 b' unknown type {{cell.type}}'
94 {%- block traceback_line %}
114 {%- block traceback_line %}
95 {{line| ansi2html}}
115 {{line| ansi2html}}
96 {%- endblock traceback_line %}
116 {%- endblock traceback_line %}
117
118
119 {%- block data_text %}
120 <pre>{{output.text | ansi2html}}</pre>
121 {%- endblock -%}
@@ -43,7 +43,10 b' consider calling super even if block is leave block, we might insert more block '
43 {%- elif output.output_type in ['stream'] -%}
43 {%- elif output.output_type in ['stream'] -%}
44 {%- block stream scoped -%}{%- endblock stream -%}
44 {%- block stream scoped -%}{%- endblock stream -%}
45 {%- elif output.output_type in ['display_data'] -%}
45 {%- elif output.output_type in ['display_data'] -%}
46 {%- block display_data scoped -%}{%- endblock display_data -%}
46 {%- block display_data scoped -%}
47 {%- block data_priority scoped -%}
48 {%- endblock data_priority -%}
49 {%- endblock display_data -%}
47 {%- elif output.output_type in ['pyerr'] -%}
50 {%- elif output.output_type in ['pyerr'] -%}
48 {%- block pyerr scoped -%}
51 {%- block pyerr scoped -%}
49 {%- for line in output.traceback -%}
52 {%- for line in output.traceback -%}
General Comments 0
You need to be logged in to leave comments. Login now