Skip to content

Commit

Permalink
Fix issue ipython-contrib#1638: support dynamic loading marked.sj wit…
Browse files Browse the repository at this point in the history
…h 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.
  • Loading branch information
johnjbarton committed May 8, 2023
1 parent 374defd commit f96b891
Showing 1 changed file with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,29 @@ define([
'require',
'notebook/js/cell',
'base/js/security',
'components/marked/lib/marked',
// marked loaded dynamically for v5 vs v6
'base/js/events',
'notebook/js/textcell'
], function(IPython, $, requirejs, cell, security, marked, events, textcell) {
], function(IPython, $, requirejs, cell, security, events, textcell) {
"use strict";

var marked = null;
requirejs('nbextensions/python-markdown/marked.min',
function(marked_local) {
marked = marked_local.marked;
},
function(e_ignored) {
// fall back to components for v<6.
requirejs('components/marked/lib/marked',
function(marked_compat) {
marked = marked_compat;
},
function(error) {
marked = function() {
return "ERROR: marked JS library required but not found";
}
})
});
/*
* Find Python expression enclosed in {{ }}, execute and add to text as
* <span> tags. The actual content gets filled in later by a callback.
Expand Down

0 comments on commit f96b891

Please sign in to comment.