##// END OF EJS Templates
jupyter-rendering: added a custom preprocessor to implement Javascript object...
marcink -
r1495:4a485783 default
parent child Browse files
Show More
@@ -268,16 +268,31 b' class MarkupRenderer(object):'
268 268 raise
269 269
270 270 @classmethod
271 def jupyter(cls, source):
271 def jupyter(cls, source, safe=True):
272 272 from rhodecode.lib import helpers
273
274 from traitlets.config import Config
273 275 import nbformat
274 276 from nbconvert import HTMLExporter
275 from traitlets.config import Config
277 from nbconvert.preprocessors import Preprocessor
276 278
277 279 class CustomHTMLExporter(HTMLExporter):
278 280 def _template_file_default(self):
279 281 return 'basic'
280 282
283 class Sandbox(Preprocessor):
284
285 def preprocess(self, nb, resources):
286 sandbox_text = 'SandBoxed(IPython.core.display.Javascript object)'
287 for cell in nb['cells']:
288 if safe and 'outputs' in cell:
289 for cell_output in cell['outputs']:
290 if 'data' in cell_output:
291 if 'application/javascript' in cell_output['data']:
292 cell_output['data']['text/plain'] = sandbox_text
293 cell_output['data'].pop('application/javascript', None)
294 return nb, resources
295
281 296 def _sanitize_resources(resources):
282 297 """
283 298 Skip/sanitize some of the CSS generated and included in jupyter
@@ -295,6 +310,7 b' class MarkupRenderer(object):'
295 310
296 311 def as_html(notebook):
297 312 conf = Config()
313 conf.CustomHTMLExporter.preprocessors = [Sandbox]
298 314 html_exporter = CustomHTMLExporter(config=conf)
299 315
300 316 (body, resources) = html_exporter.from_notebook_node(notebook)
General Comments 0
You need to be logged in to leave comments. Login now