Skip to content

Commit c2a2bcc

Browse files
authored
Merge pull request #4041 from arradha/fix/mathjax-codeblocks
Disable math jax inside fenced code blocks (closes #4037)
2 parents dfcea5b + 7eb6e29 commit c2a2bcc

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

notebook/static/notebook/js/mathjaxutils.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,12 @@ define([
113113
var hasCodeSpans = /`/.test(text),
114114
de_tilde;
115115
if (hasCodeSpans) {
116-
text = text.replace(/~/g, "~T").replace(/(^|[^\\])(`+)([^\n]*?[^`\n])\2(?!`)/gm, function (wholematch) {
116+
var tilde = function (wholematch) {
117117
return wholematch.replace(/\$/g, "~D");
118-
});
118+
}
119+
text = text.replace(/~/g, "~T")
120+
.replace(/(^|[^\\])(`+)([^\n]*?[^`\n])\2(?!`)/gm, tilde)
121+
.replace(/^\s{0,3}(`{3,})(.|\n)*?\1/gm, tilde);
119122
de_tilde = function (text) {
120123
return text.replace(/~([TD])/g, function (wholematch, character) {
121124
return { T: "~", D: "$" }[character];

notebook/tests/notebook/markdown.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ casper.notebook_test(function () {
103103
result = '<pre><code class="cm-s-ipython language-aaaa">x = 1</code></pre>'
104104
md_render_test(codeblock, result, 'Markdown code block unknown language');
105105

106+
codeblock = '```python\ns = "$"\nt = "$"\n```'
107+
result = '<pre><code class="cm-s-ipython language-python">' +
108+
'<span class="cm-variable">s</span> <span class="cm-operator">=</span> <span class="cm-string">"$"</span>\n' +
109+
'<span class="cm-variable">t</span> <span class="cm-operator">=</span> <span class="cm-string">"$"</span></code></pre>';
110+
md_render_test(codeblock, result, 'Markdown code block python');
111+
106112
function mathjax_render_test(input_string, result, message){
107113
casper.thenEvaluate(function (text){
108114
window._test_result = null;

0 commit comments

Comments
 (0)