You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.4 KiB

import html from "html";
import { ref, onMounted } from "vue";
import { marked, setOptions } from "../../lib/marked/marked.esm.js";
import mermaid from "../../lib/mermaid/mermaid.esm.min.mjs";
import hljs from "../../lib/highlightjs/highlight.min.js";
1 year ago
export default {
template: html`<div ref="tplRef">
<div class="source" style="display:none;"><slot /></div>
<div class="markdown-body"></div>
</div>`,
1 year ago
props: {
name: {
default: null,
},
1 year ago
},
setup(props) {
const tplRef = ref(null);
mermaid.initialize({ startOnLoad: false });
let id = 0;
onMounted(async () => {
setOptions({
highlight: function (code, lang) {
if (lang === "mermaid") {
1 year ago
return mermaid.mermaidAPI.render(`mermaid${id++}`, code, undefined);
} else {
const language = hljs.getLanguage(lang) ? lang : "plaintext";
1 year ago
return hljs.highlight(code, { language }).value;
}
},
langPrefix: "hljs language-",
1 year ago
});
let mdText = tplRef.value.querySelector(".source").innerText;
1 year ago
if (props.name !== null) {
const response = await fetch(`./assets/docs/${props.name}.md`);
mdText = await response.text();
}
tplRef.value.querySelector(".markdown-body").innerHTML = marked(mdText);
tplRef.value.querySelector(".source").remove();
1 year ago
});
return {
tplRef,
1 year ago
};
},
};