@nuxtjs/mdc 0.1.3 → 0.1.5
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.
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -51,27 +51,6 @@ function processUnistPlugins(plugins) {
|
|
|
51
51
|
const registerMDCSlotTransformer = (resolver) => {
|
|
52
52
|
extendViteConfig((config) => {
|
|
53
53
|
const compilerOptions = config.vue.template.compilerOptions;
|
|
54
|
-
config.plugins = config.plugins || [];
|
|
55
|
-
config.plugins.push({
|
|
56
|
-
name: "mdc-render-slot-import",
|
|
57
|
-
enforce: "post",
|
|
58
|
-
transform(code) {
|
|
59
|
-
if (code.includes("_renderMDCSlot")) {
|
|
60
|
-
return {
|
|
61
|
-
code: `import { renderSlot as _renderMDCSlot } from '${resolver.resolve("./runtime/utils/slot")}';
|
|
62
|
-
${code}`,
|
|
63
|
-
map: { mappings: "" }
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
if (code.includes("_ssrRenderMDCSlot")) {
|
|
67
|
-
return {
|
|
68
|
-
code: `import { ssrRenderSlot as _ssrRenderMDCSlot } from '${resolver.resolve("./runtime/utils/ssrSlot")}';
|
|
69
|
-
${code}`,
|
|
70
|
-
map: { mappings: "" }
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
54
|
compilerOptions.nodeTransforms = [
|
|
76
55
|
function viteMDCSlot(node, context) {
|
|
77
56
|
if (node.tag === "MDCSlot") {
|
|
@@ -83,6 +62,13 @@ ${code}`,
|
|
|
83
62
|
transform?.(node, context);
|
|
84
63
|
const codegen = context.ssr ? node.ssrCodegenNode : node.codegenNode;
|
|
85
64
|
codegen.callee = codegen.callee === RENDER_SLOT ? "_renderMDCSlot" : "_ssrRenderMDCSlot";
|
|
65
|
+
const importExp = context.ssr ? "{ ssrRenderSlot as _ssrRenderMDCSlot }" : "{ renderSlot as _renderMDCSlot }";
|
|
66
|
+
if (!context.imports.some((i) => String(i.exp) === importExp)) {
|
|
67
|
+
context.imports.push({
|
|
68
|
+
exp: importExp,
|
|
69
|
+
path: resolver.resolve(`./runtime/utils/${context.ssr ? "ssrSlot" : "slot"}`)
|
|
70
|
+
});
|
|
71
|
+
}
|
|
86
72
|
};
|
|
87
73
|
}
|
|
88
74
|
if (context.nodeTransforms[0].name !== "viteMDCSlot") {
|
|
@@ -13,9 +13,10 @@
|
|
|
13
13
|
</template>
|
|
14
14
|
|
|
15
15
|
<script setup lang="ts">
|
|
16
|
+
import { hash } from 'ohash'
|
|
16
17
|
import { useAsyncData } from 'nuxt/app'
|
|
17
18
|
import { parseMarkdown } from '../parser'
|
|
18
|
-
import { watch } from 'vue'
|
|
19
|
+
import { watch, computed } from 'vue'
|
|
19
20
|
|
|
20
21
|
const props = defineProps({
|
|
21
22
|
tag: {
|
|
@@ -28,7 +29,9 @@ const props = defineProps({
|
|
|
28
29
|
}
|
|
29
30
|
})
|
|
30
31
|
|
|
31
|
-
const
|
|
32
|
+
const key = computed(() => hash(props.value))
|
|
33
|
+
|
|
34
|
+
const { data, refresh } = await useAsyncData(key.value, async () => await parseMarkdown(props.value, { highlight: {}}))
|
|
32
35
|
|
|
33
36
|
watch(() => props.value, () => {
|
|
34
37
|
refresh()
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Text } from "vue";
|
|
1
2
|
export const TEXT_TAGS = ["p", "h1", "h2", "h3", "h4", "h5", "h6", "li"];
|
|
2
3
|
export function isTag(vnode, tag) {
|
|
3
4
|
if (vnode.type === tag) {
|
|
@@ -12,7 +13,7 @@ export function isTag(vnode, tag) {
|
|
|
12
13
|
return false;
|
|
13
14
|
}
|
|
14
15
|
export function isText(vnode) {
|
|
15
|
-
return isTag(vnode, "text") ||
|
|
16
|
+
return isTag(vnode, "text") || isTag(vnode, Text);
|
|
16
17
|
}
|
|
17
18
|
export function nodeChildren(node) {
|
|
18
19
|
if (Array.isArray(node.children) || typeof node.children === "string") {
|
|
@@ -31,11 +32,11 @@ export function nodeTextContent(node) {
|
|
|
31
32
|
return node.map(nodeTextContent).join("");
|
|
32
33
|
}
|
|
33
34
|
if (isText(node)) {
|
|
34
|
-
return node.children || node.value;
|
|
35
|
+
return node.children || node.value || "";
|
|
35
36
|
}
|
|
36
37
|
const children = nodeChildren(node);
|
|
37
38
|
if (Array.isArray(children)) {
|
|
38
|
-
return children.map(nodeTextContent).join("");
|
|
39
|
+
return children.map(nodeTextContent).filter(Boolean).join("");
|
|
39
40
|
}
|
|
40
41
|
return "";
|
|
41
42
|
}
|
|
@@ -61,7 +62,7 @@ function _flatUnwrap(vnodes, tags = ["p"]) {
|
|
|
61
62
|
}
|
|
62
63
|
export function flatUnwrap(vnodes, tags = ["p"]) {
|
|
63
64
|
return _flatUnwrap(vnodes, tags).reduce((acc, item) => {
|
|
64
|
-
if (
|
|
65
|
+
if (isText(item)) {
|
|
65
66
|
if (typeof acc[acc.length - 1] === "string") {
|
|
66
67
|
acc[acc.length - 1] += item.children;
|
|
67
68
|
} else {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuxtjs/mdc",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "Nuxt MDC module",
|
|
5
5
|
"repository": "nuxt-modules/mdc",
|
|
6
6
|
"license": "MIT",
|
|
@@ -43,15 +43,16 @@
|
|
|
43
43
|
"destr": "^2.0.1",
|
|
44
44
|
"detab": "^3.0.2",
|
|
45
45
|
"github-slugger": "^2.0.0",
|
|
46
|
-
"hast-util-to-string": "^
|
|
46
|
+
"hast-util-to-string": "^3.0.0",
|
|
47
47
|
"mdast-util-to-hast": "^13.0.2",
|
|
48
48
|
"micromark-util-sanitize-uri": "^2.0.0",
|
|
49
|
+
"ohash": "^1.1.3",
|
|
49
50
|
"property-information": "^6.2.0",
|
|
50
51
|
"rehype-external-links": "^2.1.0",
|
|
51
52
|
"rehype-raw": "^6.1.1",
|
|
52
53
|
"rehype-slug": "^5.1.0",
|
|
53
|
-
"rehype-sort-attribute-values": "^
|
|
54
|
-
"rehype-sort-attributes": "^
|
|
54
|
+
"rehype-sort-attribute-values": "^5.0.0",
|
|
55
|
+
"rehype-sort-attributes": "^5.0.0",
|
|
55
56
|
"remark-emoji": "^4.0.0",
|
|
56
57
|
"remark-gfm": "^3.0.1",
|
|
57
58
|
"remark-mdc": "^2.0.0",
|