-
Notifications
You must be signed in to change notification settings - Fork 83
/
Copy pathmd.js
41 lines (40 loc) · 1.4 KB
/
md.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import {highlight, marked} from "./dependencies.js";
import {template} from "./template.js";
export function md(require) {
return require(marked.resolve()).then(function(marked) {
return template(
function(string) {
var root = document.createElement("div");
root.innerHTML = marked(string, {langPrefix: ""}).trim();
var code = root.querySelectorAll("pre code[class]");
if (code.length > 0) {
require(highlight.resolve()).then(function(hl) {
code.forEach(function(block) {
function done() {
hl.highlightBlock(block);
block.parentNode.classList.add("observablehq--md-pre");
}
if (hl.getLanguage(block.className)) {
done();
} else {
require(highlight.resolve("async-languages/index.js"))
.then(index => {
if (index.has(block.className)) {
return require(highlight.resolve("async-languages/" + index.get(block.className))).then(language => {
hl.registerLanguage(block.className, language);
});
}
})
.then(done, done);
}
});
});
}
return root;
},
function() {
return document.createElement("div");
}
);
});
}