##// END OF EJS Templates
fix fileext and html multidisplay
Matthias BUSSONNIER -
Show More
@@ -1,8 +1,10 b''
1 1 c = get_config()
2 2
3 3
4 4 c.ConverterTemplate.extract_figures=False
5 5 c.ConverterTemplate.template_file='basichtml'
6 6 c.ConverterTemplate.tex_environement=False
7 7
8 c.NbconvertApp.fileext='html'
9
8 10 c.ExtractFigureTransformer.enabled = False
@@ -1,8 +1,10 b''
1 1 c = get_config()
2 2
3 3
4 4 c.ConverterTemplate.extract_figures=False
5 5 c.ConverterTemplate.template_file='fullhtml'
6 6 c.ConverterTemplate.tex_environement=False
7 7
8 c.NbconvertApp.fileext='html'
9
8 10 c.ExtractFigureTransformer.enabled = False
@@ -1,10 +1,11 b''
1 1 c = get_config()
2 2
3 3 c.ConverterTemplate.extract_figures=True
4 4 c.ConverterTemplate.template_file='latex_base'
5 5 c.ConverterTemplate.tex_environement=True
6 6 c.ConverterTemplate.display_data_priority=['latex', 'svg', 'png', 'jpg', 'jpeg' , 'text']
7 7 c.ExtractFigureTransformer.display_data_priority=['latex', 'svg', 'png', 'jpg', 'jpeg']
8 c.NbconvertApp.fileext='tex'
8 9
9 10 c.ExtractFigureTransformer.extra_ext_map={'svg':'pdf'}
10 11 c.ExtractFigureTransformer.enabled=True
@@ -1,5 +1,7 b''
1 1 c = get_config()
2 2
3 3 c.ConverterTemplate.extract_figures=False
4 4 c.ConverterTemplate.template_file='python'
5 5 c.ConverterTemplate.tex_environement=False
6
7 c.NbconvertApp.fileext='py'
@@ -1,135 +1,137 b''
1 1 #!/usr/bin/env python
2 2 """
3 3 ================================================================================
4 4
5 5 |,---. | | , .| |
6 6 ||---', .|--- |---.,---.,---. |\ ||---.,---.,---.,---.. ,,---.,---.|---
7 7 || | || | || || | | \ || || | || | \ / |---'| |
8 8 `` `---|`---'` '`---'` ' ` `'`---'`---'`---'` ' `' `---'` `---'
9 9 `---'
10 10 ================================================================================
11 11
12 12 Highly experimental for now
13 13
14 14 """
15 15 #-----------------------------------------------------------------------------
16 16 # Imports
17 17 #-----------------------------------------------------------------------------
18 18 from __future__ import print_function
19 19 import sys
20 20 import io
21 21 import os
22 22
23 23 from converters.template import *
24 24 from converters.template import ConverterTemplate
25 25 from converters.html import ConverterHTML
26 26 # From IPython
27 27
28 28 # All the stuff needed for the configurable things
29 29 from IPython.config.application import Application
30 30 from IPython.config.loader import ConfigFileNotFound
31 31 from IPython.utils.traitlets import List, Unicode, Type, Bool, Dict, CaselessStrEnum
32 32
33 33 from converters.transformers import (ConfigurableTransformers,Foobar,ExtractFigureTransformer)
34 34
35 35
36 36 class NbconvertApp(Application):
37 37
38 38 stdout = Bool(True, config=True)
39 39 write = Bool(False, config=True)
40 40
41 fileext = Unicode('txt', config=True)
42
41 43 aliases = {
42 44 'stdout':'NbconvertApp.stdout',
43 45 'write':'NbconvertApp.write',
44 46 }
45 47
46 48 flags= {}
47 49 flags['no-stdout'] = (
48 50 {'NbconvertApp' : {'stdout' : False}},
49 51 """the doc for this flag
50 52
51 53 """
52 54 )
53 55
54 56 def __init__(self, **kwargs):
55 57 super(NbconvertApp, self).__init__(**kwargs)
56 58 self.classes.insert(0,ConverterTemplate)
57 59 # register class here to have help with help all
58 60 self.classes.insert(0,ExtractFigureTransformer)
59 61 self.classes.insert(0,Foobar)
60 62 # ensure those are registerd
61 63
62 64 def load_config_file(self, profile_name):
63 65 try:
64 66 Application.load_config_file(
65 67 self,
66 68 profile_name+'.nbcv',
67 69 path=[os.path.join(os.getcwdu(),'profile')]
68 70 )
69 71 except ConfigFileNotFound:
70 72 self.log.warn("Config file for profile '%s' not found, giving up ",profile_name)
71 73 exit(1)
72 74
73 75
74 76 def initialize(self, argv=None):
75 77 self.parse_command_line(argv)
76 78 cl_config = self.config
77 79 profile_file = sys.argv[1]
78 80 self.load_config_file(profile_file)
79 81 self.update_config(cl_config)
80 82
81 83
82 84
83 85 def run(self):
84 86 """Convert a notebook to html in one step"""
85 87 template_file = (self.extra_args or [None])[0]
86 88 ipynb_file = (self.extra_args or [None])[1]
87 89
88 90 template_file = sys.argv[1]
89 91
90 92 C = ConverterTemplate(config=self.config)
91 93 C.read(ipynb_file)
92 94
93 95 output,resources = C.convert()
94 96 if self.stdout :
95 97 print(output.encode('utf-8'))
96 98
97 99 out_root = ipynb_file[:-6].replace('.','_').replace(' ','_')
98 100
99 101 keys = resources.keys()
100 102 if self.write :
101 with io.open(os.path.join(out_root+'.'+'ext'),'w') as f:
103 with io.open(os.path.join(out_root+'.'+self.fileext),'w') as f:
102 104 f.write(output)
103 105 if keys :
104 106 if self.write and not os.path.exists(out_root+'_files'):
105 107 os.mkdir(out_root+'_files')
106 108 for key in keys:
107 109 if self.write:
108 110 with io.open(os.path.join(out_root+'_files',key),'wb') as f:
109 111 print(' writing to ',os.path.join(out_root,key))
110 112 f.write(resources[key])
111 113 if self.stdout:
112 114 print('''
113 115 ====================== Keys in Resources ==================================
114 116 ''')
115 117 print(resources.keys())
116 118 print("""
117 119 ===========================================================================
118 120 you are responsible from writing those data do a file in the right place if
119 121 they need to be.
120 122 ===========================================================================
121 123 """)
122 124
123 125 def main():
124 126 """Convert a notebook to html in one step"""
125 127 app = NbconvertApp.instance()
126 128 app.description = __doc__
127 129 app.initialize()
128 130 app.start()
129 131 app.run()
130 132 #-----------------------------------------------------------------------------
131 133 # Script main
132 134 #-----------------------------------------------------------------------------
133 135
134 136 if __name__ == '__main__':
135 137 main()
@@ -1,132 +1,147 b''
1 1 {%- extends 'display_priority.tpl' -%}
2 2
3 3
4 4
5 5 {% block codecell %}
6 6 <div class="cell border-box-sizing code_cell vbox">
7 7 {{ super() }}</div>
8 8 {%- endblock codecell %}
9 9
10 10 {% block input_group -%}
11 11 <div class="input hbox">
12 12 {{super()}}
13 13 </div>
14 14 {% endblock input_group %}
15 15
16 16 {% block output_group -%}
17 <div class="vbox output_wrapper">
17 <div class="output_wrapper">
18 18 <div class="output vbox">
19 <div class="hbox output_area">
20 19 {{ super() }}
21 20 </div>
22 21 </div>
23 </div>
24 22 {% endblock output_group %}
25 23
26 24
27 25 {% block in_prompt -%}
28 26 <div class="prompt input_prompt">In&nbsp;[{{cell.prompt_number}}]:</div>
29 27 {%- endblock in_prompt %}
30 28
31 29 {% block output_prompt -%}
32 30 <div class="prompt output_prompt">
31 <div class="output vbox">
33 32 {%- if cell.haspyout -%}
34 33 Out[{{cell.prompt_number}}]:
35 34 {%- endif -%}
36 35 </div>
36 </div>
37 37 {% endblock output_prompt %}
38 38
39 39 {% block input %}
40 40 <div class="input_area box-flex1">
41 41 {{cell.input | highlight }}
42 42 </div>
43 43 {%- endblock input %}
44 44
45 45
46 46 {% block markdowncell scoped %}
47 47 <div class="text_cell_render border-box-sizing rendered_html">
48 48 {{ cell.source | markdown| rm_fake}}
49 49 </div>
50 50 {%- endblock markdowncell %}
51 51
52 52 {% block headingcell scoped %}
53 53 <div class="text_cell_render border-box-sizing rendered_html">
54 54 <h{{cell.level}}>
55 55 {{cell.source}}
56 56 </h{{cell.level}}>
57 57 </div>
58 58 {% endblock headingcell %}
59 59
60 60 {% block rawcell scoped %}
61 61 {{ cell.source }}
62 62 {% endblock rawcell %}
63 63
64 64 {% block unknowncell scoped %}
65 65 unknown type {{cell.type}}
66 66 {% endblock unknowncell %}
67 67
68 68
69 69 {% block pyout -%}
70 <div class="output_subarea output_pyout">
70 <div class="hbox output_area">
71 <div class="prompt"></div>
72 <div class="box-flex1 output_subarea output_pyout">
71 73 {% block data_priority scoped %}{{ super()}}{% endblock %}
72 74 </div>
75 </div>
73 76 {%- endblock pyout %}
74 77
75 78 {% block stream_stdout -%}
76 <div class="output_subarea output_stream output_stdout">
79 <div class="hbox output_area">
80 <div class="prompt"></div>
81 <div class="box-flex1 output_subarea output_stream output_stdout">
77 82 <pre>{{output.text |ansi2html}}</pre>
78 83 </div>
84 </div>
79 85 {%- endblock stream_stdout %}
80 86
81 87 {% block stream_stderr -%}
82 <div class="output_subarea output_stream output_stderr">
88 <div class="hbox output_area">
89 <div class="prompt"></div>
90 <div class="box-flex1 output_subarea output_stream output_stderr">
83 91 <pre>{{output.text |ansi2html}}</pre>
84 92 </div>
93 </div>
85 94 {%- endblock stream_stderr %}
86 95
87 96 {% block data_svg -%}
88 97 {{output.svg}}
89 98 {%- endblock data_svg %}
90 99
91 100
92 101 {% block data_html -%}
93 102 <div class="output_html rendered_html">
94 103 {{output.html}}
95 104 </div>
96 105 {%- endblock data_html %}
97 106
98 107 {% block data_png %}
99 108 <img src="data:image/png;base64,{{output.png}}"></img>
100 109 {%- endblock data_png %}
101 110
102 111
103 112 {% block data_jpg %}
104 113 <img src="data:image/jpeg;base64,{{output.jpeg}}"></img>
105 114 {%- endblock data_jpg %}
106 115
107 116
108 117 {% block data_latex %}
109 118 {{output.latex}}
110 119 {%- endblock data_latex %}
111 120
112 121 {% block pyerr -%}
113 <div class="output_subarea output_pyerr">
122 <div class="hbox output_area">
123 <div class="prompt"></div>
124 <div class="box-flex1 output_subarea output_pyerr">
114 125 <pre>{{super()}}</pre>
115 126 </div>
127 </div>
116 128 {%- endblock pyerr %}
117 129
118 130 {%- block traceback_line %}
119 131 {{line| ansi2html}}
120 132 {%- endblock traceback_line %}
121 133
122 134
123 135 {%- block data_text %}
124 136 <pre>{{output.text | ansi2html}}</pre>
125 137 {%- endblock -%}
126 138
127 139
128 140 {%- block display_data scoped -%}
129 <div class="output_subarea output_display_data">
141 <div class="hbox output_area">
142 <div class="prompt"></div>
143 <div class="box-flex1 output_subarea output_display_data">
130 144 {{super()}}
131 145 </div>
146 </div>
132 147 {%- endblock display_data -%}
General Comments 0
You need to be logged in to leave comments. Login now