-
Notifications
You must be signed in to change notification settings - Fork 5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
163 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// 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) { | ||
options = $.extend({ | ||
// Apply mathjax transformation | ||
with_math: false, | ||
// Prevent marked from returning inline styles for table cells | ||
clean_tables: false | ||
}, options); | ||
var renderer = new marked.Renderer(); | ||
if(options.clean_tables) { | ||
renderer.tablecell = function (content, flags) { | ||
var type = flags.header ? 'th' : 'td'; | ||
var style = flags.align == null ? '': ' style="text-align: ' + flags.align + '"'; | ||
var start_tag = '<' + type + style + '>'; | ||
var end_tag = '</' + type + '>\n'; | ||
return start_tag + content + end_tag; | ||
}; | ||
} | ||
var text = markdown; | ||
var math = null; | ||
if(options.with_math) { | ||
ensure_mathjax_init(); | ||
var text_and_math = mathjaxutils.remove_math(markdown); | ||
text = text_and_math[0]; | ||
math = text_and_math[1]; | ||
} | ||
marked(text, { renderer: renderer }, function (err, html) { | ||
if(!err) { | ||
if(options.with_math) { | ||
html = mathjaxutils.replace_math(html, math); | ||
} | ||
if(options.sanitize) { | ||
html = $(security.sanitize_html_and_parse(html)); | ||
} | ||
} | ||
callback(err, html); | ||
}); | ||
} | ||
|
||
return {'render': render}; | ||
}); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
cba4975
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This commit has been mentioned on Jupyter Community Forum. There might be relevant details there:
https://discourse.jupyter.org/t/the-static-notebook-js-mathjaxutils-js-is-missing/7303/2