@nuxtjs/mdc 0.16.1 → 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 +18 -39
  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 +50 -14
  58. package/dist/runtime/utils/slot.d.ts +1 -1
  59. package/dist/shared/{mdc.86c0ccda.d.ts → mdc.BkZUOs7X.d.mts} +3 -18
  60. package/dist/types.d.mts +3 -5
  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 -603
  65. package/dist/shared/mdc.86c0ccda.d.mts +0 -82
  66. package/dist/types.d.ts +0 -7
@@ -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 = "";
@@ -6,6 +6,8 @@ import { visit } from "unist-util-visit";
6
6
  import { format } from "hast-util-format";
7
7
  import { computeHighlightRanges, refineCodeLanguage } from "./utils.js";
8
8
  const mdcRemarkElementType = "mdc-element";
9
+ const mdastTextComponentType = "textDirective";
10
+ const mdcTextComponentType = "textComponent";
9
11
  const own = {}.hasOwnProperty;
10
12
  export function mdcRemark(options) {
11
13
  return function(node, _file) {
@@ -27,6 +29,26 @@ export function mdcRemark(options) {
27
29
  ...options?.nodeHandlers
28
30
  }
29
31
  });
32
+ visit(mdast, (node2) => node2.type === mdastTextComponentType, (node2, index, parent) => {
33
+ node2.type = mdcTextComponentType;
34
+ if (node2.name === "binding") {
35
+ return;
36
+ }
37
+ if (index && parent && parent.children) {
38
+ if (index > 0 && parent.children[index - 1].type === "text") {
39
+ const text = parent.children[index - 1];
40
+ if (!["\n", " ", " "].includes(text.value.slice(-1))) {
41
+ text.value += " ";
42
+ }
43
+ }
44
+ if (index && index < parent.children.length - 1 && parent.children[index + 1].type === "text") {
45
+ const text = parent.children[index + 1];
46
+ if (!["\n", " ", " ", ",", "."].includes(text.value.slice(0, 1))) {
47
+ text.value = " " + text.value;
48
+ }
49
+ }
50
+ }
51
+ });
30
52
  return mdast;
31
53
  };
32
54
  }
@@ -64,6 +86,13 @@ const mdcRemarkNodeHandlers = {
64
86
  if (node.properties && node.properties.dataMdast === "ignore") {
65
87
  return;
66
88
  }
89
+ if (node.properties && (node.properties.className || node.properties["class-name"])) {
90
+ const pascal = Array.isArray(node.properties.className || "") ? node.properties.className : String(node.properties.className || "").split(" ");
91
+ const kebab = Array.isArray(node.properties["class-name"] || "") ? node.properties["class-name"] : String(node.properties["class-name"] || "").split(" ");
92
+ node.properties.class = [node.properties.class || "", ...pascal, ...kebab].filter(Boolean).join(" ");
93
+ Reflect.deleteProperty(node.properties, "className");
94
+ Reflect.deleteProperty(node.properties, "class-name");
95
+ }
67
96
  if (own.call(state.handlers, node.tagName)) {
68
97
  return state.handlers[node.tagName](state, node, parent) || void 0;
69
98
  }
@@ -72,10 +101,10 @@ const mdcRemarkNodeHandlers = {
72
101
  state.patch(node, result);
73
102
  return result;
74
103
  }
75
- const isInlineElement = (parent?.children || []).some((child) => child.type === "text") || ["p", "li"].includes(parent?.tagName);
104
+ const isInlineElement = (parent?.children || []).some((child) => child.type === "text") || ["p", "li", "strong", "em", "span"].includes(parent?.tagName);
76
105
  if (isInlineElement) {
77
106
  return {
78
- type: "textComponent",
107
+ type: mdastTextComponentType,
79
108
  name: node.tagName,
80
109
  attributes: node.properties,
81
110
  children: state.all(node)
@@ -145,16 +174,21 @@ const mdcRemarkHandlers = {
145
174
  meta
146
175
  };
147
176
  },
148
- span: (state, node) => {
149
- const result = {
150
- type: "textComponent",
151
- name: "span",
152
- attributes: node.properties,
153
- children: state.all(node)
154
- };
155
- state.patch(node, result);
156
- return result;
177
+ button: (state, node) => {
178
+ if (
179
+ // @ts-expect-error: custom type
180
+ node.children?.find((child) => child.type === mdcRemarkElementType) || node.children?.find((child) => child.type === "text" && child.value.includes("\n"))
181
+ ) {
182
+ return {
183
+ type: "containerComponent",
184
+ name: "button",
185
+ children: state.all(node),
186
+ attributes: node.properties
187
+ };
188
+ }
189
+ return createTextComponent("button")(state, node);
157
190
  },
191
+ span: createTextComponent("span"),
158
192
  binding: createTextComponent("binding"),
159
193
  iframe: createTextComponent("iframe"),
160
194
  video: createTextComponent("video"),
@@ -221,11 +255,13 @@ const mdcRemarkHandlers = {
221
255
  };
222
256
  function createTextComponent(name) {
223
257
  return (state, node) => {
224
- return {
225
- type: "textComponent",
258
+ const result = {
259
+ type: mdastTextComponentType,
226
260
  name,
227
261
  attributes: node.properties,
228
- children: node.children ? state.toFlow(state.all(node)) : void 0
262
+ children: state.all(node)
229
263
  };
264
+ state.patch(node, result);
265
+ return result;
230
266
  };
231
267
  }
@@ -1,3 +1,3 @@
1
- export declare const renderSlot: (slots: Record<string, any>, name: string, props: any, ...rest: any[]) => import("@vue/runtime-core").VNode<import("@vue/runtime-core").RendererNode, import("@vue/runtime-core").RendererElement, {
1
+ export declare const renderSlot: (slots: Record<string, any>, name: string, props: any, ...rest: any[]) => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
2
2
  [key: string]: any;
3
3
  }>;
@@ -1,9 +1,6 @@
1
- import type { BuiltinTheme, Highlighter as Highlighter$1, HighlighterCore, ShikiTransformer } from 'shiki';
2
- import type { Processor } from 'unified';
3
- import type { ElementContent } from 'hast';
4
-
5
-
6
-
1
+ import { BuiltinTheme, Highlighter as Highlighter$1, ShikiTransformer, HighlighterCore } from 'shiki';
2
+ import { Processor } from 'unified';
3
+ import { ElementContent } from 'hast';
7
4
 
8
5
  type MdcThemeOptions = BuiltinTheme | string | Record<string, BuiltinTheme | string>;
9
6
  interface HighlighterOptions {
@@ -22,16 +19,6 @@ interface RehypeHighlightOption {
22
19
  highlighter?: Highlighter;
23
20
  }
24
21
 
25
-
26
-
27
-
28
-
29
-
30
-
31
-
32
-
33
-
34
-
35
22
  type Awaitable<T> = T | Promise<T>;
36
23
  interface MdcConfig {
37
24
  /**
@@ -74,8 +61,6 @@ interface MdcConfig {
74
61
  };
75
62
  }
76
63
 
77
-
78
-
79
64
  declare function defineConfig(config: MdcConfig): MdcConfig;
80
65
 
81
66
  export { defineConfig as d };
package/dist/types.d.mts CHANGED
@@ -1,7 +1,5 @@
1
- import type { NuxtModule } from '@nuxt/schema'
1
+ export { type Awaitable, type HighlightResult, type Highlighter, type HighlighterOptions, type defineConfig } from './shared/mdc.BkZUOs7X.mjs'
2
2
 
3
- import type { default as Module } from './module.js'
3
+ export { type DefaultHighlightLangs, type MdcConfig, type MdcThemeOptions, type RehypeHighlightOption, default } from './module.mjs'
4
4
 
5
- export type ModuleOptions = typeof Module extends NuxtModule<infer O> ? Partial<O> : Record<string, any>
6
-
7
- export { type Awaitable, type HighlightResult, type Highlighter, type HighlighterOptions, type defineConfig } from './module.js'
5
+ export { type Comment, type CommentData, type Content, type Data, type Doctype, type DoctypeData, type Element, type ElementContent, type ElementContentMap, type ElementData, type Literal, type Literals, type MDCComment, type MDCData, type MDCElement, type MDCNode, type MDCParseOptions, type MDCParserResult, type MDCRenderOptions, type MDCRoot, type MDCStringifyOptions, type MDCText, type ModuleOptions, type Node, type NodePosition, type Nodes, type Parent, type Parents, type Properties, type RehypePlugin, type RemarkPlugin, type Root, type RootContent, type RootContentMap, type RootData, type Text, type TextData, type Toc, type TocLink, type UnistPlugin } from './module.mjs'
package/package.json CHANGED
@@ -1,18 +1,14 @@
1
1
  {
2
2
  "name": "@nuxtjs/mdc",
3
- "version": "0.16.1",
3
+ "version": "0.17.0",
4
4
  "description": "Nuxt MDC module",
5
5
  "repository": "nuxt-modules/mdc",
6
6
  "license": "MIT",
7
7
  "type": "module",
8
8
  "exports": {
9
- ".": {
10
- "types": "./dist/module.d.ts",
11
- "import": "./dist/module.mjs",
12
- "require": "./dist/module.cjs"
13
- },
9
+ ".": "./dist/module.mjs",
14
10
  "./config": {
15
- "types": "./dist/config.d.ts",
11
+ "types": "./dist/config.d.mts",
16
12
  "import": "./dist/config.mjs",
17
13
  "require": "./dist/config.cjs"
18
14
  },
@@ -41,19 +37,19 @@
41
37
  "import": "./dist/runtime/*.js"
42
38
  }
43
39
  },
44
- "main": "./dist/module.cjs",
45
- "types": "./dist/types.d.ts",
40
+ "main": "./dist/module.mjs",
41
+ "types": "./dist/types.d.mts",
46
42
  "files": [
47
43
  "dist"
48
44
  ],
49
45
  "typesVersions": {
50
46
  "*": {
51
47
  "*": [
52
- "./dist/* ",
53
- "./dist/index.d.ts"
48
+ "./dist/*",
49
+ "./dist/index.d.mts"
54
50
  ],
55
51
  "config": [
56
- "./dist/config.d.ts"
52
+ "./dist/config.d.mts"
57
53
  ]
58
54
  }
59
55
  },
@@ -72,15 +68,17 @@
72
68
  "verify": "npm run dev:prepare && npm run lint && npm run test && npm run typecheck"
73
69
  },
74
70
  "dependencies": {
75
- "@nuxt/kit": "^3.16.1",
76
- "@shikijs/transformers": "^3.2.1",
71
+ "@nuxt/kit": "^3.16.2",
72
+ "@shikijs/langs": "^3.3.0",
73
+ "@shikijs/themes": "^3.3.0",
74
+ "@shikijs/transformers": "^3.3.0",
77
75
  "@types/hast": "^3.0.4",
78
76
  "@types/mdast": "^4.0.4",
79
77
  "@vue/compiler-core": "^3.5.13",
80
78
  "consola": "^3.4.2",
81
79
  "debug": "4.4.0",
82
80
  "defu": "^6.1.4",
83
- "destr": "^2.0.3",
81
+ "destr": "^2.0.5",
84
82
  "detab": "^3.0.2",
85
83
  "github-slugger": "^2.0.0",
86
84
  "hast-util-format": "^1.1.0",
@@ -88,25 +86,25 @@
88
86
  "hast-util-to-string": "^3.0.1",
89
87
  "mdast-util-to-hast": "^13.2.0",
90
88
  "micromark-util-sanitize-uri": "^2.0.1",
91
- "parse5": "^7.2.1",
89
+ "parse5": "^7.3.0",
92
90
  "pathe": "^2.0.3",
93
91
  "property-information": "^7.0.0",
94
92
  "rehype-external-links": "^3.0.0",
95
93
  "rehype-minify-whitespace": "^6.0.2",
96
94
  "rehype-raw": "^7.0.0",
97
- "rehype-remark": "^10.0.0",
95
+ "rehype-remark": "^10.0.1",
98
96
  "rehype-slug": "^6.0.0",
99
97
  "rehype-sort-attribute-values": "^5.0.1",
100
98
  "rehype-sort-attributes": "^5.0.1",
101
99
  "remark-emoji": "^5.0.1",
102
100
  "remark-gfm": "^4.0.1",
103
- "remark-mdc": "^3.5.3",
101
+ "remark-mdc": "v3.6.0",
104
102
  "remark-parse": "^11.0.0",
105
- "remark-rehype": "^11.1.1",
103
+ "remark-rehype": "^11.1.2",
106
104
  "remark-stringify": "^11.0.0",
107
105
  "scule": "^1.3.0",
108
- "shiki": "^3.2.1",
109
- "ufo": "^1.5.4",
106
+ "shiki": "^3.3.0",
107
+ "ufo": "^1.6.1",
110
108
  "unified": "^11.0.5",
111
109
  "unist-builder": "^4.0.0",
112
110
  "unist-util-visit": "^5.0.0",
@@ -114,26 +112,26 @@
114
112
  "vfile": "^6.0.3"
115
113
  },
116
114
  "devDependencies": {
117
- "@nuxt/devtools": "^2.3.1",
118
- "@nuxt/eslint-config": "^1.2.0",
119
- "@nuxt/module-builder": "^0.8.4",
120
- "@nuxt/schema": "^3.16.1",
115
+ "@nuxt/devtools": "^2.4.0",
116
+ "@nuxt/eslint-config": "^1.3.0",
117
+ "@nuxt/module-builder": "^1.0.1",
118
+ "@nuxt/schema": "^3.16.2",
121
119
  "@nuxt/test-utils": "^3.17.2",
122
- "@nuxt/ui": "^3.0.0",
120
+ "@nuxt/ui": "^3.0.2",
123
121
  "@nuxtjs/mdc": "link:.",
124
- "@types/node": "^22.13.10",
125
- "eslint": "^9.22.0",
126
- "nuxt": "^3.16.1",
122
+ "@types/node": "^22.14.1",
123
+ "eslint": "^9.25.1",
124
+ "nuxt": "^3.16.2",
127
125
  "rehype": "^13.0.2",
128
- "release-it": "^18.1.2",
129
- "typescript": "5.8.2",
130
- "vitest": "^3.0.9",
131
- "vue-tsc": "^2.2.8"
126
+ "release-it": "^19.0.1",
127
+ "typescript": "5.8.3",
128
+ "vitest": "^3.1.2",
129
+ "vue-tsc": "^2.2.10"
132
130
  },
133
131
  "resolutions": {
134
132
  "@nuxtjs/mdc": "workspace:*"
135
133
  },
136
- "packageManager": "pnpm@10.6.5",
134
+ "packageManager": "pnpm@10.9.0",
137
135
  "release-it": {
138
136
  "git": {
139
137
  "commitMessage": "chore(release): release v${version}"
package/dist/config.d.ts DELETED
@@ -1,4 +0,0 @@
1
- export { d as defineConfig } from './shared/mdc.86c0ccda.js';
2
- import 'shiki';
3
- import 'unified';
4
- import 'hast';
package/dist/module.cjs DELETED
@@ -1,5 +0,0 @@
1
- module.exports = function(...args) {
2
- return import('./module.mjs').then(m => m.default.call(this, ...args))
3
- }
4
- const _meta = module.exports.meta = require('./module.json')
5
- module.exports.getMeta = () => Promise.resolve(_meta)