diff --git a/notebook/static/base/js/markdown.js b/notebook/static/base/js/markdown.js new file mode 100644 index 0000000000..94b8850140 --- /dev/null +++ b/notebook/static/base/js/markdown.js @@ -0,0 +1,117 @@ +// Copyright (c) Jupyter Development Team. +// Distributed under the terms of the Modified BSD License. + +define([ + 'jquery', + 'base/js/utils', + 'base/js/mathjaxutils', + 'base/js/security', + 'components/marked/lib/marked', + 'codemirror/lib/codemirror', +], function($, utils, mathjaxutils, security, marked, CodeMirror){ + "use strict"; + + marked.setOptions({ + gfm : true, + tables: true, + langPrefix: "cm-s-ipython language-", + highlight: function(code, lang, callback) { + if (!lang) { + // no language, no highlight + if (callback) { + callback(null, code); + return; + } else { + return code; + } + } + utils.requireCodeMirrorMode(lang, function (spec) { + var el = document.createElement("div"); + var mode = CodeMirror.getMode({}, spec); + if (!mode) { + console.log("No CodeMirror mode: " + lang); + callback(null, code); + return; + } + try { + CodeMirror.runMode(code, spec, el); + callback(null, el.innerHTML); + } catch (err) { + console.log("Failed to highlight " + lang + " code", err); + callback(err, code); + } + }, function (err) { + console.log("No CodeMirror mode: " + lang); + console.log("Require CodeMirror mode error: " + err); + callback(null, code); + }); + } + }); + + var mathjax_init_done = false; + function ensure_mathjax_init() { + if(!mathjax_init_done) { + mathjax_init_done = true; + mathjaxutils.init(); + } + } + + function render(markdown, options, callback) { + /** + * Find a readme in the current directory. Look for files with + * a name like 'readme.md' (case insensitive) or similar and + * mimetype 'text/markdown'. + * + * @param markdown: the markdown text to parse + * @param options + * Object with parameters: + * with_math: the markdown can contain mathematics + * clean_tables: prevent default inline styles for table cells + * sanitize: remove dangerous html (like +{% endif %} + + + + +{{super()}} + +{% endblock %} + {% block title %}{{page_title}}{% endblock %} @@ -142,6 +159,7 @@ +
diff --git a/notebook/tests/notebook/markdown.js b/notebook/tests/notebook/markdown.js index 202379f0a0..c2341ccfb1 100644 --- a/notebook/tests/notebook/markdown.js +++ b/notebook/tests/notebook/markdown.js @@ -112,7 +112,7 @@ casper.notebook_test(function () { function mathjax_render_test(input_string, result, message){ casper.thenEvaluate(function (text){ window._test_result = null; - require(['notebook/js/mathjaxutils'],function(mathjaxutils){ + require(['base/js/mathjaxutils'],function(mathjaxutils){ window._test_result = mathjaxutils.remove_math(text); }); }, {text: input_string}); diff --git a/notebook/tree/handlers.py b/notebook/tree/handlers.py index bb4958d289..ea5a4ee3e1 100644 --- a/notebook/tree/handlers.py +++ b/notebook/tree/handlers.py @@ -51,7 +51,9 @@ def get(self, path=''): breadcrumbs=breadcrumbs, terminals_available=self.settings['terminals_available'], server_root=self.settings['server_root_dir'], - shutdown_button=self.settings.get('shutdown_button', False) + shutdown_button=self.settings.get('shutdown_button', False), + mathjax_url=self.mathjax_url, + mathjax_config=self.mathjax_config )) elif cm.file_exists(path): # it's not a directory, we have redirecting to do