@nuxtjs/mdc 0.16.0 → 0.17.0
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/README.md +8 -8
- package/dist/config.d.mts +1 -1
- package/dist/module.d.mts +15 -3
- package/dist/module.json +3 -3
- package/dist/module.mjs +9 -4
- package/dist/runtime/components/MDC.vue +25 -33
- package/dist/runtime/components/MDC.vue.d.ts +140 -0
- package/dist/runtime/components/MDCCached.vue +117 -0
- package/dist/runtime/components/MDCCached.vue.d.ts +155 -0
- package/dist/runtime/components/MDCRenderer.vue +19 -13
- package/dist/runtime/components/MDCRenderer.vue.d.ts +11 -123
- package/dist/runtime/components/MDCSlot.vue.d.ts +2 -2
- package/dist/runtime/components/prose/ProseA.vue +5 -7
- package/dist/runtime/components/prose/ProseA.vue.d.ts +36 -0
- package/dist/runtime/components/prose/ProseBlockquote.vue.d.ts +12 -0
- package/dist/runtime/components/prose/ProseCode.vue.d.ts +12 -0
- package/dist/runtime/components/prose/ProseEm.vue.d.ts +12 -0
- package/dist/runtime/components/prose/ProseH1.vue +7 -7
- package/dist/runtime/components/prose/ProseH1.vue.d.ts +17 -0
- package/dist/runtime/components/prose/ProseH2.vue +7 -7
- package/dist/runtime/components/prose/ProseH2.vue.d.ts +17 -0
- package/dist/runtime/components/prose/ProseH3.vue +7 -7
- package/dist/runtime/components/prose/ProseH3.vue.d.ts +17 -0
- package/dist/runtime/components/prose/ProseH4.vue +7 -7
- package/dist/runtime/components/prose/ProseH4.vue.d.ts +17 -0
- package/dist/runtime/components/prose/ProseH5.vue +7 -7
- package/dist/runtime/components/prose/ProseH5.vue.d.ts +17 -0
- package/dist/runtime/components/prose/ProseH6.vue +7 -7
- package/dist/runtime/components/prose/ProseH6.vue.d.ts +17 -0
- package/dist/runtime/components/prose/ProseHr.vue.d.ts +2 -0
- package/dist/runtime/components/prose/ProseImg.vue +15 -18
- package/dist/runtime/components/prose/ProseImg.vue.d.ts +41 -0
- package/dist/runtime/components/prose/ProseLi.vue.d.ts +12 -0
- package/dist/runtime/components/prose/ProseOl.vue.d.ts +12 -0
- package/dist/runtime/components/prose/ProseP.vue.d.ts +12 -0
- package/dist/runtime/components/prose/ProsePre.vue +4 -4
- package/dist/runtime/components/prose/ProsePre.vue.d.ts +69 -0
- package/dist/runtime/components/prose/ProseScript.vue +4 -4
- package/dist/runtime/components/prose/ProseScript.vue.d.ts +14 -0
- package/dist/runtime/components/prose/ProseStrong.vue.d.ts +12 -0
- package/dist/runtime/components/prose/ProseTable.vue.d.ts +12 -0
- package/dist/runtime/components/prose/ProseTbody.vue.d.ts +12 -0
- package/dist/runtime/components/prose/ProseTd.vue.d.ts +12 -0
- package/dist/runtime/components/prose/ProseTh.vue.d.ts +12 -0
- package/dist/runtime/components/prose/ProseThead.vue.d.ts +12 -0
- package/dist/runtime/components/prose/ProseTr.vue.d.ts +12 -0
- package/dist/runtime/components/prose/ProseUl.vue.d.ts +12 -0
- package/dist/runtime/highlighter/shiki.d.ts +1 -1
- package/dist/runtime/highlighter/shiki.js +9 -6
- package/dist/runtime/index.d.ts +1 -0
- package/dist/runtime/index.js +1 -0
- package/dist/runtime/parser/cached.d.ts +2 -0
- package/dist/runtime/parser/cached.js +44 -0
- package/dist/runtime/parser/compiler.js +11 -9
- package/dist/runtime/parser/handlers/utils.js +6 -2
- package/dist/runtime/parser/index.js +9 -5
- package/dist/runtime/stringify/mdc-remark.js +63 -50
- package/dist/runtime/utils/slot.d.ts +1 -1
- package/dist/shared/{mdc.4762b8bc.d.ts → mdc.BkZUOs7X.d.mts} +2 -1
- package/dist/types.d.mts +5 -1
- package/package.json +32 -34
- package/dist/config.d.ts +0 -4
- package/dist/module.cjs +0 -5
- package/dist/module.d.ts +0 -570
- package/dist/shared/mdc.4762b8bc.d.mts +0 -66
- package/dist/types.d.ts +0 -1
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ MDC supercharges regular Markdown to write documents interacting deeply with any
|
|
|
22
22
|
- Support asynchronous rendering of nested components
|
|
23
23
|
- Add attributes and classes to inline HTML tags
|
|
24
24
|
|
|
25
|
-
Learn more about the MDC syntax on https://content.
|
|
25
|
+
Learn more about the MDC syntax on https://content.nuxt.com/docs/files/markdown
|
|
26
26
|
|
|
27
27
|
> [!Note]
|
|
28
28
|
> You may utilize this package inside of your Nuxt project (standard configuration) or within any Vue project.
|
|
@@ -381,13 +381,13 @@ import {
|
|
|
381
381
|
createShikiHighlighter,
|
|
382
382
|
} from '@nuxtjs/mdc/runtime'
|
|
383
383
|
// Import desired Shiki themes and languages
|
|
384
|
-
import MaterialThemePalenight from '
|
|
385
|
-
import HtmlLang from '
|
|
386
|
-
import MdcLang from '
|
|
387
|
-
import TsLang from '
|
|
388
|
-
import VueLang from '
|
|
389
|
-
import ScssLang from '
|
|
390
|
-
import YamlLang from '
|
|
384
|
+
import MaterialThemePalenight from '@shikijs/themes/material-theme-palenight'
|
|
385
|
+
import HtmlLang from '@shikijs/langs/html'
|
|
386
|
+
import MdcLang from '@shikijs/langs/mdc'
|
|
387
|
+
import TsLang from '@shikijs/langs/typescript'
|
|
388
|
+
import VueLang from '@shikijs/langs/vue'
|
|
389
|
+
import ScssLang from '@shikijs/langs/scss'
|
|
390
|
+
import YamlLang from '@shikijs/langs/yaml'
|
|
391
391
|
|
|
392
392
|
export default function useMarkdownParser() {
|
|
393
393
|
let parser: Awaited<ReturnType<typeof createMarkdownParser>>
|
package/dist/config.d.mts
CHANGED
package/dist/module.d.mts
CHANGED
|
@@ -1,25 +1,32 @@
|
|
|
1
1
|
import * as _nuxt_schema from '@nuxt/schema';
|
|
2
2
|
import { BundledLanguage, LanguageRegistration, BundledTheme, ThemeRegistrationAny } from 'shiki';
|
|
3
3
|
import { Options } from 'remark-rehype';
|
|
4
|
-
import { R as RehypeHighlightOption, M as MdcConfig, a as MdcThemeOptions } from './shared/mdc.
|
|
5
|
-
export { A as Awaitable, b as HighlightResult, c as Highlighter, H as HighlighterOptions, d as defineConfig } from './shared/mdc.
|
|
4
|
+
import { R as RehypeHighlightOption, M as MdcConfig, a as MdcThemeOptions } from './shared/mdc.BkZUOs7X.mjs';
|
|
5
|
+
export { A as Awaitable, b as HighlightResult, c as Highlighter, H as HighlighterOptions, d as defineConfig } from './shared/mdc.BkZUOs7X.mjs';
|
|
6
6
|
import { Options as Options$1 } from 'remark-stringify';
|
|
7
7
|
import 'unified';
|
|
8
8
|
import 'hast';
|
|
9
9
|
|
|
10
|
+
type NodePosition = {
|
|
11
|
+
start: number;
|
|
12
|
+
end: number;
|
|
13
|
+
};
|
|
10
14
|
type MDCText = {
|
|
11
15
|
type: 'text';
|
|
12
16
|
value: string;
|
|
17
|
+
position?: NodePosition;
|
|
13
18
|
};
|
|
14
19
|
type MDCComment = {
|
|
15
20
|
type: 'comment';
|
|
16
21
|
value: string;
|
|
22
|
+
position?: NodePosition;
|
|
17
23
|
};
|
|
18
24
|
type MDCElement = {
|
|
19
25
|
type: 'element';
|
|
20
26
|
tag: string;
|
|
21
27
|
props: Record<string, any> | undefined;
|
|
22
28
|
children: Array<MDCElement | MDCText | MDCComment>;
|
|
29
|
+
position?: NodePosition;
|
|
23
30
|
};
|
|
24
31
|
type MDCNode = MDCElement | MDCText | MDCComment;
|
|
25
32
|
type MDCRoot = {
|
|
@@ -69,6 +76,10 @@ interface MDCParseOptions {
|
|
|
69
76
|
searchDepth?: number;
|
|
70
77
|
} | false;
|
|
71
78
|
keepComments?: boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Keep the position of the node
|
|
81
|
+
*/
|
|
82
|
+
keepPosition?: boolean;
|
|
72
83
|
/**
|
|
73
84
|
* Extract content heading from the markdown file.
|
|
74
85
|
*
|
|
@@ -567,4 +578,5 @@ declare module '@nuxt/schema' {
|
|
|
567
578
|
}
|
|
568
579
|
}
|
|
569
580
|
|
|
570
|
-
export {
|
|
581
|
+
export { DefaultHighlightLangs, MdcConfig, MdcThemeOptions, RehypeHighlightOption, _default as default };
|
|
582
|
+
export type { Comment, CommentData, Content, Data, Doctype, DoctypeData, Element, ElementContent, ElementContentMap, ElementData, Literal, Literals, MDCComment, MDCData, MDCElement, MDCNode, MDCParseOptions, MDCParserResult, MDCRenderOptions, MDCRoot, MDCStringifyOptions, MDCText, ModuleOptions, Node, NodePosition, Nodes, Parent, Parents, Properties, RehypePlugin, RemarkPlugin, Root, RootContent, RootContentMap, RootData, Text, TextData, Toc, TocLink, UnistPlugin };
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -3,6 +3,7 @@ import { extendViteConfig, useNitro, defineNuxtModule, createResolver, addServer
|
|
|
3
3
|
import { defu } from 'defu';
|
|
4
4
|
import { resolve } from 'pathe';
|
|
5
5
|
import fs from 'node:fs/promises';
|
|
6
|
+
import { bundledLanguagesInfo } from 'shiki/bundle/full';
|
|
6
7
|
import { pascalCase } from 'scule';
|
|
7
8
|
export { defineConfig } from './config.mjs';
|
|
8
9
|
|
|
@@ -79,7 +80,10 @@ async function mdcHighlighter({
|
|
|
79
80
|
"import.meta.client ? import('shiki/wasm') : import('shiki/onig.wasm')"
|
|
80
81
|
);
|
|
81
82
|
}
|
|
82
|
-
|
|
83
|
+
code = code.replace(
|
|
84
|
+
/from\s+(['"])shiki\1/,
|
|
85
|
+
'from "shiki/engine/javascript"'
|
|
86
|
+
);
|
|
83
87
|
const langsMap = /* @__PURE__ */ new Map();
|
|
84
88
|
options.langs?.forEach((lang) => {
|
|
85
89
|
if (typeof lang === "string") {
|
|
@@ -104,13 +108,13 @@ async function mdcHighlighter({
|
|
|
104
108
|
} = options;
|
|
105
109
|
return [
|
|
106
110
|
"import { getMdcConfigs } from '#mdc-configs'",
|
|
107
|
-
shikiEngine === "javascript" ? "
|
|
111
|
+
shikiEngine === "javascript" ? "" : "import { createOnigurumaEngine } from 'shiki/engine/oniguruma'",
|
|
108
112
|
code,
|
|
109
113
|
"const bundledLangs = {",
|
|
110
|
-
...Array.from(langsMap.entries()).map(([name, lang]) => typeof lang === "string" ? JSON.stringify(name) + `: () => import('
|
|
114
|
+
...Array.from(langsMap.entries()).map(([name, lang]) => typeof lang === "string" ? JSON.stringify(name) + `: () => import('@shikijs/langs/${lang}').then(r => r.default || r),` : JSON.stringify(name) + ": " + JSON.stringify(lang) + ","),
|
|
111
115
|
"}",
|
|
112
116
|
"const bundledThemes = {",
|
|
113
|
-
...themes.map((theme) => typeof theme === "string" ? JSON.stringify(theme) + `: () => import('
|
|
117
|
+
...themes.map((theme) => typeof theme === "string" ? JSON.stringify(theme) + `: () => import('@shikijs/themes/${theme}').then(r => r.default || r),` : JSON.stringify(theme.name) + ": " + JSON.stringify(theme) + ","),
|
|
114
118
|
"}",
|
|
115
119
|
"const options = " + JSON.stringify({
|
|
116
120
|
theme: options.theme,
|
|
@@ -326,6 +330,7 @@ const module = defineNuxtModule({
|
|
|
326
330
|
options
|
|
327
331
|
});
|
|
328
332
|
addComponent({ name: "MDC", filePath: resolver.resolve("./runtime/components/MDC") });
|
|
333
|
+
addComponent({ name: "MDCCached", filePath: resolver.resolve("./runtime/components/MDCCached") });
|
|
329
334
|
addComponent({ name: "MDCRenderer", filePath: resolver.resolve("./runtime/components/MDCRenderer") });
|
|
330
335
|
addComponent({ name: "MDCSlot", filePath: resolver.resolve("./runtime/components/MDCSlot") });
|
|
331
336
|
addImports({ from: resolver.resolve("./runtime/utils/node"), name: "flatUnwrap", as: "unwrapSlot" });
|
|
@@ -17,16 +17,13 @@
|
|
|
17
17
|
</slot>
|
|
18
18
|
</template>
|
|
19
19
|
|
|
20
|
-
<script setup
|
|
21
|
-
import { useAsyncData } from
|
|
22
|
-
import { watch, computed
|
|
23
|
-
import type { MDCParseOptions } from '@nuxtjs/mdc'
|
|
24
|
-
import { parseMarkdown } from '../parser'
|
|
25
|
-
|
|
20
|
+
<script setup>
|
|
21
|
+
import { useAsyncData } from "nuxt/app";
|
|
22
|
+
import { watch, computed } from "vue";
|
|
26
23
|
const props = defineProps({
|
|
27
24
|
tag: {
|
|
28
25
|
type: [String, Boolean],
|
|
29
|
-
default:
|
|
26
|
+
default: "div"
|
|
30
27
|
},
|
|
31
28
|
/**
|
|
32
29
|
* Raw markdown string or parsed markdown object from `parseMarkdown`
|
|
@@ -46,7 +43,7 @@ const props = defineProps({
|
|
|
46
43
|
* Options for `parseMarkdown`
|
|
47
44
|
*/
|
|
48
45
|
parserOptions: {
|
|
49
|
-
type: Object
|
|
46
|
+
type: Object,
|
|
50
47
|
default: () => ({})
|
|
51
48
|
},
|
|
52
49
|
/**
|
|
@@ -54,7 +51,7 @@ const props = defineProps({
|
|
|
54
51
|
*/
|
|
55
52
|
class: {
|
|
56
53
|
type: [String, Array, Object],
|
|
57
|
-
default:
|
|
54
|
+
default: ""
|
|
58
55
|
},
|
|
59
56
|
/**
|
|
60
57
|
* Tags to unwrap separated by spaces
|
|
@@ -70,7 +67,7 @@ const props = defineProps({
|
|
|
70
67
|
*/
|
|
71
68
|
cacheKey: {
|
|
72
69
|
type: String,
|
|
73
|
-
default:
|
|
70
|
+
default: void 0
|
|
74
71
|
},
|
|
75
72
|
/**
|
|
76
73
|
* Partial parsing (if partial is `true`, title and toc generation will not be generated)
|
|
@@ -79,38 +76,33 @@ const props = defineProps({
|
|
|
79
76
|
type: Boolean,
|
|
80
77
|
default: true
|
|
81
78
|
}
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
const key = computed(() => props.cacheKey ?? hashString(props.value))
|
|
85
|
-
|
|
79
|
+
});
|
|
80
|
+
const key = computed(() => props.cacheKey ?? hashString(props.value));
|
|
86
81
|
const { data, refresh, error } = await useAsyncData(key.value, async () => {
|
|
87
|
-
if (typeof props.value !==
|
|
88
|
-
return props.value
|
|
82
|
+
if (typeof props.value !== "string") {
|
|
83
|
+
return props.value;
|
|
89
84
|
}
|
|
85
|
+
const { parseMarkdown } = await import("@nuxtjs/mdc/runtime");
|
|
90
86
|
return await parseMarkdown(props.value, {
|
|
91
87
|
...props.parserOptions,
|
|
92
88
|
toc: props.partial ? false : props.parserOptions?.toc,
|
|
93
89
|
contentHeading: props.partial ? false : props.parserOptions?.contentHeading
|
|
94
|
-
})
|
|
95
|
-
})
|
|
96
|
-
|
|
97
|
-
const body = computed(() => props.excerpt ? data.value?.excerpt : data.value?.body)
|
|
98
|
-
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
const body = computed(() => props.excerpt ? data.value?.excerpt : data.value?.body);
|
|
99
93
|
watch(() => props.value, () => {
|
|
100
|
-
refresh()
|
|
101
|
-
})
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
if (typeof str !== 'string') {
|
|
106
|
-
str = JSON.stringify(str || '')
|
|
94
|
+
refresh();
|
|
95
|
+
});
|
|
96
|
+
function hashString(str) {
|
|
97
|
+
if (typeof str !== "string") {
|
|
98
|
+
str = JSON.stringify(str || "");
|
|
107
99
|
}
|
|
108
|
-
let hash = 0
|
|
100
|
+
let hash = 0;
|
|
109
101
|
for (let i = 0; i < str.length; i++) {
|
|
110
|
-
const char = str.charCodeAt(i)
|
|
111
|
-
hash = (
|
|
112
|
-
hash = hash & hash
|
|
102
|
+
const char = str.charCodeAt(i);
|
|
103
|
+
hash = (hash << 6) - hash + char;
|
|
104
|
+
hash = hash & hash;
|
|
113
105
|
}
|
|
114
|
-
return `mdc-${hash === 0 ?
|
|
106
|
+
return `mdc-${hash === 0 ? "0000" : hash.toString(36)}-key`;
|
|
115
107
|
}
|
|
116
108
|
</script>
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { type PropType } from 'vue';
|
|
2
|
+
import type { MDCParseOptions } from '@nuxtjs/mdc';
|
|
3
|
+
declare var __VLS_1: {
|
|
4
|
+
data: any;
|
|
5
|
+
body: any;
|
|
6
|
+
toc: any;
|
|
7
|
+
excerpt: any;
|
|
8
|
+
error: import("nuxt/app").NuxtError<unknown> | null;
|
|
9
|
+
};
|
|
10
|
+
type __VLS_Slots = {} & {
|
|
11
|
+
default?: (props: typeof __VLS_1) => any;
|
|
12
|
+
};
|
|
13
|
+
declare const __VLS_component: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
14
|
+
tag: {
|
|
15
|
+
type: (StringConstructor | BooleanConstructor)[];
|
|
16
|
+
default: string;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Raw markdown string or parsed markdown object from `parseMarkdown`
|
|
20
|
+
*/
|
|
21
|
+
value: {
|
|
22
|
+
type: (StringConstructor | ObjectConstructor)[];
|
|
23
|
+
required: true;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Render only the excerpt
|
|
27
|
+
*/
|
|
28
|
+
excerpt: {
|
|
29
|
+
type: BooleanConstructor;
|
|
30
|
+
default: boolean;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Options for `parseMarkdown`
|
|
34
|
+
*/
|
|
35
|
+
parserOptions: {
|
|
36
|
+
type: PropType<MDCParseOptions>;
|
|
37
|
+
default: () => {};
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Class to be applied to the root element
|
|
41
|
+
*/
|
|
42
|
+
class: {
|
|
43
|
+
type: (StringConstructor | ObjectConstructor | ArrayConstructor)[];
|
|
44
|
+
default: string;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Tags to unwrap separated by spaces
|
|
48
|
+
* Example: 'ul li'
|
|
49
|
+
*/
|
|
50
|
+
unwrap: {
|
|
51
|
+
type: (StringConstructor | BooleanConstructor)[];
|
|
52
|
+
default: boolean;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Async Data Unique Key
|
|
56
|
+
* @default `hash(props.value)`
|
|
57
|
+
*/
|
|
58
|
+
cacheKey: {
|
|
59
|
+
type: StringConstructor;
|
|
60
|
+
default: undefined;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Partial parsing (if partial is `true`, title and toc generation will not be generated)
|
|
64
|
+
*/
|
|
65
|
+
partial: {
|
|
66
|
+
type: BooleanConstructor;
|
|
67
|
+
default: boolean;
|
|
68
|
+
};
|
|
69
|
+
}>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
70
|
+
tag: {
|
|
71
|
+
type: (StringConstructor | BooleanConstructor)[];
|
|
72
|
+
default: string;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Raw markdown string or parsed markdown object from `parseMarkdown`
|
|
76
|
+
*/
|
|
77
|
+
value: {
|
|
78
|
+
type: (StringConstructor | ObjectConstructor)[];
|
|
79
|
+
required: true;
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Render only the excerpt
|
|
83
|
+
*/
|
|
84
|
+
excerpt: {
|
|
85
|
+
type: BooleanConstructor;
|
|
86
|
+
default: boolean;
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* Options for `parseMarkdown`
|
|
90
|
+
*/
|
|
91
|
+
parserOptions: {
|
|
92
|
+
type: PropType<MDCParseOptions>;
|
|
93
|
+
default: () => {};
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* Class to be applied to the root element
|
|
97
|
+
*/
|
|
98
|
+
class: {
|
|
99
|
+
type: (StringConstructor | ObjectConstructor | ArrayConstructor)[];
|
|
100
|
+
default: string;
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* Tags to unwrap separated by spaces
|
|
104
|
+
* Example: 'ul li'
|
|
105
|
+
*/
|
|
106
|
+
unwrap: {
|
|
107
|
+
type: (StringConstructor | BooleanConstructor)[];
|
|
108
|
+
default: boolean;
|
|
109
|
+
};
|
|
110
|
+
/**
|
|
111
|
+
* Async Data Unique Key
|
|
112
|
+
* @default `hash(props.value)`
|
|
113
|
+
*/
|
|
114
|
+
cacheKey: {
|
|
115
|
+
type: StringConstructor;
|
|
116
|
+
default: undefined;
|
|
117
|
+
};
|
|
118
|
+
/**
|
|
119
|
+
* Partial parsing (if partial is `true`, title and toc generation will not be generated)
|
|
120
|
+
*/
|
|
121
|
+
partial: {
|
|
122
|
+
type: BooleanConstructor;
|
|
123
|
+
default: boolean;
|
|
124
|
+
};
|
|
125
|
+
}>> & Readonly<{}>, {
|
|
126
|
+
tag: string | boolean;
|
|
127
|
+
excerpt: boolean;
|
|
128
|
+
parserOptions: MDCParseOptions;
|
|
129
|
+
class: string | unknown[] | Record<string, any>;
|
|
130
|
+
unwrap: string | boolean;
|
|
131
|
+
cacheKey: string;
|
|
132
|
+
partial: boolean;
|
|
133
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
134
|
+
declare const _default: __VLS_WithSlots<typeof __VLS_component, __VLS_Slots>;
|
|
135
|
+
export default _default;
|
|
136
|
+
type __VLS_WithSlots<T, S> = T & {
|
|
137
|
+
new (): {
|
|
138
|
+
$slots: S;
|
|
139
|
+
};
|
|
140
|
+
};
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<slot
|
|
3
|
+
:data="data?.data"
|
|
4
|
+
:body="data?.body"
|
|
5
|
+
:toc="data?.toc"
|
|
6
|
+
:excerpt="data?.excerpt"
|
|
7
|
+
:error="error"
|
|
8
|
+
>
|
|
9
|
+
<MDCRenderer
|
|
10
|
+
v-if="body"
|
|
11
|
+
:tag="props.tag"
|
|
12
|
+
:class="props.class"
|
|
13
|
+
:body="body"
|
|
14
|
+
:data="data?.data"
|
|
15
|
+
:unwrap="props.unwrap"
|
|
16
|
+
:components="props.components"
|
|
17
|
+
/>
|
|
18
|
+
</slot>
|
|
19
|
+
</template>
|
|
20
|
+
|
|
21
|
+
<script setup>
|
|
22
|
+
import { useAsyncData } from "nuxt/app";
|
|
23
|
+
import { watch, computed } from "vue";
|
|
24
|
+
import { createCachedParser } from "@nuxtjs/mdc/runtime";
|
|
25
|
+
const props = defineProps({
|
|
26
|
+
tag: {
|
|
27
|
+
type: [String, Boolean],
|
|
28
|
+
default: "div"
|
|
29
|
+
},
|
|
30
|
+
/**
|
|
31
|
+
* Raw markdown string or parsed markdown object from `parseMarkdown`
|
|
32
|
+
*/
|
|
33
|
+
value: {
|
|
34
|
+
type: [String, Object],
|
|
35
|
+
required: true
|
|
36
|
+
},
|
|
37
|
+
/**
|
|
38
|
+
* Render only the excerpt
|
|
39
|
+
*/
|
|
40
|
+
excerpt: {
|
|
41
|
+
type: Boolean,
|
|
42
|
+
default: false
|
|
43
|
+
},
|
|
44
|
+
/**
|
|
45
|
+
* Options for `parseMarkdown`
|
|
46
|
+
*/
|
|
47
|
+
parserOptions: {
|
|
48
|
+
type: Object,
|
|
49
|
+
default: () => ({})
|
|
50
|
+
},
|
|
51
|
+
/**
|
|
52
|
+
* Class to be applied to the root element
|
|
53
|
+
*/
|
|
54
|
+
class: {
|
|
55
|
+
type: [String, Array, Object],
|
|
56
|
+
default: ""
|
|
57
|
+
},
|
|
58
|
+
/**
|
|
59
|
+
* Tags to unwrap separated by spaces
|
|
60
|
+
* Example: 'ul li'
|
|
61
|
+
*/
|
|
62
|
+
unwrap: {
|
|
63
|
+
type: [Boolean, String],
|
|
64
|
+
default: false
|
|
65
|
+
},
|
|
66
|
+
/**
|
|
67
|
+
* Async Data Unique Key
|
|
68
|
+
* @default `hash(props.value)`
|
|
69
|
+
*/
|
|
70
|
+
cacheKey: {
|
|
71
|
+
type: String,
|
|
72
|
+
default: void 0
|
|
73
|
+
},
|
|
74
|
+
/**
|
|
75
|
+
* Partial parsing (if partial is `true`, title and toc generation will not be generated)
|
|
76
|
+
*/
|
|
77
|
+
partial: {
|
|
78
|
+
type: Boolean,
|
|
79
|
+
default: true
|
|
80
|
+
},
|
|
81
|
+
/**
|
|
82
|
+
* The map of custom components to use for rendering.
|
|
83
|
+
*/
|
|
84
|
+
components: {
|
|
85
|
+
type: Object,
|
|
86
|
+
default: () => ({})
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
const key = computed(() => props.cacheKey ?? hashString(props.value));
|
|
90
|
+
const parse = createCachedParser({
|
|
91
|
+
...props.parserOptions,
|
|
92
|
+
toc: props.partial ? false : props.parserOptions?.toc,
|
|
93
|
+
contentHeading: props.partial ? false : props.parserOptions?.contentHeading
|
|
94
|
+
});
|
|
95
|
+
const { data, refresh, error } = await useAsyncData(key.value, async () => {
|
|
96
|
+
if (typeof props.value !== "string") {
|
|
97
|
+
return props.value;
|
|
98
|
+
}
|
|
99
|
+
return await parse(props.value);
|
|
100
|
+
});
|
|
101
|
+
const body = computed(() => props.excerpt ? data.value?.excerpt : data.value?.body);
|
|
102
|
+
watch(() => props.value, () => {
|
|
103
|
+
refresh();
|
|
104
|
+
});
|
|
105
|
+
function hashString(str) {
|
|
106
|
+
if (typeof str !== "string") {
|
|
107
|
+
str = JSON.stringify(str || "");
|
|
108
|
+
}
|
|
109
|
+
let hash = 0;
|
|
110
|
+
for (let i = 0; i < str.length; i++) {
|
|
111
|
+
const char = str.charCodeAt(i);
|
|
112
|
+
hash = (hash << 6) - hash + char;
|
|
113
|
+
hash = hash & hash;
|
|
114
|
+
}
|
|
115
|
+
return `mdc-${hash === 0 ? "0000" : hash.toString(36)}-key`;
|
|
116
|
+
}
|
|
117
|
+
</script>
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { type PropType, type DefineComponent } from 'vue';
|
|
2
|
+
import type { MDCParseOptions } from '@nuxtjs/mdc';
|
|
3
|
+
declare var __VLS_1: {
|
|
4
|
+
data: any;
|
|
5
|
+
body: any;
|
|
6
|
+
toc: any;
|
|
7
|
+
excerpt: any;
|
|
8
|
+
error: import("nuxt/app").NuxtError<unknown> | null;
|
|
9
|
+
};
|
|
10
|
+
type __VLS_Slots = {} & {
|
|
11
|
+
default?: (props: typeof __VLS_1) => any;
|
|
12
|
+
};
|
|
13
|
+
declare const __VLS_component: DefineComponent<import("vue").ExtractPropTypes<{
|
|
14
|
+
tag: {
|
|
15
|
+
type: (StringConstructor | BooleanConstructor)[];
|
|
16
|
+
default: string;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Raw markdown string or parsed markdown object from `parseMarkdown`
|
|
20
|
+
*/
|
|
21
|
+
value: {
|
|
22
|
+
type: (StringConstructor | ObjectConstructor)[];
|
|
23
|
+
required: true;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Render only the excerpt
|
|
27
|
+
*/
|
|
28
|
+
excerpt: {
|
|
29
|
+
type: BooleanConstructor;
|
|
30
|
+
default: boolean;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Options for `parseMarkdown`
|
|
34
|
+
*/
|
|
35
|
+
parserOptions: {
|
|
36
|
+
type: PropType<MDCParseOptions>;
|
|
37
|
+
default: () => {};
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Class to be applied to the root element
|
|
41
|
+
*/
|
|
42
|
+
class: {
|
|
43
|
+
type: (StringConstructor | ObjectConstructor | ArrayConstructor)[];
|
|
44
|
+
default: string;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Tags to unwrap separated by spaces
|
|
48
|
+
* Example: 'ul li'
|
|
49
|
+
*/
|
|
50
|
+
unwrap: {
|
|
51
|
+
type: (StringConstructor | BooleanConstructor)[];
|
|
52
|
+
default: boolean;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Async Data Unique Key
|
|
56
|
+
* @default `hash(props.value)`
|
|
57
|
+
*/
|
|
58
|
+
cacheKey: {
|
|
59
|
+
type: StringConstructor;
|
|
60
|
+
default: undefined;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Partial parsing (if partial is `true`, title and toc generation will not be generated)
|
|
64
|
+
*/
|
|
65
|
+
partial: {
|
|
66
|
+
type: BooleanConstructor;
|
|
67
|
+
default: boolean;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* The map of custom components to use for rendering.
|
|
71
|
+
*/
|
|
72
|
+
components: {
|
|
73
|
+
type: PropType<Record<string, string | DefineComponent<any, any, any>>>;
|
|
74
|
+
default: () => {};
|
|
75
|
+
};
|
|
76
|
+
}>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
77
|
+
tag: {
|
|
78
|
+
type: (StringConstructor | BooleanConstructor)[];
|
|
79
|
+
default: string;
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Raw markdown string or parsed markdown object from `parseMarkdown`
|
|
83
|
+
*/
|
|
84
|
+
value: {
|
|
85
|
+
type: (StringConstructor | ObjectConstructor)[];
|
|
86
|
+
required: true;
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* Render only the excerpt
|
|
90
|
+
*/
|
|
91
|
+
excerpt: {
|
|
92
|
+
type: BooleanConstructor;
|
|
93
|
+
default: boolean;
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* Options for `parseMarkdown`
|
|
97
|
+
*/
|
|
98
|
+
parserOptions: {
|
|
99
|
+
type: PropType<MDCParseOptions>;
|
|
100
|
+
default: () => {};
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* Class to be applied to the root element
|
|
104
|
+
*/
|
|
105
|
+
class: {
|
|
106
|
+
type: (StringConstructor | ObjectConstructor | ArrayConstructor)[];
|
|
107
|
+
default: string;
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* Tags to unwrap separated by spaces
|
|
111
|
+
* Example: 'ul li'
|
|
112
|
+
*/
|
|
113
|
+
unwrap: {
|
|
114
|
+
type: (StringConstructor | BooleanConstructor)[];
|
|
115
|
+
default: boolean;
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* Async Data Unique Key
|
|
119
|
+
* @default `hash(props.value)`
|
|
120
|
+
*/
|
|
121
|
+
cacheKey: {
|
|
122
|
+
type: StringConstructor;
|
|
123
|
+
default: undefined;
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* Partial parsing (if partial is `true`, title and toc generation will not be generated)
|
|
127
|
+
*/
|
|
128
|
+
partial: {
|
|
129
|
+
type: BooleanConstructor;
|
|
130
|
+
default: boolean;
|
|
131
|
+
};
|
|
132
|
+
/**
|
|
133
|
+
* The map of custom components to use for rendering.
|
|
134
|
+
*/
|
|
135
|
+
components: {
|
|
136
|
+
type: PropType<Record<string, string | DefineComponent<any, any, any>>>;
|
|
137
|
+
default: () => {};
|
|
138
|
+
};
|
|
139
|
+
}>> & Readonly<{}>, {
|
|
140
|
+
tag: string | boolean;
|
|
141
|
+
excerpt: boolean;
|
|
142
|
+
parserOptions: MDCParseOptions;
|
|
143
|
+
class: string | unknown[] | Record<string, any>;
|
|
144
|
+
unwrap: string | boolean;
|
|
145
|
+
cacheKey: string;
|
|
146
|
+
partial: boolean;
|
|
147
|
+
components: Record<string, string | DefineComponent<any, any, any>>;
|
|
148
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
149
|
+
declare const _default: __VLS_WithSlots<typeof __VLS_component, __VLS_Slots>;
|
|
150
|
+
export default _default;
|
|
151
|
+
type __VLS_WithSlots<T, S> = T & {
|
|
152
|
+
new (): {
|
|
153
|
+
$slots: S;
|
|
154
|
+
};
|
|
155
|
+
};
|