Skip to content

Commit 7046b76

Browse files
authored
Merge pull request #1122 from jcb91/pymd
[python-markdown] avoid js error when marked doesn't wrap things in <p>
2 parents 59b98a4 + 4a1279b commit 7046b76

File tree

1 file changed

+6
-6
lines changed
  • src/jupyter_contrib_nbextensions/nbextensions/python-markdown

1 file changed

+6
-6
lines changed

src/jupyter_contrib_nbextensions/nbextensions/python-markdown/main.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ define([
6363
html = marked(text);
6464
} else if (out_data.msg_type === "stream") {
6565
html = marked(out_data.content.text);
66-
var t = html.match(/<p>([\s\S]*?)<\/p>/)[1]; //strip <p> and </p> that marked adds and we don't want
67-
html = t ? t : html;
68-
var q = html.match(/&#39;([\s\S]*?)&#39;/); // strip quotes from strings
66+
var t = html.match(/^\s*<p>([\s\S]*?)<\/p>\s*$/); //strip <p> and </p> that marked (maybe) adds and we don't want
67+
html = t !== null ? t[1] : html;
68+
var q = html.match(/^&#39;([\s\S]*?)&#39;$/); // strip quotes from strings
6969
if (q !== null) html = q[1]
7070
} else if (out_data.msg_type === "execute_result" | out_data.msg_type === "display_data" ) {
7171
var ul = out_data.content.data;
@@ -90,9 +90,9 @@ define([
9090
} else {
9191
html = marked(ul['text/plain']);
9292
// [\s\S] is used to also catch newlines
93-
var t = html.match(/<p>([\s\S]*?)<\/p>/)[1]; //strip <p> and </p> that marked adds and we don't want
94-
html = t ? t : html;
95-
var q = html.match(/&#39;([\s\S]*?)&#39;/); // strip quotes from strings
93+
var t = html.match(/^\s*<p>([\s\S]*?)<\/p>\s*$/); //strip <p> and </p> that marked adds and we don't want
94+
html = t !== null ? t[1] : html;
95+
var q = html.match(/^&#39;([\s\S]*?)&#39;$/); // strip quotes from strings
9696
if (q !== null) html = q[1]
9797
}
9898
}

0 commit comments

Comments
 (0)