@elmethis/core 1.0.0-alpha.154 → 1.0.0-alpha.156
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { defineComponent, ref, onMounted, onUpdated, createBlock, openBlock, resolveDynamicComponent, normalizeStyle, normalizeClass, withCtx,
|
|
2
|
-
import
|
|
1
|
+
import { defineComponent, ref, onServerPrefetch, onMounted, onUpdated, createBlock, openBlock, resolveDynamicComponent, normalizeStyle, normalizeClass, withCtx, createElementBlock, toDisplayString } from "vue";
|
|
2
|
+
import { renderToString } from "katex";
|
|
3
3
|
/* empty css */
|
|
4
|
+
const _hoisted_1 = ["innerHTML"];
|
|
5
|
+
const _hoisted_2 = { key: 1 };
|
|
4
6
|
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
5
7
|
__name: "ElmKatex",
|
|
6
8
|
props: {
|
|
@@ -9,32 +11,37 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
9
11
|
},
|
|
10
12
|
setup(__props) {
|
|
11
13
|
const props = __props;
|
|
12
|
-
const
|
|
14
|
+
const isRendered = ref(false);
|
|
15
|
+
const html = ref(props.expression);
|
|
13
16
|
const render = () => {
|
|
14
|
-
if (
|
|
17
|
+
if (!isRendered.value) {
|
|
15
18
|
try {
|
|
16
|
-
|
|
19
|
+
html.value = renderToString(props.expression, {
|
|
17
20
|
displayMode: props.block
|
|
18
21
|
});
|
|
22
|
+
isRendered.value = true;
|
|
19
23
|
} catch (err) {
|
|
20
24
|
console.error("KaTeX rendering error:", err);
|
|
21
25
|
}
|
|
22
26
|
}
|
|
23
27
|
};
|
|
28
|
+
onServerPrefetch(render);
|
|
24
29
|
onMounted(render);
|
|
25
30
|
onUpdated(render);
|
|
26
31
|
return (_ctx, _cache) => {
|
|
27
32
|
return openBlock(), createBlock(resolveDynamicComponent(props.block ? "div" : "span"), {
|
|
28
33
|
class: normalizeClass(_ctx.$style.katex),
|
|
29
34
|
key: JSON.stringify(props),
|
|
30
|
-
|
|
31
|
-
ref: targetRef,
|
|
35
|
+
ref: "targetRef",
|
|
32
36
|
style: normalizeStyle({
|
|
33
37
|
"--margin-block": props.block ? "3rem" : void 0
|
|
34
38
|
})
|
|
35
39
|
}, {
|
|
36
40
|
default: withCtx(() => [
|
|
37
|
-
|
|
41
|
+
isRendered.value ? (openBlock(), createElementBlock("span", {
|
|
42
|
+
key: 0,
|
|
43
|
+
innerHTML: html.value
|
|
44
|
+
}, null, 8, _hoisted_1)) : (openBlock(), createElementBlock("span", _hoisted_2, toDisplayString(_ctx.expression), 1))
|
|
38
45
|
]),
|
|
39
46
|
_: 1
|
|
40
47
|
}, 8, ["class", "style"]);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { defineComponent, ref, onMounted, onServerPrefetch, createElementBlock, openBlock, normalizeClass, createElementVNode } from "vue";
|
|
2
|
-
import {
|
|
2
|
+
import { getHighlighterSingleton } from "./shikiInstance.mjs";
|
|
3
3
|
const _hoisted_1 = ["innerHTML"];
|
|
4
4
|
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
5
5
|
__name: "ElmShikiHighlighter",
|
|
@@ -13,10 +13,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
13
13
|
const html = ref(`<pre>${props.code}</pre>`);
|
|
14
14
|
const render = async () => {
|
|
15
15
|
if (!isRendered.value) {
|
|
16
|
-
const highlighter = await
|
|
17
|
-
langs: [props.language],
|
|
18
|
-
themes: ["vitesse-light", "vitesse-dark"]
|
|
19
|
-
});
|
|
16
|
+
const highlighter = await getHighlighterSingleton();
|
|
20
17
|
html.value = highlighter.codeToHtml(props.code, {
|
|
21
18
|
lang: props.language,
|
|
22
19
|
themes: {
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { createHighlighter } from "shiki";
|
|
2
|
+
let highlighterPromise = null;
|
|
3
|
+
function getHighlighterSingleton() {
|
|
4
|
+
if (!highlighterPromise) {
|
|
5
|
+
highlighterPromise = createHighlighter({
|
|
6
|
+
langs: [
|
|
7
|
+
"abap",
|
|
8
|
+
"bash",
|
|
9
|
+
"c",
|
|
10
|
+
"clojure",
|
|
11
|
+
"coffeescript",
|
|
12
|
+
"c++",
|
|
13
|
+
"c#",
|
|
14
|
+
"css",
|
|
15
|
+
"dart",
|
|
16
|
+
"diff",
|
|
17
|
+
"docker",
|
|
18
|
+
"elixir",
|
|
19
|
+
"elm",
|
|
20
|
+
"erlang",
|
|
21
|
+
"f#",
|
|
22
|
+
"gherkin",
|
|
23
|
+
"glsl",
|
|
24
|
+
"go",
|
|
25
|
+
"graphql",
|
|
26
|
+
"groovy",
|
|
27
|
+
"haskell",
|
|
28
|
+
"html",
|
|
29
|
+
"java",
|
|
30
|
+
"javascript",
|
|
31
|
+
"json",
|
|
32
|
+
"julia",
|
|
33
|
+
"kotlin",
|
|
34
|
+
"latex",
|
|
35
|
+
"less",
|
|
36
|
+
"lisp",
|
|
37
|
+
"lua",
|
|
38
|
+
"makefile",
|
|
39
|
+
"markdown",
|
|
40
|
+
"matlab",
|
|
41
|
+
"mermaid",
|
|
42
|
+
"nix",
|
|
43
|
+
"objective-c",
|
|
44
|
+
"ocaml",
|
|
45
|
+
"pascal",
|
|
46
|
+
"perl",
|
|
47
|
+
"php",
|
|
48
|
+
"plaintext",
|
|
49
|
+
"powershell",
|
|
50
|
+
"prolog",
|
|
51
|
+
"protobuf",
|
|
52
|
+
"python",
|
|
53
|
+
"r",
|
|
54
|
+
"ruby",
|
|
55
|
+
"rust",
|
|
56
|
+
"sass",
|
|
57
|
+
"scala",
|
|
58
|
+
"scheme",
|
|
59
|
+
"scss",
|
|
60
|
+
"shell",
|
|
61
|
+
"sql",
|
|
62
|
+
"swift",
|
|
63
|
+
"typescript",
|
|
64
|
+
"wasm",
|
|
65
|
+
"xml",
|
|
66
|
+
"yaml"
|
|
67
|
+
],
|
|
68
|
+
themes: ["vitesse-light", "vitesse-dark"]
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
return highlighterPromise;
|
|
72
|
+
}
|
|
73
|
+
export {
|
|
74
|
+
getHighlighterSingleton
|
|
75
|
+
};
|