Skip to content

Commit

Permalink
Fix issue #1638: support local directory loading marked.js
Browse files Browse the repository at this point in the history
In v6 jupyter notebook components/marked/lib/marked no longer exists. The extension silently falls over.

Add  https://cdnjs.com/libraries/marked for local loading into the python-markdown directory.

Change required path and calls marked -> marked.marked.

Add 6.x to yaml compat setting
  • Loading branch information
johnjbarton committed May 9, 2023
1 parent 374defd commit 020a69b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ define([
'require',
'notebook/js/cell',
'base/js/security',
'components/marked/lib/marked',
'nbextensions/python-markdown/marked.min',
'base/js/events',
'notebook/js/textcell'
], function(IPython, $, requirejs, cell, security, marked, events, textcell) {
Expand Down Expand Up @@ -60,9 +60,9 @@ define([
var html;
if (out_data.msg_type === "error") {
var text = "**" + out_data.content.ename + "**: " + out_data.content.evalue;
html = marked(text);
html = marked.marked(text);
} else if (out_data.msg_type === "stream") {
html = marked(out_data.content.text);
html = marked.marked(out_data.content.text);
var t = html.match(/^\s*<p>([\s\S]*?)<\/p>\s*$/); //strip <p> and </p> that marked (maybe) adds and we don't want
html = t !== null ? t[1] : html;
var q = html.match(/^&#39;([\s\S]*?)&#39;$/); // strip quotes from strings
Expand All @@ -84,11 +84,11 @@ define([
var png = ul['image/png'];
html = '<img src="data:image/png;base64,' + png + '"/>';
} else if (ul['text/markdown'] != undefined) {
html = marked(ul['text/markdown']);
html = marked.marked(ul['text/markdown']);
} else if (ul['text/html'] != undefined) {
html = ul['text/html'];
} else {
html = marked(ul['text/plain']);
html = marked.marked(ul['text/plain']);
// [\s\S] is used to also catch newlines
var t = html.match(/^\s*<p>([\s\S]*?)<\/p>\s*$/); //strip <p> and </p> that marked adds and we don't want
html = t !== null ? t[1] : html;
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ Link: readme.md
Icon: python-markdown.png
Main: main.js
Preprocessor: pymdpreprocessor.py
Compatibility: 4.x, 5.x
Compatibility: 4.x, 5.x, 6.x

0 comments on commit 020a69b

Please sign in to comment.