Show More
@@ -1,57 +1,65 b'' | |||||
1 | """HTML Exporter class""" |
|
1 | """HTML Exporter class""" | |
2 |
|
2 | |||
3 | # Copyright (c) IPython Development Team. |
|
3 | # Copyright (c) IPython Development Team. | |
4 | # Distributed under the terms of the Modified BSD License. |
|
4 | # Distributed under the terms of the Modified BSD License. | |
5 |
|
5 | |||
6 | import os |
|
6 | import os | |
7 |
|
7 | |||
8 | from IPython.nbconvert.filters.highlight import Highlight2HTML |
|
8 | from IPython.nbconvert.filters.highlight import Highlight2HTML | |
9 | from IPython.config import Config |
|
9 | from IPython.config import Config | |
10 |
|
10 | |||
11 | from .templateexporter import TemplateExporter |
|
11 | from .templateexporter import TemplateExporter | |
12 |
|
12 | |||
13 | #----------------------------------------------------------------------------- |
|
13 | #----------------------------------------------------------------------------- | |
14 | # Classes |
|
14 | # Classes | |
15 | #----------------------------------------------------------------------------- |
|
15 | #----------------------------------------------------------------------------- | |
16 |
|
16 | |||
17 | class HTMLExporter(TemplateExporter): |
|
17 | class HTMLExporter(TemplateExporter): | |
18 | """ |
|
18 | """ | |
19 | Exports a basic HTML document. This exporter assists with the export of |
|
19 | Exports a basic HTML document. This exporter assists with the export of | |
20 | HTML. Inherit from it if you are writing your own HTML template and need |
|
20 | HTML. Inherit from it if you are writing your own HTML template and need | |
21 | custom preprocessors/filters. If you don't need custom preprocessors/ |
|
21 | custom preprocessors/filters. If you don't need custom preprocessors/ | |
22 | filters, just change the 'template_file' config option. |
|
22 | filters, just change the 'template_file' config option. | |
23 | """ |
|
23 | """ | |
24 |
|
24 | |||
25 | def _file_extension_default(self): |
|
25 | def _file_extension_default(self): | |
26 | return '.html' |
|
26 | return '.html' | |
27 |
|
27 | |||
28 | def _default_template_path_default(self): |
|
28 | def _default_template_path_default(self): | |
29 | return os.path.join("..", "templates", "html") |
|
29 | return os.path.join("..", "templates", "html") | |
30 |
|
30 | |||
31 | def _template_file_default(self): |
|
31 | def _template_file_default(self): | |
32 | return 'full' |
|
32 | return 'full' | |
33 |
|
33 | |||
34 | output_mimetype = 'text/html' |
|
34 | output_mimetype = 'text/html' | |
35 |
|
35 | |||
36 | @property |
|
36 | @property | |
37 | def default_config(self): |
|
37 | def default_config(self): | |
38 | c = Config({ |
|
38 | c = Config({ | |
39 | 'NbConvertBase': { |
|
39 | 'NbConvertBase': { | |
40 | 'display_data_priority' : ['application/javascript', 'text/html', 'text/markdown', 'application/pdf', 'image/svg+xml', 'text/latex', 'image/png', 'image/jpeg', 'text/plain'] |
|
40 | 'display_data_priority' : ['application/javascript', | |
|
41 | 'text/html', | |||
|
42 | 'text/markdown', | |||
|
43 | 'image/svg+xml', | |||
|
44 | 'text/latex', | |||
|
45 | 'image/png', | |||
|
46 | 'image/jpeg', | |||
|
47 | 'text/plain' | |||
|
48 | ] | |||
41 | }, |
|
49 | }, | |
42 | 'CSSHTMLHeaderPreprocessor':{ |
|
50 | 'CSSHTMLHeaderPreprocessor':{ | |
43 | 'enabled':True |
|
51 | 'enabled':True | |
44 | }, |
|
52 | }, | |
45 | 'HighlightMagicsPreprocessor': { |
|
53 | 'HighlightMagicsPreprocessor': { | |
46 | 'enabled':True |
|
54 | 'enabled':True | |
47 | } |
|
55 | } | |
48 | }) |
|
56 | }) | |
49 | c.merge(super(HTMLExporter,self).default_config) |
|
57 | c.merge(super(HTMLExporter,self).default_config) | |
50 | return c |
|
58 | return c | |
51 |
|
59 | |||
52 | def from_notebook_node(self, nb, resources=None, **kw): |
|
60 | def from_notebook_node(self, nb, resources=None, **kw): | |
53 | langinfo = nb.metadata.get('language_info', {}) |
|
61 | langinfo = nb.metadata.get('language_info', {}) | |
54 | lexer = langinfo.get('pygments_lexer', langinfo.get('name', None)) |
|
62 | lexer = langinfo.get('pygments_lexer', langinfo.get('name', None)) | |
55 | self.register_filter('highlight_code', |
|
63 | self.register_filter('highlight_code', | |
56 | Highlight2HTML(pygments_lexer=lexer, parent=self)) |
|
64 | Highlight2HTML(pygments_lexer=lexer, parent=self)) | |
57 | return super(HTMLExporter, self).from_notebook_node(nb, resources, **kw) |
|
65 | return super(HTMLExporter, self).from_notebook_node(nb, resources, **kw) |
General Comments 0
You need to be logged in to leave comments.
Login now