@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.
Files changed (66) hide show
  1. package/README.md +8 -8
  2. package/dist/config.d.mts +1 -1
  3. package/dist/module.d.mts +15 -3
  4. package/dist/module.json +3 -3
  5. package/dist/module.mjs +9 -4
  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/mdc-remark.js +63 -50
  58. package/dist/runtime/utils/slot.d.ts +1 -1
  59. package/dist/shared/{mdc.4762b8bc.d.ts → mdc.BkZUOs7X.d.mts} +2 -1
  60. package/dist/types.d.mts +5 -1
  61. package/package.json +32 -34
  62. package/dist/config.d.ts +0 -4
  63. package/dist/module.cjs +0 -5
  64. package/dist/module.d.ts +0 -570
  65. package/dist/shared/mdc.4762b8bc.d.mts +0 -66
  66. package/dist/types.d.ts +0 -1
@@ -8,38 +8,35 @@
8
8
  />
9
9
  </template>
10
10
 
11
- <script setup lang="ts">
12
- import { withTrailingSlash, withLeadingSlash, joinURL } from 'ufo'
13
- import { useRuntimeConfig, computed } from '#imports'
14
-
15
- import ImageComponent from '#build/mdc-image-component.mjs'
16
-
11
+ <script setup>
12
+ import { withTrailingSlash, withLeadingSlash, joinURL } from "ufo";
13
+ import { useRuntimeConfig, computed } from "#imports";
14
+ import ImageComponent from "#build/mdc-image-component.mjs";
17
15
  const props = defineProps({
18
16
  src: {
19
17
  type: String,
20
- default: ''
18
+ default: ""
21
19
  },
22
20
  alt: {
23
21
  type: String,
24
- default: ''
22
+ default: ""
25
23
  },
26
24
  width: {
27
25
  type: [String, Number],
28
- default: undefined
26
+ default: void 0
29
27
  },
30
28
  height: {
31
29
  type: [String, Number],
32
- default: undefined
30
+ default: void 0
33
31
  }
34
- })
35
-
32
+ });
36
33
  const refinedSrc = computed(() => {
37
- if (props.src?.startsWith('/') && !props.src.startsWith('//')) {
38
- const _base = withLeadingSlash(withTrailingSlash(useRuntimeConfig().app.baseURL))
39
- if (_base !== '/' && !props.src.startsWith(_base)) {
40
- return joinURL(_base, props.src)
34
+ if (props.src?.startsWith("/") && !props.src.startsWith("//")) {
35
+ const _base = withLeadingSlash(withTrailingSlash(useRuntimeConfig().app.baseURL));
36
+ if (_base !== "/" && !props.src.startsWith(_base)) {
37
+ return joinURL(_base, props.src);
41
38
  }
42
39
  }
43
- return props.src
44
- })
40
+ return props.src;
41
+ });
45
42
  </script>
@@ -0,0 +1,41 @@
1
+ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
2
+ src: {
3
+ type: StringConstructor;
4
+ default: string;
5
+ };
6
+ alt: {
7
+ type: StringConstructor;
8
+ default: string;
9
+ };
10
+ width: {
11
+ type: (StringConstructor | NumberConstructor)[];
12
+ default: undefined;
13
+ };
14
+ height: {
15
+ type: (StringConstructor | NumberConstructor)[];
16
+ default: undefined;
17
+ };
18
+ }>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
19
+ src: {
20
+ type: StringConstructor;
21
+ default: string;
22
+ };
23
+ alt: {
24
+ type: StringConstructor;
25
+ default: string;
26
+ };
27
+ width: {
28
+ type: (StringConstructor | NumberConstructor)[];
29
+ default: undefined;
30
+ };
31
+ height: {
32
+ type: (StringConstructor | NumberConstructor)[];
33
+ default: undefined;
34
+ };
35
+ }>> & Readonly<{}>, {
36
+ src: string;
37
+ alt: string;
38
+ width: string | number;
39
+ height: string | number;
40
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
41
+ export default _default;
@@ -0,0 +1,12 @@
1
+ declare var __VLS_1: {};
2
+ type __VLS_Slots = {} & {
3
+ default?: (props: typeof __VLS_1) => any;
4
+ };
5
+ declare const __VLS_component: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
6
+ declare const _default: __VLS_WithSlots<typeof __VLS_component, __VLS_Slots>;
7
+ export default _default;
8
+ type __VLS_WithSlots<T, S> = T & {
9
+ new (): {
10
+ $slots: S;
11
+ };
12
+ };
@@ -0,0 +1,12 @@
1
+ declare var __VLS_1: {};
2
+ type __VLS_Slots = {} & {
3
+ default?: (props: typeof __VLS_1) => any;
4
+ };
5
+ declare const __VLS_component: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
6
+ declare const _default: __VLS_WithSlots<typeof __VLS_component, __VLS_Slots>;
7
+ export default _default;
8
+ type __VLS_WithSlots<T, S> = T & {
9
+ new (): {
10
+ $slots: S;
11
+ };
12
+ };
@@ -0,0 +1,12 @@
1
+ declare var __VLS_1: {};
2
+ type __VLS_Slots = {} & {
3
+ default?: (props: typeof __VLS_1) => any;
4
+ };
5
+ declare const __VLS_component: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
6
+ declare const _default: __VLS_WithSlots<typeof __VLS_component, __VLS_Slots>;
7
+ export default _default;
8
+ type __VLS_WithSlots<T, S> = T & {
9
+ new (): {
10
+ $slots: S;
11
+ };
12
+ };
@@ -2,11 +2,11 @@
2
2
  <pre :class="$props.class"><slot /></pre>
3
3
  </template>
4
4
 
5
- <script setup lang="ts">
5
+ <script setup>
6
6
  defineProps({
7
7
  code: {
8
8
  type: String,
9
- default: ''
9
+ default: ""
10
10
  },
11
11
  language: {
12
12
  type: String,
@@ -17,7 +17,7 @@ defineProps({
17
17
  default: null
18
18
  },
19
19
  highlights: {
20
- type: Array as () => number[],
20
+ type: Array,
21
21
  default: () => []
22
22
  },
23
23
  meta: {
@@ -28,7 +28,7 @@ defineProps({
28
28
  type: String,
29
29
  default: null
30
30
  }
31
- })
31
+ });
32
32
  </script>
33
33
 
34
34
  <style>
@@ -0,0 +1,69 @@
1
+ declare var __VLS_1: {};
2
+ type __VLS_Slots = {} & {
3
+ default?: (props: typeof __VLS_1) => any;
4
+ };
5
+ declare const __VLS_component: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
6
+ code: {
7
+ type: StringConstructor;
8
+ default: string;
9
+ };
10
+ language: {
11
+ type: StringConstructor;
12
+ default: null;
13
+ };
14
+ filename: {
15
+ type: StringConstructor;
16
+ default: null;
17
+ };
18
+ highlights: {
19
+ type: () => number[];
20
+ default: () => never[];
21
+ };
22
+ meta: {
23
+ type: StringConstructor;
24
+ default: null;
25
+ };
26
+ class: {
27
+ type: StringConstructor;
28
+ default: null;
29
+ };
30
+ }>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
31
+ code: {
32
+ type: StringConstructor;
33
+ default: string;
34
+ };
35
+ language: {
36
+ type: StringConstructor;
37
+ default: null;
38
+ };
39
+ filename: {
40
+ type: StringConstructor;
41
+ default: null;
42
+ };
43
+ highlights: {
44
+ type: () => number[];
45
+ default: () => never[];
46
+ };
47
+ meta: {
48
+ type: StringConstructor;
49
+ default: null;
50
+ };
51
+ class: {
52
+ type: StringConstructor;
53
+ default: null;
54
+ };
55
+ }>> & Readonly<{}>, {
56
+ class: string;
57
+ code: string;
58
+ meta: string;
59
+ language: string;
60
+ highlights: number[];
61
+ filename: string;
62
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
63
+ declare const _default: __VLS_WithSlots<typeof __VLS_component, __VLS_Slots>;
64
+ export default _default;
65
+ type __VLS_WithSlots<T, S> = T & {
66
+ new (): {
67
+ $slots: S;
68
+ };
69
+ };
@@ -4,12 +4,12 @@
4
4
  </div>
5
5
  </template>
6
6
 
7
- <script setup lang="ts">
7
+ <script setup>
8
8
  defineProps({
9
9
  src: {
10
10
  type: String,
11
- default: ''
11
+ default: ""
12
12
  }
13
- })
14
- const isDev = import.meta.dev
13
+ });
14
+ const isDev = import.meta.dev;
15
15
  </script>
@@ -0,0 +1,14 @@
1
+ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
2
+ src: {
3
+ type: StringConstructor;
4
+ default: string;
5
+ };
6
+ }>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
7
+ src: {
8
+ type: StringConstructor;
9
+ default: string;
10
+ };
11
+ }>> & Readonly<{}>, {
12
+ src: string;
13
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
14
+ export default _default;
@@ -0,0 +1,12 @@
1
+ declare var __VLS_1: {};
2
+ type __VLS_Slots = {} & {
3
+ default?: (props: typeof __VLS_1) => any;
4
+ };
5
+ declare const __VLS_component: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
6
+ declare const _default: __VLS_WithSlots<typeof __VLS_component, __VLS_Slots>;
7
+ export default _default;
8
+ type __VLS_WithSlots<T, S> = T & {
9
+ new (): {
10
+ $slots: S;
11
+ };
12
+ };
@@ -0,0 +1,12 @@
1
+ declare var __VLS_1: {};
2
+ type __VLS_Slots = {} & {
3
+ default?: (props: typeof __VLS_1) => any;
4
+ };
5
+ declare const __VLS_component: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
6
+ declare const _default: __VLS_WithSlots<typeof __VLS_component, __VLS_Slots>;
7
+ export default _default;
8
+ type __VLS_WithSlots<T, S> = T & {
9
+ new (): {
10
+ $slots: S;
11
+ };
12
+ };
@@ -0,0 +1,12 @@
1
+ declare var __VLS_1: {};
2
+ type __VLS_Slots = {} & {
3
+ default?: (props: typeof __VLS_1) => any;
4
+ };
5
+ declare const __VLS_component: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
6
+ declare const _default: __VLS_WithSlots<typeof __VLS_component, __VLS_Slots>;
7
+ export default _default;
8
+ type __VLS_WithSlots<T, S> = T & {
9
+ new (): {
10
+ $slots: S;
11
+ };
12
+ };
@@ -0,0 +1,12 @@
1
+ declare var __VLS_1: {};
2
+ type __VLS_Slots = {} & {
3
+ default?: (props: typeof __VLS_1) => any;
4
+ };
5
+ declare const __VLS_component: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
6
+ declare const _default: __VLS_WithSlots<typeof __VLS_component, __VLS_Slots>;
7
+ export default _default;
8
+ type __VLS_WithSlots<T, S> = T & {
9
+ new (): {
10
+ $slots: S;
11
+ };
12
+ };
@@ -0,0 +1,12 @@
1
+ declare var __VLS_1: {};
2
+ type __VLS_Slots = {} & {
3
+ default?: (props: typeof __VLS_1) => any;
4
+ };
5
+ declare const __VLS_component: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
6
+ declare const _default: __VLS_WithSlots<typeof __VLS_component, __VLS_Slots>;
7
+ export default _default;
8
+ type __VLS_WithSlots<T, S> = T & {
9
+ new (): {
10
+ $slots: S;
11
+ };
12
+ };
@@ -0,0 +1,12 @@
1
+ declare var __VLS_1: {};
2
+ type __VLS_Slots = {} & {
3
+ default?: (props: typeof __VLS_1) => any;
4
+ };
5
+ declare const __VLS_component: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
6
+ declare const _default: __VLS_WithSlots<typeof __VLS_component, __VLS_Slots>;
7
+ export default _default;
8
+ type __VLS_WithSlots<T, S> = T & {
9
+ new (): {
10
+ $slots: S;
11
+ };
12
+ };
@@ -0,0 +1,12 @@
1
+ declare var __VLS_1: {};
2
+ type __VLS_Slots = {} & {
3
+ default?: (props: typeof __VLS_1) => any;
4
+ };
5
+ declare const __VLS_component: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
6
+ declare const _default: __VLS_WithSlots<typeof __VLS_component, __VLS_Slots>;
7
+ export default _default;
8
+ type __VLS_WithSlots<T, S> = T & {
9
+ new (): {
10
+ $slots: S;
11
+ };
12
+ };
@@ -0,0 +1,12 @@
1
+ declare var __VLS_1: {};
2
+ type __VLS_Slots = {} & {
3
+ default?: (props: typeof __VLS_1) => any;
4
+ };
5
+ declare const __VLS_component: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
6
+ declare const _default: __VLS_WithSlots<typeof __VLS_component, __VLS_Slots>;
7
+ export default _default;
8
+ type __VLS_WithSlots<T, S> = T & {
9
+ new (): {
10
+ $slots: S;
11
+ };
12
+ };
@@ -1,4 +1,4 @@
1
- import { type LanguageInput, type ThemeInput, type RegexEngine } from 'shiki';
1
+ import type { LanguageInput, ThemeInput, RegexEngine } from '@shikijs/types';
2
2
  import type { MdcConfig, Highlighter } from '@nuxtjs/mdc';
3
3
  export interface CreateShikiHighlighterOptions {
4
4
  themes?: ThemeInput[];
@@ -1,4 +1,4 @@
1
- import { createJavaScriptRegexEngine } from "shiki";
1
+ import { createJavaScriptRegexEngine } from "shiki/engine/javascript";
2
2
  export function createShikiHighlighter({
3
3
  langs = [],
4
4
  themes = [],
@@ -92,19 +92,22 @@ export function createShikiHighlighter({
92
92
  }
93
93
  }
94
94
  }
95
- const transformers = [
96
- ...baseTransformers
97
- ];
95
+ const transformersMap = /* @__PURE__ */ new Map();
96
+ for (const transformer of baseTransformers) {
97
+ transformersMap.set(transformer.name || `transformer:${Math.random()}-${transformer.constructor.name}`, transformer);
98
+ }
98
99
  for (const config of await getConfigs()) {
99
100
  const newTransformers = typeof config.shiki?.transformers === "function" ? await config.shiki?.transformers(code, lang, theme, options) : config.shiki?.transformers || [];
100
- transformers.push(...newTransformers);
101
+ for (const transformer of newTransformers) {
102
+ transformersMap.set(transformer.name || `transformer:${Math.random()}-${transformer.constructor.name}`, transformer);
103
+ }
101
104
  }
102
105
  const root = shiki2.codeToHast(code.trimEnd(), {
103
106
  lang,
104
107
  ...codeToHastOptions,
105
108
  themes: themesObject,
106
109
  transformers: [
107
- ...transformers,
110
+ ...transformersMap.values(),
108
111
  {
109
112
  name: "mdc:highlight",
110
113
  line(node, line) {
@@ -2,4 +2,5 @@ export { parseMarkdown, createMarkdownParser, createParseProcessor } from './par
2
2
  export { stringifyMarkdown, createMarkdownStringifier, createStringifyProcessor } from './stringify/index.js';
3
3
  export { rehypeHighlight } from './highlighter/rehype.js';
4
4
  export { createShikiHighlighter } from './highlighter/shiki.js';
5
+ export { createCachedParser } from './parser/cached.js';
5
6
  export * from './utils/node.js';
@@ -2,4 +2,5 @@ export { parseMarkdown, createMarkdownParser, createParseProcessor } from "./par
2
2
  export { stringifyMarkdown, createMarkdownStringifier, createStringifyProcessor } from "./stringify/index.js";
3
3
  export { rehypeHighlight } from "./highlighter/rehype.js";
4
4
  export { createShikiHighlighter } from "./highlighter/shiki.js";
5
+ export { createCachedParser } from "./parser/cached.js";
5
6
  export * from "./utils/node.js";
@@ -0,0 +1,2 @@
1
+ import type { MDCParseOptions } from '@nuxtjs/mdc';
2
+ export declare function createCachedParser(parserOptions: MDCParseOptions): (value: string) => Promise<any>;
@@ -0,0 +1,44 @@
1
+ export function createCachedParser(parserOptions) {
2
+ let processor;
3
+ let lastValue = "";
4
+ let lastParse;
5
+ return async function parse(value) {
6
+ if (!processor) {
7
+ processor = await import("@nuxtjs/mdc/runtime").then((m) => m.createParseProcessor({
8
+ ...parserOptions,
9
+ keepPosition: true
10
+ }));
11
+ }
12
+ if (!value.startsWith(lastValue)) {
13
+ lastValue = "";
14
+ lastParse = void 0;
15
+ }
16
+ let startOffset = 0;
17
+ if (lastParse?.body?.children.length && lastParse.body.children.length > 1) {
18
+ const lastCompleteNode = lastParse.body.children[lastParse.body.children.length - 2];
19
+ if (lastCompleteNode?.position?.end) {
20
+ startOffset = lastCompleteNode.position.end;
21
+ }
22
+ }
23
+ const processorResult = await processor.process({ value: value.slice(startOffset) });
24
+ const result = processorResult?.result;
25
+ if (result) {
26
+ const body = {
27
+ type: "root",
28
+ children: [
29
+ ...startOffset > 0 ? lastParse?.body?.children.slice(0, -1) || [] : [],
30
+ ...result.body.children.map((child) => ({
31
+ ...child,
32
+ position: child.position && {
33
+ start: child.position.start + startOffset,
34
+ end: child.position.end + startOffset
35
+ }
36
+ }))
37
+ ]
38
+ };
39
+ lastParse = { ...result, body };
40
+ lastValue = value;
41
+ return lastParse;
42
+ }
43
+ };
44
+ }
@@ -10,6 +10,10 @@ export function compileHast(options = {}) {
10
10
  children: node.children.map((child) => compileToJSON(child, node)).filter(Boolean)
11
11
  };
12
12
  }
13
+ const position = node.position?.start?.offset && node.position?.end?.offset ? {
14
+ start: node.position.start.offset,
15
+ end: node.position.end.offset
16
+ } : void 0;
13
17
  if (node.type === "element") {
14
18
  if (node.tagName === "p" && node.children.every((child) => child.type === "text" && /^\s*$/.test(child.value))) {
15
19
  return null;
@@ -40,26 +44,24 @@ export function compileHast(options = {}) {
40
44
  node.tagName = "template";
41
45
  }
42
46
  const children = (node.tagName === "template" && node.content?.children.length ? node.content.children : node.children).map((child) => compileToJSON(child, node)).filter(Boolean);
43
- return {
47
+ const result = {
44
48
  type: "element",
45
49
  tag: node.tagName,
46
50
  props: validateProps(node.tagName, node.properties),
47
51
  children
48
52
  };
53
+ if (options.keepPosition) {
54
+ result.position = position;
55
+ }
56
+ return result;
49
57
  }
50
58
  if (node.type === "text") {
51
59
  if (!/^\n+$/.test(node.value || "") || parent?.properties?.emptyLinePlaceholder) {
52
- return {
53
- type: "text",
54
- value: node.value
55
- };
60
+ return options.keepPosition ? { type: "text", value: node.value, position } : { type: "text", value: node.value };
56
61
  }
57
62
  }
58
63
  if (options.keepComments && node.type === "comment") {
59
- return {
60
- type: "comment",
61
- value: node.value
62
- };
64
+ return options.keepPosition ? { type: "comment", value: node.value, position } : { type: "comment", value: node.value };
63
65
  }
64
66
  return null;
65
67
  }
@@ -9,13 +9,17 @@ export function parseThematicBlock(lang) {
9
9
  }
10
10
  const languageMatches = lang.replace(/[{|[](.+)/, "").match(/^[^ \t]+(?=[ \t]|$)/);
11
11
  const highlightTokensMatches = lang.match(/\{([^}]*)\}/);
12
- const filenameMatches = lang.match(/\[((\\\]|[^\]])*)\]/);
12
+ const filenameMatches = lang.match(/\[(.*)\]/);
13
13
  const meta = lang.replace(languageMatches?.[0] ?? "", "").replace(highlightTokensMatches?.[0] ?? "", "").replace(filenameMatches?.[0] ?? "", "").trim();
14
+ let filename = void 0;
15
+ if (filenameMatches?.[1]) {
16
+ filename = filenameMatches[1].replace(/\\([[\]{}().*+?^$|])/g, "$1");
17
+ }
14
18
  return {
15
19
  language: languageMatches?.[0] || void 0,
16
20
  highlights: parseHighlightedLines(highlightTokensMatches?.[1] || void 0),
17
21
  // https://github.com/nuxt/content/pull/2169
18
- filename: filenameMatches?.[1].replace(/\\\]/g, "]") || void 0,
22
+ filename,
19
23
  meta
20
24
  };
21
25
  }
@@ -44,10 +44,14 @@ export const createParseProcessor = async (inlineOptions = {}) => {
44
44
  highlight: moduleOptions?.highlight
45
45
  }, defaults);
46
46
  if (options.rehype?.plugins?.highlight) {
47
- options.rehype.plugins.highlight.options = {
48
- ...options.rehype.plugins.highlight.options || {},
49
- ...options.highlight || {}
50
- };
47
+ if (inlineOptions.highlight === false) {
48
+ delete options.rehype.plugins.highlight;
49
+ } else {
50
+ options.rehype.plugins.highlight.options = {
51
+ ...options.rehype.plugins.highlight.options || {},
52
+ ...options.highlight || {}
53
+ };
54
+ }
51
55
  }
52
56
  let processor = unified();
53
57
  for (const config of mdcConfigs) {
@@ -103,7 +107,7 @@ export const createMarkdownParser = async (inlineOptions = {}) => {
103
107
  };
104
108
  export const parseMarkdown = async (md, markdownParserOptions = {}, parseOptions = {}) => {
105
109
  const parser = await createMarkdownParser(markdownParserOptions);
106
- return parser(md, parseOptions);
110
+ return parser(md.replace(/\r\n/g, "\n"), parseOptions);
107
111
  };
108
112
  export function contentHeading(body) {
109
113
  let title = "";