Show More
@@ -425,14 +425,17 b' class MarkupRenderer(object):' | |||||
425 | def jupyter(cls, source, safe=True): |
|
425 | def jupyter(cls, source, safe=True): | |
426 | from rhodecode.lib import helpers |
|
426 | from rhodecode.lib import helpers | |
427 |
|
427 | |||
428 |
from traitlets |
|
428 | from traitlets import default, config | |
429 | import nbformat |
|
429 | import nbformat | |
430 | from nbconvert import HTMLExporter |
|
430 | from nbconvert import HTMLExporter | |
431 | from nbconvert.preprocessors import Preprocessor |
|
431 | from nbconvert.preprocessors import Preprocessor | |
432 |
|
432 | |||
433 | class CustomHTMLExporter(HTMLExporter): |
|
433 | class CustomHTMLExporter(HTMLExporter): | |
|
434 | ||||
|
435 | @default("template_file") | |||
434 | def _template_file_default(self): |
|
436 | def _template_file_default(self): | |
435 | return 'basic' |
|
437 | if self.template_extension: | |
|
438 | return "basic/index" + self.template_extension | |||
436 |
|
439 | |||
437 | class Sandbox(Preprocessor): |
|
440 | class Sandbox(Preprocessor): | |
438 |
|
441 | |||
@@ -458,7 +461,7 b' class MarkupRenderer(object):' | |||||
458 | def _sanitize_resources(input_resources): |
|
461 | def _sanitize_resources(input_resources): | |
459 | """ |
|
462 | """ | |
460 | Skip/sanitize some of the CSS generated and included in jupyter |
|
463 | Skip/sanitize some of the CSS generated and included in jupyter | |
461 |
so it doesn't mess |
|
464 | so it doesn't mess up UI so much | |
462 | """ |
|
465 | """ | |
463 |
|
466 | |||
464 | # TODO(marcink): probably we should replace this with whole custom |
|
467 | # TODO(marcink): probably we should replace this with whole custom | |
@@ -471,11 +474,12 b' class MarkupRenderer(object):' | |||||
471 | return input_resources |
|
474 | return input_resources | |
472 |
|
475 | |||
473 | def as_html(notebook): |
|
476 | def as_html(notebook): | |
474 | conf = Config() |
|
477 | conf = config.Config() | |
475 | conf.CustomHTMLExporter.preprocessors = [Sandbox] |
|
478 | conf.CustomHTMLExporter.preprocessors = [Sandbox] | |
476 | html_exporter = CustomHTMLExporter(config=conf) |
|
479 | html_exporter = CustomHTMLExporter(config=conf) | |
477 |
|
480 | |||
478 | (body, resources) = html_exporter.from_notebook_node(notebook) |
|
481 | (body, resources) = html_exporter.from_notebook_node(notebook) | |
|
482 | ||||
479 | header = '<!-- ## IPYTHON NOTEBOOK RENDERING ## -->' |
|
483 | header = '<!-- ## IPYTHON NOTEBOOK RENDERING ## -->' | |
480 | js = MakoTemplate(r''' |
|
484 | js = MakoTemplate(r''' | |
481 | <!-- MathJax configuration --> |
|
485 | <!-- MathJax configuration --> | |
@@ -514,7 +518,7 b' class MarkupRenderer(object):' | |||||
514 | body = '\n'.join([header, css, js, body]) |
|
518 | body = '\n'.join([header, css, js, body]) | |
515 | return body, resources |
|
519 | return body, resources | |
516 |
|
520 | |||
517 |
notebook = nbformat.reads(source, as_version= |
|
521 | notebook = nbformat.reads(source, as_version=nbformat.NO_CONVERT) | |
518 | (body, resources) = as_html(notebook) |
|
522 | (body, resources) = as_html(notebook) | |
519 | return body |
|
523 | return body | |
520 |
|
524 |
General Comments 0
You need to be logged in to leave comments.
Login now