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