Skip to content

Commit f96b891

Browse files
committed
Fix issue #1638: support dynamic loading marked.sj with fallback for v<6
In v6 jupyter notebook components/marked/lib/marked no longer exists. The extension silently falls over. Hack around puts local copy of marked.min from cdnjs.com into the python-markdown directory. require 'marked' on two paths, first expecting marked.min.j in the same dir, second expecting marked in the v6 compenents/ location. Insert ERROR message in user page if neither is found.
1 parent 374defd commit f96b891

File tree

1 file changed

+19
-2
lines changed
  • src/jupyter_contrib_nbextensions/nbextensions/python-markdown

1 file changed

+19
-2
lines changed

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

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,29 @@ define([
1313
'require',
1414
'notebook/js/cell',
1515
'base/js/security',
16-
'components/marked/lib/marked',
16+
// marked loaded dynamically for v5 vs v6
1717
'base/js/events',
1818
'notebook/js/textcell'
19-
], function(IPython, $, requirejs, cell, security, marked, events, textcell) {
19+
], function(IPython, $, requirejs, cell, security, events, textcell) {
2020
"use strict";
2121

22+
var marked = null;
23+
requirejs('nbextensions/python-markdown/marked.min',
24+
function(marked_local) {
25+
marked = marked_local.marked;
26+
},
27+
function(e_ignored) {
28+
// fall back to components for v<6.
29+
requirejs('components/marked/lib/marked',
30+
function(marked_compat) {
31+
marked = marked_compat;
32+
},
33+
function(error) {
34+
marked = function() {
35+
return "ERROR: marked JS library required but not found";
36+
}
37+
})
38+
});
2239
/*
2340
* Find Python expression enclosed in {{ }}, execute and add to text as
2441
* <span> tags. The actual content gets filled in later by a callback.

0 commit comments

Comments
 (0)