-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
35 lines (31 loc) · 868 Bytes
/
index.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
import fromDom from "hast-util-from-dom";
import map from "unist-util-map";
import { JSDOM } from "jsdom";
import ABCJS from "./abcjs";
const remarkMusic = () => {
return (tree, file) => {
return map(tree, (node) => {
if (node.type === "code" && node.lang === "abc") {
const {
window: { document },
} = new JSDOM();
const renderInto = document.createElement("div");
renderInto.className = "abcjsContainer";
ABCJS.renderAbc(renderInto, node.value);
const data = fromDom(renderInto);
return {
type: "abc",
value: node.value,
data: {
hName: data.tagName,
hProperties: data.properties,
hChildren: data.children,
},
};
} else {
return node;
}
});
};
};
export default remarkMusic;