Skip to content

Commit 837957e

Browse files
committed
Externalize marked.
1 parent caf3f91 commit 837957e

File tree

3 files changed

+37
-41
lines changed

3 files changed

+37
-41
lines changed

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@
2727
"dist/**/*.js"
2828
],
2929
"dependencies": {
30-
"d3-require": "^1.2.4",
31-
"marked": "https://github.com/observablehq/marked.git#94c6b946f462fd25db4465d71a6859183f86c57f"
30+
"d3-require": "^1.2.4"
3231
},
3332
"devDependencies": {
3433
"eslint": "^6.7.2",

src/md.js

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,47 @@
11
import template from "./template.js";
2-
import marked from "marked";
32

43
const HL_ROOT =
54
"https://cdn.jsdelivr.net/npm/@observablehq/[email protected]/";
65

76
export default function(require) {
87
return function() {
9-
return template(
10-
function(string) {
11-
var root = document.createElement("div");
12-
root.innerHTML = marked(string, {langPrefix: ""}).trim();
13-
var code = root.querySelectorAll("pre code[class]");
14-
if (code.length > 0) {
15-
require(HL_ROOT + "highlight.min.js").then(function(hl) {
16-
code.forEach(function(block) {
17-
function done() {
18-
hl.highlightBlock(block);
19-
block.parentNode.classList.add("observablehq--md-pre");
20-
}
21-
if (hl.getLanguage(block.className)) {
22-
done();
23-
} else {
24-
require(HL_ROOT + "async-languages/index.js")
25-
.then(index => {
26-
if (index.has(block.className)) {
27-
return require(HL_ROOT +
28-
"async-languages/" +
29-
index.get(block.className)).then(language => {
30-
hl.registerLanguage(block.className, language);
31-
});
32-
}
33-
})
34-
.then(done, done);
35-
}
8+
return require("[email protected]/marked.min.js").then(function(marked) {
9+
return template(
10+
function(string) {
11+
var root = document.createElement("div");
12+
root.innerHTML = marked(string, {langPrefix: ""}).trim();
13+
var code = root.querySelectorAll("pre code[class]");
14+
if (code.length > 0) {
15+
require(HL_ROOT + "highlight.min.js").then(function(hl) {
16+
code.forEach(function(block) {
17+
function done() {
18+
hl.highlightBlock(block);
19+
block.parentNode.classList.add("observablehq--md-pre");
20+
}
21+
if (hl.getLanguage(block.className)) {
22+
done();
23+
} else {
24+
require(HL_ROOT + "async-languages/index.js")
25+
.then(index => {
26+
if (index.has(block.className)) {
27+
return require(HL_ROOT +
28+
"async-languages/" +
29+
index.get(block.className)).then(language => {
30+
hl.registerLanguage(block.className, language);
31+
});
32+
}
33+
})
34+
.then(done, done);
35+
}
36+
});
3637
});
37-
});
38+
}
39+
return root;
40+
},
41+
function() {
42+
return document.createElement("div");
3843
}
39-
return root;
40-
},
41-
function() {
42-
return document.createElement("div");
43-
}
44-
);
44+
);
45+
});
4546
};
4647
}

yarn.lock

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1735,10 +1735,6 @@ make-error@^1.1.1:
17351735
resolved "https://registry.yarnpkg.com/make-error/-/make-error-1.3.5.tgz#efe4e81f6db28cadd605c70f29c831b58ef776c8"
17361736
integrity sha512-c3sIjNUow0+8swNwVpqoH4YCShKNFkMaw6oH1mNS2haDZQqkeZFlHS3dhoeEbKKmJB4vXpJucU6oH75aDYeE9g==
17371737

1738-
"marked@https://github.com/observablehq/marked.git#94c6b946f462fd25db4465d71a6859183f86c57f":
1739-
version "0.3.12"
1740-
resolved "https://github.com/observablehq/marked.git#94c6b946f462fd25db4465d71a6859183f86c57f"
1741-
17421738
merge-source-map@^1.1.0:
17431739
version "1.1.0"
17441740
resolved "https://registry.yarnpkg.com/merge-source-map/-/merge-source-map-1.1.0.tgz#2fdde7e6020939f70906a68f2d7ae685e4c8c646"

0 commit comments

Comments
 (0)