|
1 | 1 | import template from "./template.js";
|
2 |
| -import marked from "marked"; |
3 | 2 |
|
4 | 3 | const HL_ROOT =
|
5 | 4 | "https://cdn.jsdelivr.net/npm/@observablehq/[email protected]/";
|
6 | 5 |
|
7 | 6 | export default function(require) {
|
8 | 7 | 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 | + }); |
36 | 37 | });
|
37 |
| - }); |
| 38 | + } |
| 39 | + return root; |
| 40 | + }, |
| 41 | + function() { |
| 42 | + return document.createElement("div"); |
38 | 43 | }
|
39 |
| - return root; |
40 |
| - }, |
41 |
| - function() { |
42 |
| - return document.createElement("div"); |
43 |
| - } |
44 |
| - ); |
| 44 | + ); |
| 45 | + }); |
45 | 46 | };
|
46 | 47 | }
|
0 commit comments