@nuxtjs/mdc 0.16.1 → 0.17.1

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.
Files changed (67) hide show
  1. package/README.md +8 -8
  2. package/dist/config.d.mts +1 -1
  3. package/dist/module.d.mts +18 -39
  4. package/dist/module.json +3 -3
  5. package/dist/module.mjs +11 -6
  6. package/dist/runtime/components/MDC.vue +25 -33
  7. package/dist/runtime/components/MDC.vue.d.ts +140 -0
  8. package/dist/runtime/components/MDCCached.vue +117 -0
  9. package/dist/runtime/components/MDCCached.vue.d.ts +155 -0
  10. package/dist/runtime/components/MDCRenderer.vue +19 -13
  11. package/dist/runtime/components/MDCRenderer.vue.d.ts +11 -123
  12. package/dist/runtime/components/MDCSlot.vue.d.ts +2 -2
  13. package/dist/runtime/components/prose/ProseA.vue +5 -7
  14. package/dist/runtime/components/prose/ProseA.vue.d.ts +36 -0
  15. package/dist/runtime/components/prose/ProseBlockquote.vue.d.ts +12 -0
  16. package/dist/runtime/components/prose/ProseCode.vue.d.ts +12 -0
  17. package/dist/runtime/components/prose/ProseEm.vue.d.ts +12 -0
  18. package/dist/runtime/components/prose/ProseH1.vue +7 -7
  19. package/dist/runtime/components/prose/ProseH1.vue.d.ts +17 -0
  20. package/dist/runtime/components/prose/ProseH2.vue +7 -7
  21. package/dist/runtime/components/prose/ProseH2.vue.d.ts +17 -0
  22. package/dist/runtime/components/prose/ProseH3.vue +7 -7
  23. package/dist/runtime/components/prose/ProseH3.vue.d.ts +17 -0
  24. package/dist/runtime/components/prose/ProseH4.vue +7 -7
  25. package/dist/runtime/components/prose/ProseH4.vue.d.ts +17 -0
  26. package/dist/runtime/components/prose/ProseH5.vue +7 -7
  27. package/dist/runtime/components/prose/ProseH5.vue.d.ts +17 -0
  28. package/dist/runtime/components/prose/ProseH6.vue +7 -7
  29. package/dist/runtime/components/prose/ProseH6.vue.d.ts +17 -0
  30. package/dist/runtime/components/prose/ProseHr.vue.d.ts +2 -0
  31. package/dist/runtime/components/prose/ProseImg.vue +15 -18
  32. package/dist/runtime/components/prose/ProseImg.vue.d.ts +41 -0
  33. package/dist/runtime/components/prose/ProseLi.vue.d.ts +12 -0
  34. package/dist/runtime/components/prose/ProseOl.vue.d.ts +12 -0
  35. package/dist/runtime/components/prose/ProseP.vue.d.ts +12 -0
  36. package/dist/runtime/components/prose/ProsePre.vue +4 -4
  37. package/dist/runtime/components/prose/ProsePre.vue.d.ts +69 -0
  38. package/dist/runtime/components/prose/ProseScript.vue +4 -4
  39. package/dist/runtime/components/prose/ProseScript.vue.d.ts +14 -0
  40. package/dist/runtime/components/prose/ProseStrong.vue.d.ts +12 -0
  41. package/dist/runtime/components/prose/ProseTable.vue.d.ts +12 -0
  42. package/dist/runtime/components/prose/ProseTbody.vue.d.ts +12 -0
  43. package/dist/runtime/components/prose/ProseTd.vue.d.ts +12 -0
  44. package/dist/runtime/components/prose/ProseTh.vue.d.ts +12 -0
  45. package/dist/runtime/components/prose/ProseThead.vue.d.ts +12 -0
  46. package/dist/runtime/components/prose/ProseTr.vue.d.ts +12 -0
  47. package/dist/runtime/components/prose/ProseUl.vue.d.ts +12 -0
  48. package/dist/runtime/highlighter/shiki.d.ts +1 -1
  49. package/dist/runtime/highlighter/shiki.js +9 -6
  50. package/dist/runtime/index.d.ts +1 -0
  51. package/dist/runtime/index.js +1 -0
  52. package/dist/runtime/parser/cached.d.ts +2 -0
  53. package/dist/runtime/parser/cached.js +44 -0
  54. package/dist/runtime/parser/compiler.js +11 -9
  55. package/dist/runtime/parser/handlers/utils.js +6 -2
  56. package/dist/runtime/parser/index.js +9 -5
  57. package/dist/runtime/stringify/index.d.ts +1 -1
  58. package/dist/runtime/stringify/mdc-remark.js +50 -14
  59. package/dist/runtime/utils/slot.d.ts +1 -1
  60. package/dist/shared/{mdc.86c0ccda.d.ts → mdc.BkZUOs7X.d.mts} +3 -18
  61. package/dist/types.d.mts +3 -5
  62. package/package.json +36 -38
  63. package/dist/config.d.ts +0 -4
  64. package/dist/module.cjs +0 -5
  65. package/dist/module.d.ts +0 -603
  66. package/dist/shared/mdc.86c0ccda.d.mts +0 -82
  67. package/dist/types.d.ts +0 -7
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.nuxtjs.org/guide/writing/mdc
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 'shiki/themes/material-theme-palenight.mjs'
385
- import HtmlLang from 'shiki/langs/html.mjs'
386
- import MdcLang from 'shiki/langs/mdc.mjs'
387
- import TsLang from 'shiki/langs/typescript.mjs'
388
- import VueLang from 'shiki/langs/vue.mjs'
389
- import ScssLang from 'shiki/langs/scss.mjs'
390
- import YamlLang from 'shiki/langs/yaml.mjs'
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
@@ -1,4 +1,4 @@
1
- export { d as defineConfig } from './shared/mdc.86c0ccda.mjs';
1
+ export { d as defineConfig } from './shared/mdc.BkZUOs7X.mjs';
2
2
  import 'shiki';
3
3
  import 'unified';
4
4
  import 'hast';
package/dist/module.d.mts CHANGED
@@ -1,25 +1,32 @@
1
1
  import * as _nuxt_schema from '@nuxt/schema';
2
- import type { BundledLanguage, BundledTheme, LanguageRegistration, ThemeRegistrationAny } from 'shiki';
3
- import type { Options } from 'remark-rehype';
4
- import type { M as MdcConfig, R as RehypeHighlightOption, a as MdcThemeOptions } from './shared/mdc.86c0ccda.mjs';
5
- export { A as Awaitable, b as HighlightResult, c as Highlighter, H as HighlighterOptions, d as defineConfig } from './shared/mdc.86c0ccda.mjs';
6
- import type { Options as Options$1 } from 'remark-stringify';
2
+ import { BundledLanguage, LanguageRegistration, BundledTheme, ThemeRegistrationAny } from 'shiki';
3
+ import { Options } from 'remark-rehype';
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
+ 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 = {
@@ -44,14 +51,6 @@ interface Toc {
44
51
  links: TocLink[];
45
52
  }
46
53
 
47
-
48
-
49
-
50
-
51
-
52
-
53
-
54
-
55
54
  interface RemarkPlugin {
56
55
  instance?: any;
57
56
  options?: Array<any> | Record<string, any>;
@@ -77,6 +76,10 @@ interface MDCParseOptions {
77
76
  searchDepth?: number;
78
77
  } | false;
79
78
  keepComments?: boolean;
79
+ /**
80
+ * Keep the position of the node
81
+ */
82
+ keepPosition?: boolean;
80
83
  /**
81
84
  * Extract content heading from the markdown file.
82
85
  *
@@ -95,8 +98,6 @@ interface MDCParserResult {
95
98
  toc: Toc | undefined;
96
99
  }
97
100
 
98
-
99
-
100
101
  interface MDCStringifyOptions {
101
102
  plugins?: {
102
103
  remarkStringify?: {
@@ -105,15 +106,6 @@ interface MDCStringifyOptions {
105
106
  };
106
107
  }
107
108
 
108
-
109
-
110
-
111
-
112
-
113
-
114
-
115
-
116
-
117
109
  interface UnistPlugin {
118
110
  src?: string;
119
111
  options?: Record<string, any>;
@@ -300,14 +292,6 @@ interface Parent$1 extends Node$1 {
300
292
  children: Node$1[];
301
293
  }
302
294
 
303
-
304
-
305
-
306
-
307
-
308
-
309
-
310
-
311
295
  /**
312
296
  * Info associated with hast nodes by the ecosystem.
313
297
  *
@@ -557,17 +541,12 @@ interface Text extends Literal {
557
541
  */
558
542
  type TextData = Data;
559
543
 
560
-
561
-
562
544
  interface MDCRenderOptions {
563
545
  documentMeta: MDCData;
564
546
  parentScope: any;
565
547
  resolveComponent: (component: any) => any;
566
548
  }
567
549
 
568
-
569
-
570
-
571
550
  declare const DefaultHighlightLangs: BundledLanguage[];
572
551
  declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
573
552
 
@@ -599,5 +578,5 @@ declare module '@nuxt/schema' {
599
578
  }
600
579
  }
601
580
 
602
- export { DefaultHighlightLangs, _default as default };
603
- export type { Comment, CommentData, Content, Data, Doctype, DoctypeData, Element, ElementContent, ElementContentMap, ElementData, Literal, Literals, MDCComment, MDCData, MDCElement, MDCNode, MDCParseOptions, MDCParserResult, MDCRenderOptions, MDCRoot, MDCStringifyOptions, MDCText, MdcConfig, MdcThemeOptions, ModuleOptions, Node, Nodes, Parent, Parents, Properties, RehypeHighlightOption, RehypePlugin, RemarkPlugin, Root, RootContent, RootContentMap, RootData, Text, TextData, Toc, TocLink, UnistPlugin };
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
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@nuxtjs/mdc",
3
3
  "configKey": "mdc",
4
- "version": "0.16.1",
4
+ "version": "0.17.1",
5
5
  "builder": {
6
- "@nuxt/module-builder": "0.8.4",
7
- "unbuild": "2.0.0"
6
+ "@nuxt/module-builder": "1.0.1",
7
+ "unbuild": "3.5.0"
8
8
  }
9
9
  }
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
 
@@ -11,7 +12,7 @@ const registerMDCSlotTransformer = (resolver) => {
11
12
  const compilerOptions = config.vue.template.compilerOptions;
12
13
  compilerOptions.nodeTransforms = [
13
14
  function viteMDCSlot(node, context) {
14
- const isVueSlotWithUnwrap = node.tag === "slot" && node.props.find((p) => p.name === "mdc-unwrap" || p.name === "bind" && p.rawName === ":mdc-unwrap");
15
+ const isVueSlotWithUnwrap = node.tag === "slot" && node.props.find((p) => p.name === "mdc-unwrap" || p.name === "mdcUnwrap" || p.name === "bind" && p.rawName === ":mdc-unwrap");
15
16
  const isMDCSlot = node.tag === "MDCSlot";
16
17
  if (isVueSlotWithUnwrap || isMDCSlot) {
17
18
  const transform = context.ssr ? context.nodeTransforms.find((nt) => nt.name === "ssrTransformSlotOutlet") : context.nodeTransforms.find((nt) => nt.name === "transformSlotOutlet");
@@ -79,7 +80,10 @@ async function mdcHighlighter({
79
80
  "import.meta.client ? import('shiki/wasm') : import('shiki/onig.wasm')"
80
81
  );
81
82
  }
82
- const { bundledLanguagesInfo } = await import('shiki/langs');
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" ? "import { createJavaScriptRegexEngine } from 'shiki/engine/javascript'" : "import { createOnigurumaEngine } from 'shiki/engine/oniguruma'",
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('shiki/langs/${lang}.mjs'),` : JSON.stringify(name) + ": " + JSON.stringify(lang) + ","),
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('shiki/themes/${theme}.mjs').then(r => r.default),` : JSON.stringify(theme.name) + ": " + JSON.stringify(theme) + ","),
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" });
@@ -345,7 +350,7 @@ const module = defineNuxtModule({
345
350
  filename: "mdc-image-component.mjs",
346
351
  write: true,
347
352
  getContents: ({ app }) => {
348
- const image = app.components.find((c) => c.pascalName === "NuxtImg" && !c.filePath.includes("nuxt/dist/app"));
353
+ const image = app.components.find((c) => c.pascalName === "NuxtImg" && !c.filePath.includes("nuxt/dist/app") && !c.filePath.includes("nuxt-nightly/dist/app"));
349
354
  return image ? `export { default } from "${image.filePath}"` : 'export default "img"';
350
355
  }
351
356
  });
@@ -17,16 +17,13 @@
17
17
  </slot>
18
18
  </template>
19
19
 
20
- <script setup lang="ts">
21
- import { useAsyncData } from 'nuxt/app'
22
- import { watch, computed, type PropType } from 'vue'
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: 'div'
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 as PropType<MDCParseOptions>,
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: undefined
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 !== 'string') {
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
- // Simple string hashing function
104
- function hashString(str: string | object) {
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 = ((hash << 6) - hash) + char
112
- hash = hash & hash // Convert to 64bit integer
102
+ const char = str.charCodeAt(i);
103
+ hash = (hash << 6) - hash + char;
104
+ hash = hash & hash;
113
105
  }
114
- return `mdc-${hash === 0 ? '0000' : hash.toString(36)}-key`
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>