diff --git a/notebook/static/base/js/markdown.js b/notebook/static/base/js/markdown.js new file mode 100644 index 000000000..94b885014 --- /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