/
abcRender.ts
27 lines (25 loc) · 1.1 KB
/
abcRender.ts
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
import {abcRenderAdapter} from "../adapter";
import {Constants} from "../constants";
import {addScript} from "../util/addScript";
declare const ABCJS: {
renderAbc(element: HTMLElement, text: string): void;
};
export const abcRender = (element: (HTMLElement | Document) = document, cdn = Constants.CDN) => {
const abcElements = abcRenderAdapter.getMathElements(element);
if (abcElements.length > 0) {
addScript(`${cdn}/dist/js/abcjs/abcjs_basic.min.js`, "vditorAbcjsScript").then(() => {
abcElements.forEach((item: HTMLDivElement) => {
if (item.parentElement.classList.contains("vditor-wysiwyg__pre") ||
item.parentElement.classList.contains("vditor-ir__marker--pre")) {
return;
}
if (item.getAttribute("data-processed") === "true") {
return;
}
ABCJS.renderAbc(item, abcRenderAdapter.getCode(item).trim());
item.style.overflowX = "auto";
item.setAttribute("data-processed", "true");
});
});
}
};