Show More
@@ -27,8 +27,7 b' from converters.utils import markdown2rst' | |||||
27 |
|
27 | |||
28 | # Stdlib imports |
|
28 | # Stdlib imports | |
29 | import io |
|
29 | import io | |
30 | import os |
|
30 | ||
31 | from IPython.utils import path |
|
|||
32 | from IPython.utils.traitlets import MetaHasTraits |
|
31 | from IPython.utils.traitlets import MetaHasTraits | |
33 |
|
32 | |||
34 | from jinja2 import Environment, FileSystemLoader |
|
33 | from jinja2 import Environment, FileSystemLoader | |
@@ -59,50 +58,6 b' from IPython.utils.traitlets import ( Unicode, Any, List, Bool)' | |||||
59 | class ConversionException(Exception): |
|
58 | class ConversionException(Exception): | |
60 | pass |
|
59 | pass | |
61 |
|
60 | |||
62 | #todo move this out |
|
|||
63 | def header_body(): |
|
|||
64 | """Return the body of the header as a list of strings.""" |
|
|||
65 |
|
||||
66 | from pygments.formatters import HtmlFormatter |
|
|||
67 |
|
||||
68 | header = [] |
|
|||
69 | static = os.path.join(path.get_ipython_package_dir(), |
|
|||
70 | 'frontend', 'html', 'notebook', 'static', |
|
|||
71 | ) |
|
|||
72 | here = os.path.split(os.path.realpath(__file__))[0] |
|
|||
73 | css = os.path.join(static, 'css') |
|
|||
74 | for sheet in [ |
|
|||
75 | # do we need jquery and prettify? |
|
|||
76 | # os.path.join(static, 'jquery', 'css', 'themes', 'base', |
|
|||
77 | # 'jquery-ui.min.css'), |
|
|||
78 | # os.path.join(static, 'prettify', 'prettify.css'), |
|
|||
79 | os.path.join(css, 'boilerplate.css'), |
|
|||
80 | os.path.join(css, 'fbm.css'), |
|
|||
81 | os.path.join(css, 'notebook.css'), |
|
|||
82 | os.path.join(css, 'renderedhtml.css'), |
|
|||
83 | os.path.join(css, 'style.min.css'), |
|
|||
84 | # our overrides: |
|
|||
85 | os.path.join(here, '..', 'css', 'static_html.css'), |
|
|||
86 | ]: |
|
|||
87 | try: |
|
|||
88 | with io.open(sheet, encoding='utf-8') as f: |
|
|||
89 | s = f.read() |
|
|||
90 | header.append(s) |
|
|||
91 | except IOError: |
|
|||
92 | # new version of ipython with style.min.css, pass |
|
|||
93 | pass |
|
|||
94 |
|
||||
95 | pygments_css = HtmlFormatter().get_style_defs('.highlight') |
|
|||
96 | header.append(pygments_css) |
|
|||
97 | return header |
|
|||
98 |
|
||||
99 |
|
||||
100 |
|
||||
101 |
|
||||
102 |
|
||||
103 | inlining = {} |
|
|||
104 | inlining['css'] = header_body() |
|
|||
105 |
|
||||
106 |
|
61 | |||
107 |
|
62 | |||
108 | texenv.block_start_string = '((*' |
|
63 | texenv.block_start_string = '((*' | |
@@ -176,6 +131,7 b' class ConverterTemplate(Configurable):' | |||||
176 | ## for compat, remove later |
|
131 | ## for compat, remove later | |
177 | self.preprocessors.append(trans.ExtractFigureTransformer(config=config)) |
|
132 | self.preprocessors.append(trans.ExtractFigureTransformer(config=config)) | |
178 | self.preprocessors.append(trans.RevealHelpTransformer(config=config)) |
|
133 | self.preprocessors.append(trans.RevealHelpTransformer(config=config)) | |
|
134 | self.preprocessors.append(trans.CSSHtmlHeaderTransformer(config=config)) | |||
179 |
|
135 | |||
180 | ## |
|
136 | ## | |
181 | self.env.filters['filter_data_type'] = FilterDataType(config=config) |
|
137 | self.env.filters['filter_data_type'] = FilterDataType(config=config) | |
@@ -219,7 +175,7 b' class ConverterTemplate(Configurable):' | |||||
219 | other resources |
|
175 | other resources | |
220 | """ |
|
176 | """ | |
221 | nb, resources = self.process(nb) |
|
177 | nb, resources = self.process(nb) | |
222 |
return self.template.render(nb=nb, |
|
178 | return self.template.render(nb=nb, resources=resources), resources | |
223 |
|
179 | |||
224 |
|
180 | |||
225 | def from_filename(self, filename): |
|
181 | def from_filename(self, filename): | |
@@ -228,3 +184,4 b' class ConverterTemplate(Configurable):' | |||||
228 | return self.convert(nbformat.read(f, 'json')) |
|
184 | return self.convert(nbformat.read(f, 'json')) | |
229 |
|
185 | |||
230 |
|
186 | |||
|
187 |
@@ -2,13 +2,13 b'' | |||||
2 |
|
2 | |||
3 | """ |
|
3 | """ | |
4 |
|
4 | |||
5 |
from __future__ import print_function |
|
5 | from __future__ import print_function | |
|
6 | ||||
6 |
|
7 | |||
7 | from IPython.config.configurable import Configurable |
|
8 | from IPython.config.configurable import Configurable | |
8 | from IPython.utils.traitlets import Unicode, Bool, Dict, List |
|
9 | from IPython.utils.traitlets import Unicode, Bool, Dict, List | |
9 | from .jinja_filters import GlobalConfigurable |
|
|||
10 |
|
10 | |||
11 |
class ConfigurableTransformers( |
|
11 | class ConfigurableTransformers(Configurable): | |
12 | """ A configurable transformer """ |
|
12 | """ A configurable transformer """ | |
13 |
|
13 | |||
14 | def __init__(self, config=None, **kw): |
|
14 | def __init__(self, config=None, **kw): | |
@@ -85,6 +85,15 b' class ExtractFigureTransformer(ActivatableTransformer):' | |||||
85 | Usefull for latex where svg will be converted to pdf before inclusion |
|
85 | Usefull for latex where svg will be converted to pdf before inclusion | |
86 | """ |
|
86 | """ | |
87 | ) |
|
87 | ) | |
|
88 | display_data_priority = List(['html', 'pdf', 'svg', 'latex', 'png', 'jpg', 'jpeg' , 'text'], | |||
|
89 | config=True, | |||
|
90 | help= """ | |||
|
91 | An ordered list of prefered output type, the first | |||
|
92 | encounterd will usually be used when converting discarding | |||
|
93 | the others. | |||
|
94 | """ | |||
|
95 | ) | |||
|
96 | ||||
88 |
|
97 | |||
89 | #to do change this to .format {} syntax |
|
98 | #to do change this to .format {} syntax | |
90 | key_tpl = Unicode('_fig_%02i.%s', config=True) |
|
99 | key_tpl = Unicode('_fig_%02i.%s', config=True) | |
@@ -223,3 +232,62 b' class RevealHelpTransformer(ConfigurableTransformers):' | |||||
223 | cell.metadata.slideshow.open_fragment = False |
|
232 | cell.metadata.slideshow.open_fragment = False | |
224 | return cell,other |
|
233 | return cell,other | |
225 |
|
234 | |||
|
235 | ||||
|
236 | class CSSHtmlHeaderTransformer(ActivatableTransformer): | |||
|
237 | ||||
|
238 | def __call__(self, nb, resources): | |||
|
239 | """Fetch and add css to the resource dict | |||
|
240 | ||||
|
241 | Fetch css from IPython adn Pygment to add at the beginning | |||
|
242 | of the html files. | |||
|
243 | ||||
|
244 | Add this css in resources in the "inlining.css" key | |||
|
245 | """ | |||
|
246 | resources['inlining']= {} | |||
|
247 | resources['inlining']['css'] = self.header | |||
|
248 | return nb, resources | |||
|
249 | ||||
|
250 | header= [] | |||
|
251 | ||||
|
252 | def __init__(self, config=None, **kw): | |||
|
253 | super(CSSHtmlHeaderTransformer,self).__init__(config=config, **kw) | |||
|
254 | if self.enabled : | |||
|
255 | self.regen_header() | |||
|
256 | ||||
|
257 | def regen_header(self): | |||
|
258 | ## lazy load asa this might not be use in many transformers | |||
|
259 | import os | |||
|
260 | from IPython.utils import path | |||
|
261 | import io | |||
|
262 | from pygments.formatters import HtmlFormatter | |||
|
263 | header = [] | |||
|
264 | static = os.path.join(path.get_ipython_package_dir(), | |||
|
265 | 'frontend', 'html', 'notebook', 'static', | |||
|
266 | ) | |||
|
267 | here = os.path.split(os.path.realpath(__file__))[0] | |||
|
268 | css = os.path.join(static, 'css') | |||
|
269 | for sheet in [ | |||
|
270 | # do we need jquery and prettify? | |||
|
271 | # os.path.join(static, 'jquery', 'css', 'themes', 'base', | |||
|
272 | # 'jquery-ui.min.css'), | |||
|
273 | # os.path.join(static, 'prettify', 'prettify.css'), | |||
|
274 | os.path.join(css, 'boilerplate.css'), | |||
|
275 | os.path.join(css, 'fbm.css'), | |||
|
276 | os.path.join(css, 'notebook.css'), | |||
|
277 | os.path.join(css, 'renderedhtml.css'), | |||
|
278 | os.path.join(css, 'style.min.css'), | |||
|
279 | # our overrides: | |||
|
280 | os.path.join(here, '..', 'css', 'static_html.css'), | |||
|
281 | ]: | |||
|
282 | try: | |||
|
283 | with io.open(sheet, encoding='utf-8') as f: | |||
|
284 | s = f.read() | |||
|
285 | header.append(s) | |||
|
286 | except IOError: | |||
|
287 | # new version of ipython with style.min.css, pass | |||
|
288 | pass | |||
|
289 | ||||
|
290 | pygments_css = HtmlFormatter().get_style_defs('.highlight') | |||
|
291 | header.append(pygments_css) | |||
|
292 | self.header = header | |||
|
293 |
@@ -8,3 +8,4 b' c.ConverterTemplate.tex_environement=False' | |||||
8 | c.NbconvertApp.fileext='html' |
|
8 | c.NbconvertApp.fileext='html' | |
9 |
|
9 | |||
10 | c.ExtractFigureTransformer.enabled = False |
|
10 | c.ExtractFigureTransformer.enabled = False | |
|
11 | c.CSSHtmlHeaderTransformer.enabled=True |
@@ -1,9 +1,5 b'' | |||||
1 | c = get_config() |
|
1 | c = get_config() | |
2 |
|
2 | load_subconfig('base_html.nbcv') | ||
3 |
|
3 | |||
4 | c.ConverterTemplate.template_file='fullhtml' |
|
4 | c.ConverterTemplate.template_file='fullhtml' | |
5 | c.ConverterTemplate.tex_environement=False |
|
|||
6 |
|
||||
7 | c.NbconvertApp.fileext='html' |
|
|||
8 |
|
5 | |||
9 | c.ExtractFigureTransformer.enabled = False |
|
@@ -5,7 +5,7 b'' | |||||
5 | <head> |
|
5 | <head> | |
6 | <meta charset="UTF-8"> |
|
6 | <meta charset="UTF-8"> | |
7 | <title>[{{nb.metadata.name}}]</title> |
|
7 | <title>[{{nb.metadata.name}}]</title> | |
8 | {% for css in inlining.css -%} |
|
8 | {% for css in resources.inlining.css -%} | |
9 | <style type="text/css"> |
|
9 | <style type="text/css"> | |
10 | {{css}} |
|
10 | {{css}} | |
11 | </style> |
|
11 | </style> |
@@ -104,7 +104,7 b' document.write( \'<link rel="stylesheet" href="reveal/css/print/\' + ( window.loca' | |||||
104 | <script src="reveal/lib/js/html5shiv.js"></script> |
|
104 | <script src="reveal/lib/js/html5shiv.js"></script> | |
105 | <![endif]--> |
|
105 | <![endif]--> | |
106 |
|
106 | |||
107 | {% for css in inlining.css -%} |
|
107 | {% for css in resources.inlining.css -%} | |
108 | <style type="text/css"> |
|
108 | <style type="text/css"> | |
109 | {{css}} |
|
109 | {{css}} | |
110 | </style> |
|
110 | </style> |
General Comments 0
You need to be logged in to leave comments.
Login now