@kubb/parser-md 5.0.0-beta.100

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Stijn Van Hulle
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,101 @@
1
+ <div align="center">
2
+ <a href="https://kubb.dev" target="_blank" rel="noopener noreferrer">
3
+ <img src="https://kubb.dev/og.png" alt="Kubb banner">
4
+ </a>
5
+
6
+ [![npm version][npm-version-src]][npm-version-href]
7
+ [![npm downloads][npm-downloads-src]][npm-downloads-href]
8
+ [![Stars][stars-src]][stars-href]
9
+ [![License][license-src]][license-href]
10
+ [![Node][node-src]][node-href]
11
+
12
+ <h4>
13
+ <a href="https://kubb.dev" target="_blank">Documentation</a>
14
+ <span> · </span>
15
+ <a href="https://github.com/kubb-labs/kubb/issues/" target="_blank">Report Bug</a>
16
+ <span> · </span>
17
+ <a href="https://github.com/kubb-labs/kubb/issues/" target="_blank">Request Feature</a>
18
+ </h4>
19
+ </div>
20
+
21
+ <br />
22
+
23
+ # @kubb/parser-md
24
+
25
+ ### Markdown source file parser for Kubb
26
+
27
+ Joins source blocks as plain markdown and renders YAML frontmatter via `parserMd.print`.
28
+
29
+ ## Installation
30
+
31
+ ```bash
32
+ bun add @kubb/parser-md
33
+ # or
34
+ pnpm add @kubb/parser-md
35
+ # or
36
+ npm install @kubb/parser-md
37
+ ```
38
+
39
+ ## Usage
40
+
41
+ ```typescript
42
+ import { defineConfig } from 'kubb'
43
+ import { parserMd } from '@kubb/parser-md'
44
+ import { parserTs } from '@kubb/parser-ts'
45
+
46
+ export default defineConfig({
47
+ input: './petstore.yaml',
48
+ output: { path: './src/gen' },
49
+ parsers: [parserTs(), parserMd()],
50
+ })
51
+ ```
52
+
53
+ To convert a metadata object into a YAML frontmatter envelope from inside a plugin, call `print` on a parser instance:
54
+
55
+ ```typescript
56
+ import { parserMd } from '@kubb/parser-md'
57
+
58
+ const source = parserMd().print({ title: 'Pets', layout: 'doc' })
59
+ // → ---
60
+ // title: Pets
61
+ // layout: doc
62
+ // ---
63
+ ```
64
+
65
+ ## API
66
+
67
+ ### `parserMd()`
68
+
69
+ Factory returning a parser instance for `.md` and `.markdown` files. Pass to `defineConfig({ parsers: [...] })` to emit Markdown source files.
70
+
71
+ The returned instance exposes `parse(file)` to serialize a `FileNode` to Markdown source (prepending the YAML envelope when `file.meta.frontmatter` is set) and `print(...parts)` to join markdown fragments separated by blank lines, serializing plain objects as YAML frontmatter and passing strings through unchanged.
72
+
73
+ ## Supporting Kubb
74
+
75
+ Kubb is an open source project, and its development is funded entirely by sponsors. If you would like to become a sponsor, please consider:
76
+
77
+ - [Become a Sponsor on GitHub](https://github.com/sponsors/stijnvanhulle)
78
+ - [See sponsorship tiers and our sponsors](https://kubb.dev/sponsors)
79
+
80
+ <p align="center">
81
+ <a href="https://github.com/sponsors/stijnvanhulle">
82
+ <img src="https://raw.githubusercontent.com/stijnvanhulle/sponsors/main/sponsors.svg" alt="My sponsors" />
83
+ </a>
84
+ </p>
85
+
86
+ ## License
87
+
88
+ [MIT](https://github.com/kubb-labs/kubb/blob/main/licenses/LICENSE-MIT)
89
+
90
+ <!-- Badges -->
91
+
92
+ [npm-version-src]: https://shieldcn.dev/npm/v/@kubb/parser-md.svg?variant=secondary&size=xs&theme=zinc&mode=dark
93
+ [npm-version-href]: https://npmx.dev/package/@kubb/parser-md
94
+ [npm-downloads-src]: https://shieldcn.dev/npm/dm/@kubb/parser-md.svg?variant=secondary&size=xs&theme=zinc&mode=dark
95
+ [npm-downloads-href]: https://npmx.dev/package/@kubb/parser-md
96
+ [stars-src]: https://shieldcn.dev/github/stars/kubb-labs/kubb.svg?variant=secondary&size=xs&theme=zinc&mode=dark
97
+ [stars-href]: https://github.com/kubb-labs/kubb
98
+ [license-src]: https://shieldcn.dev/npm/license/@kubb/parser-md.svg?variant=secondary&size=xs&theme=zinc
99
+ [license-href]: https://github.com/kubb-labs/kubb/blob/main/LICENSE
100
+ [node-src]: https://shieldcn.dev/npm/node/@kubb/parser-md.svg?variant=secondary&size=xs&theme=zinc&mode=dark
101
+ [node-href]: https://npmx.dev/package/@kubb/parser-md
package/dist/index.cjs ADDED
@@ -0,0 +1,91 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ //#endregion
3
+ let _kubb_kit = require("@kubb/kit");
4
+ let yaml = require("yaml");
5
+ //#region src/utils.ts
6
+ /**
7
+ * Wraps a plain object as a YAML frontmatter envelope (`---\n<yaml>\n---`).
8
+ * Returns an empty string for `null`, `undefined`, or empty objects so callers
9
+ * can drop the result through the same filter chain as other optional fields.
10
+ */
11
+ function stringifyFrontmatter(data) {
12
+ if (!data || Object.keys(data).length === 0) return "";
13
+ return `---\n${(0, yaml.stringify)(data).trimEnd()}\n---`;
14
+ }
15
+ /**
16
+ * Joins a list of markdown fragments with blank lines. Plain objects are
17
+ * rendered as YAML frontmatter via {@link stringifyFrontmatter}, and strings pass
18
+ * through unchanged.
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * print({ title: 'Hi' }, '# Hello')
23
+ * // '---\ntitle: Hi\n---\n\n# Hello'
24
+ * ```
25
+ */
26
+ function print(...parts) {
27
+ const rendered = [];
28
+ for (const part of parts) {
29
+ if (part === null || part === void 0 || part === "") continue;
30
+ const text = typeof part === "string" ? part : stringifyFrontmatter(part);
31
+ if (text) rendered.push(text.trimEnd());
32
+ }
33
+ return rendered.join("\n\n");
34
+ }
35
+ //#endregion
36
+ //#region src/parserMd.ts
37
+ /**
38
+ * Kubb parser for `.md` and `.markdown` files. Joins source blocks as plain
39
+ * markdown (separated by blank lines) and, when `file.meta.frontmatter` is set,
40
+ * prepends a YAML frontmatter envelope produced by `parserMd.print`.
41
+ *
42
+ * Runs by default next to `parserTs` and `parserTsx`. Add it to a custom
43
+ * `parsers` array yourself, since a custom list replaces the default set.
44
+ * `parserTs` keeps handling `.ts`/`.js` files, `parserMd` claims
45
+ * `.md`/`.markdown`.
46
+ *
47
+ * @example
48
+ * ```ts
49
+ * import { defineConfig } from 'kubb'
50
+ * import { adapterOas } from '@kubb/adapter-oas'
51
+ * import { parserMd } from '@kubb/parser-md'
52
+ * import { parserTs, parserTsx } from '@kubb/parser-ts'
53
+ *
54
+ * export default defineConfig({
55
+ * input: './petStore.yaml',
56
+ * output: { path: './src/gen' },
57
+ * adapter: adapterOas(),
58
+ * parsers: [parserTs(), parserTsx(), parserMd()],
59
+ * plugins: [],
60
+ * })
61
+ * ```
62
+ */
63
+ const parserMd = (0, _kubb_kit.defineParser)(() => {
64
+ return {
65
+ name: "markdown",
66
+ extNames: [".md", ".markdown"],
67
+ print(...parts) {
68
+ return print(...parts);
69
+ },
70
+ parse(file) {
71
+ const sourceParts = [];
72
+ for (const source of file.sources) {
73
+ const text = _kubb_kit.ast.extractStringsFromNodes(source.nodes);
74
+ if (text) sourceParts.push(text.trimEnd());
75
+ }
76
+ const body = sourceParts.join("\n\n");
77
+ const meta = file.meta;
78
+ const frontmatter = print(meta?.frontmatter);
79
+ return [
80
+ file.banner,
81
+ frontmatter,
82
+ body,
83
+ file.footer
84
+ ].filter((segment) => Boolean(segment)).map((segment) => segment.trimEnd()).join("\n\n");
85
+ }
86
+ };
87
+ });
88
+ //#endregion
89
+ exports.parserMd = parserMd;
90
+
91
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":["ast"],"sources":["../src/utils.ts","../src/parserMd.ts"],"sourcesContent":["import { stringify } from 'yaml'\n\n/**\n * Markdown `print` input, either a markdown text fragment (passed through\n * verbatim) or a plain object that is serialized as a YAML frontmatter envelope.\n */\nexport type PrintInput = string | Record<string, unknown>\n\n/**\n * Wraps a plain object as a YAML frontmatter envelope (`---\\n<yaml>\\n---`).\n * Returns an empty string for `null`, `undefined`, or empty objects so callers\n * can drop the result through the same filter chain as other optional fields.\n */\nfunction stringifyFrontmatter(data: Record<string, unknown> | null | undefined): string {\n if (!data || Object.keys(data).length === 0) return ''\n return `---\\n${stringify(data).trimEnd()}\\n---`\n}\n\n/**\n * Joins a list of markdown fragments with blank lines. Plain objects are\n * rendered as YAML frontmatter via {@link stringifyFrontmatter}, and strings pass\n * through unchanged.\n *\n * @example\n * ```ts\n * print({ title: 'Hi' }, '# Hello')\n * // '---\\ntitle: Hi\\n---\\n\\n# Hello'\n * ```\n */\nexport function print(...parts: Array<PrintInput | null | undefined>): string {\n const rendered: Array<string> = []\n for (const part of parts) {\n if (part === null || part === undefined || part === '') continue\n const text = typeof part === 'string' ? part : stringifyFrontmatter(part)\n if (text) rendered.push(text.trimEnd())\n }\n return rendered.join('\\n\\n')\n}\n","import { ast, defineParser } from '@kubb/kit'\n\nimport { print, type PrintInput } from './utils.ts'\n\n/**\n * Metadata accepted by `parserMd`. Set `frontmatter` on a `<File meta={...}>` and\n * the parser prepends those keys as a YAML frontmatter envelope.\n */\nexport type MdMeta = {\n frontmatter?: Record<string, unknown> | null\n}\n\n/**\n * Kubb parser for `.md` and `.markdown` files. Joins source blocks as plain\n * markdown (separated by blank lines) and, when `file.meta.frontmatter` is set,\n * prepends a YAML frontmatter envelope produced by `parserMd.print`.\n *\n * Runs by default next to `parserTs` and `parserTsx`. Add it to a custom\n * `parsers` array yourself, since a custom list replaces the default set.\n * `parserTs` keeps handling `.ts`/`.js` files, `parserMd` claims\n * `.md`/`.markdown`.\n *\n * @example\n * ```ts\n * import { defineConfig } from 'kubb'\n * import { adapterOas } from '@kubb/adapter-oas'\n * import { parserMd } from '@kubb/parser-md'\n * import { parserTs, parserTsx } from '@kubb/parser-ts'\n *\n * export default defineConfig({\n * input: './petStore.yaml',\n * output: { path: './src/gen' },\n * adapter: adapterOas(),\n * parsers: [parserTs(), parserTsx(), parserMd()],\n * plugins: [],\n * })\n * ```\n */\nexport const parserMd = defineParser(() => {\n return {\n name: 'markdown',\n extNames: ['.md', '.markdown'],\n print(...parts: Array<PrintInput>) {\n return print(...parts)\n },\n parse(file) {\n const sourceParts: Array<string> = []\n for (const source of file.sources) {\n const text = ast.extractStringsFromNodes(source.nodes as Array<ast.CodeNode>)\n if (text) sourceParts.push(text.trimEnd())\n }\n const body = sourceParts.join('\\n\\n')\n\n const meta = file.meta as MdMeta | undefined\n const frontmatter = print(meta?.frontmatter)\n\n const parts = [file.banner, frontmatter, body, file.footer].filter((segment): segment is string => Boolean(segment)).map((segment) => segment.trimEnd())\n\n return parts.join('\\n\\n')\n },\n }\n})\n"],"mappings":";;;;;;;;;;AAaA,SAAS,qBAAqB,MAA0D;CACtF,IAAI,CAAC,QAAQ,OAAO,KAAK,IAAI,CAAC,CAAC,WAAW,GAAG,OAAO;CACpD,OAAO,SAAA,GAAA,KAAA,UAAA,CAAkB,IAAI,CAAC,CAAC,QAAQ,EAAE;AAC3C;;;;;;;;;;;;AAaA,SAAgB,MAAM,GAAG,OAAqD;CAC5E,MAAM,WAA0B,CAAC;CACjC,KAAK,MAAM,QAAQ,OAAO;EACxB,IAAI,SAAS,QAAQ,SAAS,KAAA,KAAa,SAAS,IAAI;EACxD,MAAM,OAAO,OAAO,SAAS,WAAW,OAAO,qBAAqB,IAAI;EACxE,IAAI,MAAM,SAAS,KAAK,KAAK,QAAQ,CAAC;CACxC;CACA,OAAO,SAAS,KAAK,MAAM;AAC7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACCA,MAAa,YAAA,GAAA,UAAA,aAAA,OAA8B;CACzC,OAAO;EACL,MAAM;EACN,UAAU,CAAC,OAAO,WAAW;EAC7B,MAAM,GAAG,OAA0B;GACjC,OAAO,MAAM,GAAG,KAAK;EACvB;EACA,MAAM,MAAM;GACV,MAAM,cAA6B,CAAC;GACpC,KAAK,MAAM,UAAU,KAAK,SAAS;IACjC,MAAM,OAAOA,UAAAA,IAAI,wBAAwB,OAAO,KAA4B;IAC5E,IAAI,MAAM,YAAY,KAAK,KAAK,QAAQ,CAAC;GAC3C;GACA,MAAM,OAAO,YAAY,KAAK,MAAM;GAEpC,MAAM,OAAO,KAAK;GAClB,MAAM,cAAc,MAAM,MAAM,WAAW;GAI3C,OAFc;IAAC,KAAK;IAAQ;IAAa;IAAM,KAAK;GAAM,CAAC,CAAC,QAAQ,YAA+B,QAAQ,OAAO,CAAC,CAAC,CAAC,KAAK,YAAY,QAAQ,QAAQ,CAE3I,CAAC,CAAC,KAAK,MAAM;EAC1B;CACF;AACF,CAAC"}
@@ -0,0 +1,46 @@
1
+ import { t as __name } from "./rolldown-runtime-C0LytTxp.js";
2
+ //#region src/utils.d.ts
3
+ /**
4
+ * Markdown `print` input, either a markdown text fragment (passed through
5
+ * verbatim) or a plain object that is serialized as a YAML frontmatter envelope.
6
+ */
7
+ type PrintInput = string | Record<string, unknown>;
8
+ //#endregion
9
+ //#region src/parserMd.d.ts
10
+ /**
11
+ * Metadata accepted by `parserMd`. Set `frontmatter` on a `<File meta={...}>` and
12
+ * the parser prepends those keys as a YAML frontmatter envelope.
13
+ */
14
+ type MdMeta = {
15
+ frontmatter?: Record<string, unknown> | null;
16
+ };
17
+ /**
18
+ * Kubb parser for `.md` and `.markdown` files. Joins source blocks as plain
19
+ * markdown (separated by blank lines) and, when `file.meta.frontmatter` is set,
20
+ * prepends a YAML frontmatter envelope produced by `parserMd.print`.
21
+ *
22
+ * Runs by default next to `parserTs` and `parserTsx`. Add it to a custom
23
+ * `parsers` array yourself, since a custom list replaces the default set.
24
+ * `parserTs` keeps handling `.ts`/`.js` files, `parserMd` claims
25
+ * `.md`/`.markdown`.
26
+ *
27
+ * @example
28
+ * ```ts
29
+ * import { defineConfig } from 'kubb'
30
+ * import { adapterOas } from '@kubb/adapter-oas'
31
+ * import { parserMd } from '@kubb/parser-md'
32
+ * import { parserTs, parserTsx } from '@kubb/parser-ts'
33
+ *
34
+ * export default defineConfig({
35
+ * input: './petStore.yaml',
36
+ * output: { path: './src/gen' },
37
+ * adapter: adapterOas(),
38
+ * parsers: [parserTs(), parserTsx(), parserMd()],
39
+ * plugins: [],
40
+ * })
41
+ * ```
42
+ */
43
+ declare const parserMd: (options?: object | undefined) => import("@kubb/core").Parser<object, PrintInput>;
44
+ //#endregion
45
+ export { type MdMeta, parserMd };
46
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js ADDED
@@ -0,0 +1,90 @@
1
+ import "./rolldown-runtime-C0LytTxp.js";
2
+ import { ast, defineParser } from "@kubb/kit";
3
+ import { stringify } from "yaml";
4
+ //#region src/utils.ts
5
+ /**
6
+ * Wraps a plain object as a YAML frontmatter envelope (`---\n<yaml>\n---`).
7
+ * Returns an empty string for `null`, `undefined`, or empty objects so callers
8
+ * can drop the result through the same filter chain as other optional fields.
9
+ */
10
+ function stringifyFrontmatter(data) {
11
+ if (!data || Object.keys(data).length === 0) return "";
12
+ return `---\n${stringify(data).trimEnd()}\n---`;
13
+ }
14
+ /**
15
+ * Joins a list of markdown fragments with blank lines. Plain objects are
16
+ * rendered as YAML frontmatter via {@link stringifyFrontmatter}, and strings pass
17
+ * through unchanged.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * print({ title: 'Hi' }, '# Hello')
22
+ * // '---\ntitle: Hi\n---\n\n# Hello'
23
+ * ```
24
+ */
25
+ function print(...parts) {
26
+ const rendered = [];
27
+ for (const part of parts) {
28
+ if (part === null || part === void 0 || part === "") continue;
29
+ const text = typeof part === "string" ? part : stringifyFrontmatter(part);
30
+ if (text) rendered.push(text.trimEnd());
31
+ }
32
+ return rendered.join("\n\n");
33
+ }
34
+ //#endregion
35
+ //#region src/parserMd.ts
36
+ /**
37
+ * Kubb parser for `.md` and `.markdown` files. Joins source blocks as plain
38
+ * markdown (separated by blank lines) and, when `file.meta.frontmatter` is set,
39
+ * prepends a YAML frontmatter envelope produced by `parserMd.print`.
40
+ *
41
+ * Runs by default next to `parserTs` and `parserTsx`. Add it to a custom
42
+ * `parsers` array yourself, since a custom list replaces the default set.
43
+ * `parserTs` keeps handling `.ts`/`.js` files, `parserMd` claims
44
+ * `.md`/`.markdown`.
45
+ *
46
+ * @example
47
+ * ```ts
48
+ * import { defineConfig } from 'kubb'
49
+ * import { adapterOas } from '@kubb/adapter-oas'
50
+ * import { parserMd } from '@kubb/parser-md'
51
+ * import { parserTs, parserTsx } from '@kubb/parser-ts'
52
+ *
53
+ * export default defineConfig({
54
+ * input: './petStore.yaml',
55
+ * output: { path: './src/gen' },
56
+ * adapter: adapterOas(),
57
+ * parsers: [parserTs(), parserTsx(), parserMd()],
58
+ * plugins: [],
59
+ * })
60
+ * ```
61
+ */
62
+ const parserMd = defineParser(() => {
63
+ return {
64
+ name: "markdown",
65
+ extNames: [".md", ".markdown"],
66
+ print(...parts) {
67
+ return print(...parts);
68
+ },
69
+ parse(file) {
70
+ const sourceParts = [];
71
+ for (const source of file.sources) {
72
+ const text = ast.extractStringsFromNodes(source.nodes);
73
+ if (text) sourceParts.push(text.trimEnd());
74
+ }
75
+ const body = sourceParts.join("\n\n");
76
+ const meta = file.meta;
77
+ const frontmatter = print(meta?.frontmatter);
78
+ return [
79
+ file.banner,
80
+ frontmatter,
81
+ body,
82
+ file.footer
83
+ ].filter((segment) => Boolean(segment)).map((segment) => segment.trimEnd()).join("\n\n");
84
+ }
85
+ };
86
+ });
87
+ //#endregion
88
+ export { parserMd };
89
+
90
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/utils.ts","../src/parserMd.ts"],"sourcesContent":["import { stringify } from 'yaml'\n\n/**\n * Markdown `print` input, either a markdown text fragment (passed through\n * verbatim) or a plain object that is serialized as a YAML frontmatter envelope.\n */\nexport type PrintInput = string | Record<string, unknown>\n\n/**\n * Wraps a plain object as a YAML frontmatter envelope (`---\\n<yaml>\\n---`).\n * Returns an empty string for `null`, `undefined`, or empty objects so callers\n * can drop the result through the same filter chain as other optional fields.\n */\nfunction stringifyFrontmatter(data: Record<string, unknown> | null | undefined): string {\n if (!data || Object.keys(data).length === 0) return ''\n return `---\\n${stringify(data).trimEnd()}\\n---`\n}\n\n/**\n * Joins a list of markdown fragments with blank lines. Plain objects are\n * rendered as YAML frontmatter via {@link stringifyFrontmatter}, and strings pass\n * through unchanged.\n *\n * @example\n * ```ts\n * print({ title: 'Hi' }, '# Hello')\n * // '---\\ntitle: Hi\\n---\\n\\n# Hello'\n * ```\n */\nexport function print(...parts: Array<PrintInput | null | undefined>): string {\n const rendered: Array<string> = []\n for (const part of parts) {\n if (part === null || part === undefined || part === '') continue\n const text = typeof part === 'string' ? part : stringifyFrontmatter(part)\n if (text) rendered.push(text.trimEnd())\n }\n return rendered.join('\\n\\n')\n}\n","import { ast, defineParser } from '@kubb/kit'\n\nimport { print, type PrintInput } from './utils.ts'\n\n/**\n * Metadata accepted by `parserMd`. Set `frontmatter` on a `<File meta={...}>` and\n * the parser prepends those keys as a YAML frontmatter envelope.\n */\nexport type MdMeta = {\n frontmatter?: Record<string, unknown> | null\n}\n\n/**\n * Kubb parser for `.md` and `.markdown` files. Joins source blocks as plain\n * markdown (separated by blank lines) and, when `file.meta.frontmatter` is set,\n * prepends a YAML frontmatter envelope produced by `parserMd.print`.\n *\n * Runs by default next to `parserTs` and `parserTsx`. Add it to a custom\n * `parsers` array yourself, since a custom list replaces the default set.\n * `parserTs` keeps handling `.ts`/`.js` files, `parserMd` claims\n * `.md`/`.markdown`.\n *\n * @example\n * ```ts\n * import { defineConfig } from 'kubb'\n * import { adapterOas } from '@kubb/adapter-oas'\n * import { parserMd } from '@kubb/parser-md'\n * import { parserTs, parserTsx } from '@kubb/parser-ts'\n *\n * export default defineConfig({\n * input: './petStore.yaml',\n * output: { path: './src/gen' },\n * adapter: adapterOas(),\n * parsers: [parserTs(), parserTsx(), parserMd()],\n * plugins: [],\n * })\n * ```\n */\nexport const parserMd = defineParser(() => {\n return {\n name: 'markdown',\n extNames: ['.md', '.markdown'],\n print(...parts: Array<PrintInput>) {\n return print(...parts)\n },\n parse(file) {\n const sourceParts: Array<string> = []\n for (const source of file.sources) {\n const text = ast.extractStringsFromNodes(source.nodes as Array<ast.CodeNode>)\n if (text) sourceParts.push(text.trimEnd())\n }\n const body = sourceParts.join('\\n\\n')\n\n const meta = file.meta as MdMeta | undefined\n const frontmatter = print(meta?.frontmatter)\n\n const parts = [file.banner, frontmatter, body, file.footer].filter((segment): segment is string => Boolean(segment)).map((segment) => segment.trimEnd())\n\n return parts.join('\\n\\n')\n },\n }\n})\n"],"mappings":";;;;;;;;;AAaA,SAAS,qBAAqB,MAA0D;CACtF,IAAI,CAAC,QAAQ,OAAO,KAAK,IAAI,CAAC,CAAC,WAAW,GAAG,OAAO;CACpD,OAAO,QAAQ,UAAU,IAAI,CAAC,CAAC,QAAQ,EAAE;AAC3C;;;;;;;;;;;;AAaA,SAAgB,MAAM,GAAG,OAAqD;CAC5E,MAAM,WAA0B,CAAC;CACjC,KAAK,MAAM,QAAQ,OAAO;EACxB,IAAI,SAAS,QAAQ,SAAS,KAAA,KAAa,SAAS,IAAI;EACxD,MAAM,OAAO,OAAO,SAAS,WAAW,OAAO,qBAAqB,IAAI;EACxE,IAAI,MAAM,SAAS,KAAK,KAAK,QAAQ,CAAC;CACxC;CACA,OAAO,SAAS,KAAK,MAAM;AAC7B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACCA,MAAa,WAAW,mBAAmB;CACzC,OAAO;EACL,MAAM;EACN,UAAU,CAAC,OAAO,WAAW;EAC7B,MAAM,GAAG,OAA0B;GACjC,OAAO,MAAM,GAAG,KAAK;EACvB;EACA,MAAM,MAAM;GACV,MAAM,cAA6B,CAAC;GACpC,KAAK,MAAM,UAAU,KAAK,SAAS;IACjC,MAAM,OAAO,IAAI,wBAAwB,OAAO,KAA4B;IAC5E,IAAI,MAAM,YAAY,KAAK,KAAK,QAAQ,CAAC;GAC3C;GACA,MAAM,OAAO,YAAY,KAAK,MAAM;GAEpC,MAAM,OAAO,KAAK;GAClB,MAAM,cAAc,MAAM,MAAM,WAAW;GAI3C,OAFc;IAAC,KAAK;IAAQ;IAAa;IAAM,KAAK;GAAM,CAAC,CAAC,QAAQ,YAA+B,QAAQ,OAAO,CAAC,CAAC,CAAC,KAAK,YAAY,QAAQ,QAAQ,CAE3I,CAAC,CAAC,KAAK,MAAM;EAC1B;CACF;AACF,CAAC"}
@@ -0,0 +1,8 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __defProp = Object.defineProperty;
3
+ var __name = (target, value) => __defProp(target, "name", {
4
+ value,
5
+ configurable: true
6
+ });
7
+ //#endregion
8
+ export { __name as t };
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@kubb/parser-md",
3
+ "version": "5.0.0-beta.100",
4
+ "description": "Markdown source file parser for Kubb. Converts the universal AST to `.md` source and renders YAML frontmatter via the `print` helper.",
5
+ "keywords": [
6
+ "codegen",
7
+ "frontmatter",
8
+ "kubb",
9
+ "markdown",
10
+ "meta-framework",
11
+ "parser",
12
+ "yaml"
13
+ ],
14
+ "license": "MIT",
15
+ "author": "stijnvanhulle",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/kubb-labs/kubb.git",
19
+ "directory": "packages/parser-md"
20
+ },
21
+ "files": [
22
+ "dist",
23
+ "!/**/**.test.**",
24
+ "!/**/__tests__/**",
25
+ "!/**/__snapshots__/**"
26
+ ],
27
+ "type": "module",
28
+ "sideEffects": false,
29
+ "main": "./dist/index.cjs",
30
+ "module": "./dist/index.js",
31
+ "types": "./dist/index.d.ts",
32
+ "exports": {
33
+ ".": {
34
+ "import": "./dist/index.js",
35
+ "require": "./dist/index.cjs"
36
+ },
37
+ "./package.json": "./package.json"
38
+ },
39
+ "publishConfig": {
40
+ "access": "public",
41
+ "registry": "https://registry.npmjs.org/"
42
+ },
43
+ "dependencies": {
44
+ "yaml": "^2.9.0",
45
+ "@kubb/kit": "5.0.0-beta.100"
46
+ },
47
+ "engines": {
48
+ "node": ">=22"
49
+ },
50
+ "scripts": {
51
+ "build": "tsdown",
52
+ "clean": "node -e \"require('node:fs').rmSync('./dist', {recursive:true,force:true})\"",
53
+ "lint": "oxlint .",
54
+ "lint:fix": "oxlint --fix .",
55
+ "start": "tsdown --watch",
56
+ "test": "vitest --passWithNoTests",
57
+ "typecheck": "tsc -p ./tsconfig.json --noEmit --emitDeclarationOnly false"
58
+ }
59
+ }