@nuxtjs/mdc 0.9.5 → 0.10.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/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nuxtjs/mdc",
3
3
  "configKey": "mdc",
4
- "version": "0.9.5",
4
+ "version": "0.10.0",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "0.8.4",
7
7
  "unbuild": "2.0.0"
package/dist/module.mjs CHANGED
@@ -11,7 +11,9 @@ const registerMDCSlotTransformer = (resolver) => {
11
11
  const compilerOptions = config.vue.template.compilerOptions;
12
12
  compilerOptions.nodeTransforms = [
13
13
  function viteMDCSlot(node, context) {
14
- if (node.tag === "MDCSlot") {
14
+ const isVueSlotWithUnwrap = node.tag === "slot" && node.props.find((p) => p.name === "mdc-unwrap" || p.name === "bind" && p.rawName === ":mdc-unwrap");
15
+ const isMDCSlot = node.tag === "MDCSlot";
16
+ if (isVueSlotWithUnwrap || isMDCSlot) {
15
17
  const transform = context.ssr ? context.nodeTransforms.find((nt) => nt.name === "ssrTransformSlotOutlet") : context.nodeTransforms.find((nt) => nt.name === "transformSlotOutlet");
16
18
  return () => {
17
19
  node.tag = "slot";
@@ -5,6 +5,7 @@ import { kebabCase, pascalCase } from "scule";
5
5
  import { find, html } from "property-information";
6
6
  import htmlTags from "../parser/utils/html-tags-list";
7
7
  import { flatUnwrap } from "../utils/node";
8
+ import { pick } from "../utils";
8
9
  const DEFAULT_SLOT = "default";
9
10
  const rxOn = /^@|^v-on:/;
10
11
  const rxBind = /^:|^v-bind:/;
@@ -166,24 +167,29 @@ function renderSlots(node, h2, documentMeta, parentProps) {
166
167
  const children = node.children || [];
167
168
  const slotNodes = children.reduce((data, node2) => {
168
169
  if (!isTemplate(node2)) {
169
- data[DEFAULT_SLOT].push(node2);
170
+ data[DEFAULT_SLOT].children.push(node2);
170
171
  return data;
171
172
  }
172
173
  const slotName = getSlotName(node2);
173
- data[slotName] = data[slotName] || [];
174
+ data[slotName] = data[slotName] || { props: {}, children: [] };
174
175
  if (node2.type === "element") {
175
- data[slotName].push(...node2.children || []);
176
+ data[slotName].props = node2.props;
177
+ data[slotName].children.push(...node2.children || []);
176
178
  }
177
179
  return data;
178
180
  }, {
179
- [DEFAULT_SLOT]: []
181
+ [DEFAULT_SLOT]: { props: {}, children: [] }
180
182
  });
181
- const slots = Object.entries(slotNodes).reduce((slots2, [name, children2]) => {
183
+ const slots = Object.entries(slotNodes).reduce((slots2, [name, { props, children: children2 }]) => {
182
184
  if (!children2.length) {
183
185
  return slots2;
184
186
  }
185
- slots2[name] = () => {
186
- const vNodes = children2.map((child) => renderNode(child, h2, documentMeta, parentProps));
187
+ slots2[name] = (data = {}) => {
188
+ const scopedProps = pick(data, Object.keys(props || {}));
189
+ let vNodes = children2.map((child) => renderNode(child, h2, documentMeta, { ...parentProps, ...scopedProps }));
190
+ if (props?.unwrap) {
191
+ vNodes = flatUnwrap(vNodes, props.unwrap);
192
+ }
187
193
  return mergeTextNodes(vNodes);
188
194
  };
189
195
  return slots2;
@@ -1,5 +1,6 @@
1
1
  import type { Options as VFileOptions } from 'vfile';
2
2
  import type { MDCParseOptions, MDCParserResult, MDCRoot } from '@nuxtjs/mdc';
3
+ export declare const createProcessor: (inlineOptions?: MDCParseOptions) => Promise<import("unified").Processor<undefined, undefined, undefined, undefined, undefined>>;
3
4
  export declare const createMarkdownParser: (inlineOptions?: MDCParseOptions) => Promise<(md: string, { fileOptions }?: {
4
5
  fileOptions?: VFileOptions;
5
6
  }) => Promise<MDCParserResult>>;
@@ -10,7 +10,7 @@ import { generateToc } from "./toc.js";
10
10
  import { compileHast } from "./compiler.js";
11
11
  let moduleOptions;
12
12
  let generatedMdcConfigs;
13
- export const createMarkdownParser = async (inlineOptions = {}) => {
13
+ export const createProcessor = async (inlineOptions = {}) => {
14
14
  if (!moduleOptions) {
15
15
  moduleOptions = await import(
16
16
  "#mdc-imports"
@@ -67,6 +67,10 @@ export const createMarkdownParser = async (inlineOptions = {}) => {
67
67
  for (const config of mdcConfigs) {
68
68
  processor = await config.unified?.post?.(processor) || processor;
69
69
  }
70
+ return processor;
71
+ };
72
+ export const createMarkdownParser = async (inlineOptions = {}) => {
73
+ const processor = await createProcessor(inlineOptions);
70
74
  return async function parse(md, { fileOptions } = {}) {
71
75
  const { content, data: frontmatter } = await parseFrontMatter(md);
72
76
  const processedFile = await processor.process({ ...fileOptions, value: content, data: frontmatter });
@@ -78,7 +82,7 @@ export const createMarkdownParser = async (inlineOptions = {}) => {
78
82
  );
79
83
  let toc;
80
84
  if (data.toc !== false) {
81
- const tocOption = defu(data.toc || {}, options.toc);
85
+ const tocOption = defu(data.toc || {}, inlineOptions.toc, defaults.toc);
82
86
  toc = generateToc(result.body, tocOption);
83
87
  }
84
88
  return {
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Pick keys from an object
3
+ */
4
+ export declare function pick(obj: Record<string, any>, keys: string[]): Record<string, any>;
@@ -0,0 +1,12 @@
1
+ export function pick(obj, keys) {
2
+ return keys.reduce((acc, key) => {
3
+ const value = get(obj, key);
4
+ if (value !== void 0) {
5
+ acc[key] = value;
6
+ }
7
+ return acc;
8
+ }, {});
9
+ }
10
+ function get(obj, key) {
11
+ return key.split(".").reduce((acc, k) => acc && acc[k], obj);
12
+ }
@@ -31,7 +31,7 @@ export function nodeTextContent(node) {
31
31
  return node.map(nodeTextContent).join("");
32
32
  }
33
33
  if (isText(node)) {
34
- return node.children || node.value || "";
34
+ return node.value || node.children || "";
35
35
  }
36
36
  const children = nodeChildren(node);
37
37
  if (Array.isArray(children)) {
@@ -2,7 +2,7 @@ import { renderSlot as _renderSlot } from "vue";
2
2
  import { flatUnwrap } from "./node.js";
3
3
  export const renderSlot = (slots, name, props, ...rest) => {
4
4
  if (slots[name]) {
5
- return _renderSlot({ ...slots, [name]: () => flatUnwrap(slots[name](), props?.unwrap) }, name, props, ...rest);
5
+ return _renderSlot({ ...slots, [name]: () => flatUnwrap(slots[name](), props?.unwrap || props?.mdcUnwrap) }, name, props, ...rest);
6
6
  }
7
7
  return _renderSlot(slots, name, props, ...rest);
8
8
  };
@@ -2,7 +2,7 @@ import { ssrRenderSlot as _ssrRenderSlot } from "vue/server-renderer";
2
2
  import { flatUnwrap } from "./node.js";
3
3
  export const ssrRenderSlot = (slots, name, props, fallbackRenderFn, push, parentComponent, slotScopeId) => {
4
4
  if (slots[name]) {
5
- return _ssrRenderSlot({ ...slots, [name]: () => flatUnwrap(slots[name](), props?.unwrap) }, name, props, fallbackRenderFn, push, parentComponent, slotScopeId);
5
+ return _ssrRenderSlot({ ...slots, [name]: () => flatUnwrap(slots[name](), props?.unwrap || props?.mdcUnwrap) }, name, props, fallbackRenderFn, push, parentComponent, slotScopeId);
6
6
  }
7
7
  return _ssrRenderSlot(slots, name, props, fallbackRenderFn, push, parentComponent, slotScopeId);
8
8
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuxtjs/mdc",
3
- "version": "0.9.5",
3
+ "version": "0.10.0",
4
4
  "description": "Nuxt MDC module",
5
5
  "repository": "nuxt-modules/mdc",
6
6
  "license": "MIT",
@@ -72,7 +72,7 @@
72
72
  },
73
73
  "dependencies": {
74
74
  "@nuxt/kit": "^3.14.1592",
75
- "@shikijs/transformers": "^1.23.1",
75
+ "@shikijs/transformers": "^1.24.0",
76
76
  "@types/hast": "^3.0.4",
77
77
  "@types/mdast": "^4.0.4",
78
78
  "@vue/compiler-core": "^3.5.13",
@@ -96,11 +96,11 @@
96
96
  "rehype-sort-attributes": "^5.0.1",
97
97
  "remark-emoji": "^5.0.1",
98
98
  "remark-gfm": "^4.0.0",
99
- "remark-mdc": "^3.4.0",
99
+ "remark-mdc": "^3.5.0",
100
100
  "remark-parse": "^11.0.0",
101
101
  "remark-rehype": "^11.1.1",
102
102
  "scule": "^1.3.0",
103
- "shiki": "^1.23.1",
103
+ "shiki": "^1.24.0",
104
104
  "ufo": "^1.5.4",
105
105
  "unified": "^11.0.5",
106
106
  "unist-builder": "^4.0.0",
@@ -110,26 +110,27 @@
110
110
  },
111
111
  "devDependencies": {
112
112
  "@nuxt/devtools": "latest",
113
- "@nuxt/eslint-config": "^0.7.1",
113
+ "@nuxt/eslint-config": "^0.7.2",
114
114
  "@nuxt/module-builder": "^0.8.4",
115
115
  "@nuxt/schema": "^3.14.1592",
116
116
  "@nuxt/test-utils": "^3.14.4",
117
117
  "@nuxt/ui": "^2.19.2",
118
118
  "@nuxtjs/mdc": "link:.",
119
- "@types/node": "^22.9.1",
119
+ "@types/node": "^22.10.1",
120
120
  "changelogen": "^0.5.7",
121
- "eslint": "^9.15.0",
121
+ "eslint": "^9.16.0",
122
122
  "nuxt": "^3.14.1592",
123
123
  "rehype": "^13.0.2",
124
124
  "release-it": "^17.10.0",
125
- "typescript": "^5.6.3",
126
- "vitest": "^2.1.5",
125
+ "typescript": "5.6.3",
126
+ "vitest": "^2.1.7",
127
127
  "vue-tsc": "^2.1.10"
128
128
  },
129
129
  "resolutions": {
130
- "@nuxtjs/mdc": "workspace:*"
130
+ "@nuxtjs/mdc": "workspace:*",
131
+ "remark-mdc": "npm:remark-mdc-edge@latest"
131
132
  },
132
- "packageManager": "pnpm@9.14.1",
133
+ "packageManager": "pnpm@9.14.4",
133
134
  "release-it": {
134
135
  "git": {
135
136
  "commitMessage": "chore(release): release v${version}"