Skip to content

Commit

Permalink
Merge pull request #4041 from arradha/fix/mathjax-codeblocks
Browse files Browse the repository at this point in the history
Disable math jax inside fenced code blocks (closes #4037)
  • Loading branch information
blink1073 authored Oct 2, 2018
2 parents dfcea5b + 7eb6e29 commit c2a2bcc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
7 changes: 5 additions & 2 deletions notebook/static/notebook/js/mathjaxutils.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,12 @@ define([
var hasCodeSpans = /`/.test(text),
de_tilde;
if (hasCodeSpans) {
text = text.replace(/~/g, "~T").replace(/(^|[^\\])(`+)([^\n]*?[^`\n])\2(?!`)/gm, function (wholematch) {
var tilde = function (wholematch) {
return wholematch.replace(/\$/g, "~D");
});
}
text = text.replace(/~/g, "~T")
.replace(/(^|[^\\])(`+)([^\n]*?[^`\n])\2(?!`)/gm, tilde)
.replace(/^\s{0,3}(`{3,})(.|\n)*?\1/gm, tilde);
de_tilde = function (text) {
return text.replace(/~([TD])/g, function (wholematch, character) {
return { T: "~", D: "$" }[character];
Expand Down
6 changes: 6 additions & 0 deletions notebook/tests/notebook/markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ casper.notebook_test(function () {
result = '<pre><code class="cm-s-ipython language-aaaa">x = 1</code></pre>'
md_render_test(codeblock, result, 'Markdown code block unknown language');

codeblock = '```python\ns = "$"\nt = "$"\n```'
result = '<pre><code class="cm-s-ipython language-python">' +
'<span class="cm-variable">s</span> <span class="cm-operator">=</span> <span class="cm-string">"$"</span>\n' +
'<span class="cm-variable">t</span> <span class="cm-operator">=</span> <span class="cm-string">"$"</span></code></pre>';
md_render_test(codeblock, result, 'Markdown code block python');

function mathjax_render_test(input_string, result, message){
casper.thenEvaluate(function (text){
window._test_result = null;
Expand Down

0 comments on commit c2a2bcc

Please sign in to comment.