@kubb/parser-md 5.0.0-beta.25 → 5.0.0-beta.27
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 +14 -0
- package/dist/index.cjs +1 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +14 -2
- package/dist/index.js +2 -3
- package/dist/index.js.map +1 -1
- package/extension.yaml +22 -4
- package/package.json +12 -13
- package/src/parserMd.ts +4 -5
- package/src/utils.ts +1 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
Copyright (c) 2026 Stijn Van Hulle
|
|
2
|
+
|
|
3
|
+
This repository contains software under two licenses:
|
|
4
|
+
|
|
5
|
+
1. Most of the code in this repository is licensed under the
|
|
6
|
+
MIT License — see licenses/LICENSE-MIT for the full license text.
|
|
7
|
+
|
|
8
|
+
2. The following components are licensed under the
|
|
9
|
+
GNU Affero General Public License v3.0 or later (AGPL-3.0-or-later)
|
|
10
|
+
— see licenses/LICENSE-AGPL-3.0 for the full license text:
|
|
11
|
+
|
|
12
|
+
- packages/agent (published as @kubb/agent)
|
|
13
|
+
|
|
14
|
+
Each package's own LICENSE file or package.json specifies its applicable license.
|
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
//#endregion
|
|
3
|
-
let _kubb_ast = require("@kubb/ast");
|
|
4
3
|
let _kubb_core = require("@kubb/core");
|
|
5
4
|
let yaml = require("yaml");
|
|
6
5
|
//#region src/utils.ts
|
|
@@ -74,7 +73,7 @@ const parserMd = (0, _kubb_core.defineParser)({
|
|
|
74
73
|
parse(file) {
|
|
75
74
|
const sourceParts = [];
|
|
76
75
|
for (const source of file.sources) {
|
|
77
|
-
const text =
|
|
76
|
+
const text = _kubb_core.ast.extractStringsFromNodes(source.nodes);
|
|
78
77
|
if (text) sourceParts.push(text.trimEnd());
|
|
79
78
|
}
|
|
80
79
|
const body = sourceParts.join("\n\n");
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","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 serialised 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 *\n * ```\n * ---\n * <yaml>\n * ---\n * ```\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 banner/footer fields.\n */\nexport function printFrontmatter(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 printFrontmatter}; 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: string
|
|
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 serialised 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 *\n * ```\n * ---\n * <yaml>\n * ---\n * ```\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 banner/footer fields.\n */\nexport function printFrontmatter(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 printFrontmatter}; 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 : printFrontmatter(part)\n if (text) rendered.push(text.trimEnd())\n }\n return rendered.join('\\n\\n')\n}\n","import { ast } from '@kubb/core'\nimport { defineParser } from '@kubb/core'\nimport { print, type PrintInput } from './utils.ts'\n\n/**\n * Metadata accepted by `parserMd`. Set `frontmatter` on a `<File meta={…}>` to\n * have the parser prepend the corresponding YAML 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 * Add to the `parsers` array on `defineConfig` to opt in. `parserTs` keeps\n * handling `.ts`/`.js` files, `parserMd` claims `.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 *\n * export default defineConfig({\n * input: { path: './petStore.yaml' },\n * output: { path: './src/gen' },\n * adapter: adapterOas(),\n * parsers: [parserMd],\n * plugins: [],\n * })\n * ```\n */\nexport const parserMd = defineParser({\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 ?? undefined)\n\n const parts = [file.banner, frontmatter, body, file.footer].filter((segment): segment is string => Boolean(segment)).map((segment) => segment.trimEnd())\n return parts.join('\\n\\n')\n },\n})\n"],"mappings":";;;;;;;;;;;;;;;;;AAoBA,SAAgB,iBAAiB,MAA0D;CACzF,IAAI,CAAC,QAAQ,OAAO,KAAK,KAAK,CAAC,WAAW,GAAG,OAAO;CACpD,OAAO,SAAA,GAAA,KAAA,WAAkB,KAAK,CAAC,SAAS,CAAC;;;;;;;;;;;;;AAc3C,SAAgB,MAAM,GAAG,OAAqD;CAC5E,MAAM,WAA0B,EAAE;CAClC,KAAK,MAAM,QAAQ,OAAO;EACxB,IAAI,SAAS,QAAQ,SAAS,KAAA,KAAa,SAAS,IAAI;EACxD,MAAM,OAAO,OAAO,SAAS,WAAW,OAAO,iBAAiB,KAAK;EACrE,IAAI,MAAM,SAAS,KAAK,KAAK,SAAS,CAAC;;CAEzC,OAAO,SAAS,KAAK,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;ACR9B,MAAa,YAAA,GAAA,WAAA,cAAwB;CACnC,MAAM;CACN,UAAU,CAAC,OAAO,YAAY;CAC9B,MAAM,GAAG,OAA0B;EACjC,OAAO,MAAM,GAAG,MAAM;;CAExB,MAAM,MAAM;EACV,MAAM,cAA6B,EAAE;EACrC,KAAK,MAAM,UAAU,KAAK,SAAS;GACjC,MAAM,OAAOA,WAAAA,IAAI,wBAAwB,OAAO,MAA6B;GAC7E,IAAI,MAAM,YAAY,KAAK,KAAK,SAAS,CAAC;;EAE5C,MAAM,OAAO,YAAY,KAAK,OAAO;EAErC,MAAM,OAAO,KAAK;EAClB,MAAM,cAAc,MAAM,MAAM,eAAe,KAAA,EAAU;EAGzD,OADc;GAAC,KAAK;GAAQ;GAAa;GAAM,KAAK;GAAO,CAAC,QAAQ,YAA+B,QAAQ,QAAQ,CAAC,CAAC,KAAK,YAAY,QAAQ,SAAS,CAC3I,CAAC,KAAK,OAAO;;CAE5B,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
|
-
import
|
|
2
|
+
import { ast } from "@kubb/core";
|
|
3
3
|
|
|
4
|
+
//#region src/utils.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Markdown `print` input — either a markdown text fragment (passed through
|
|
7
|
+
* verbatim) or a plain object that is serialised as a YAML frontmatter envelope.
|
|
8
|
+
*/
|
|
9
|
+
type PrintInput = string | Record<string, unknown>;
|
|
10
|
+
//#endregion
|
|
4
11
|
//#region src/parserMd.d.ts
|
|
5
12
|
/**
|
|
6
13
|
* Metadata accepted by `parserMd`. Set `frontmatter` on a `<File meta={…}>` to
|
|
@@ -32,7 +39,12 @@ type MdMeta = {
|
|
|
32
39
|
* })
|
|
33
40
|
* ```
|
|
34
41
|
*/
|
|
35
|
-
declare const parserMd:
|
|
42
|
+
declare const parserMd: {
|
|
43
|
+
name: string;
|
|
44
|
+
extNames: (".md" | ".markdown")[];
|
|
45
|
+
print(...parts: Array<PrintInput>): string;
|
|
46
|
+
parse(file: ast.FileNode<any>): string;
|
|
47
|
+
};
|
|
36
48
|
//#endregion
|
|
37
49
|
export { type MdMeta, parserMd };
|
|
38
50
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import "./chunk--u3MIqq1.js";
|
|
2
|
-
import {
|
|
3
|
-
import { defineParser } from "@kubb/core";
|
|
2
|
+
import { ast, defineParser } from "@kubb/core";
|
|
4
3
|
import { stringify } from "yaml";
|
|
5
4
|
//#region src/utils.ts
|
|
6
5
|
/**
|
|
@@ -73,7 +72,7 @@ const parserMd = defineParser({
|
|
|
73
72
|
parse(file) {
|
|
74
73
|
const sourceParts = [];
|
|
75
74
|
for (const source of file.sources) {
|
|
76
|
-
const text = extractStringsFromNodes(source.nodes);
|
|
75
|
+
const text = ast.extractStringsFromNodes(source.nodes);
|
|
77
76
|
if (text) sourceParts.push(text.trimEnd());
|
|
78
77
|
}
|
|
79
78
|
const body = sourceParts.join("\n\n");
|
package/dist/index.js.map
CHANGED
|
@@ -1 +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 serialised 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 *\n * ```\n * ---\n * <yaml>\n * ---\n * ```\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 banner/footer fields.\n */\nexport function printFrontmatter(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 printFrontmatter}; 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: string
|
|
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 serialised 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 *\n * ```\n * ---\n * <yaml>\n * ---\n * ```\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 banner/footer fields.\n */\nexport function printFrontmatter(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 printFrontmatter}; 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 : printFrontmatter(part)\n if (text) rendered.push(text.trimEnd())\n }\n return rendered.join('\\n\\n')\n}\n","import { ast } from '@kubb/core'\nimport { defineParser } from '@kubb/core'\nimport { print, type PrintInput } from './utils.ts'\n\n/**\n * Metadata accepted by `parserMd`. Set `frontmatter` on a `<File meta={…}>` to\n * have the parser prepend the corresponding YAML 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 * Add to the `parsers` array on `defineConfig` to opt in. `parserTs` keeps\n * handling `.ts`/`.js` files, `parserMd` claims `.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 *\n * export default defineConfig({\n * input: { path: './petStore.yaml' },\n * output: { path: './src/gen' },\n * adapter: adapterOas(),\n * parsers: [parserMd],\n * plugins: [],\n * })\n * ```\n */\nexport const parserMd = defineParser({\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 ?? undefined)\n\n const parts = [file.banner, frontmatter, body, file.footer].filter((segment): segment is string => Boolean(segment)).map((segment) => segment.trimEnd())\n return parts.join('\\n\\n')\n },\n})\n"],"mappings":";;;;;;;;;;;;;;;;AAoBA,SAAgB,iBAAiB,MAA0D;CACzF,IAAI,CAAC,QAAQ,OAAO,KAAK,KAAK,CAAC,WAAW,GAAG,OAAO;CACpD,OAAO,QAAQ,UAAU,KAAK,CAAC,SAAS,CAAC;;;;;;;;;;;;;AAc3C,SAAgB,MAAM,GAAG,OAAqD;CAC5E,MAAM,WAA0B,EAAE;CAClC,KAAK,MAAM,QAAQ,OAAO;EACxB,IAAI,SAAS,QAAQ,SAAS,KAAA,KAAa,SAAS,IAAI;EACxD,MAAM,OAAO,OAAO,SAAS,WAAW,OAAO,iBAAiB,KAAK;EACrE,IAAI,MAAM,SAAS,KAAK,KAAK,SAAS,CAAC;;CAEzC,OAAO,SAAS,KAAK,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;ACR9B,MAAa,WAAW,aAAa;CACnC,MAAM;CACN,UAAU,CAAC,OAAO,YAAY;CAC9B,MAAM,GAAG,OAA0B;EACjC,OAAO,MAAM,GAAG,MAAM;;CAExB,MAAM,MAAM;EACV,MAAM,cAA6B,EAAE;EACrC,KAAK,MAAM,UAAU,KAAK,SAAS;GACjC,MAAM,OAAO,IAAI,wBAAwB,OAAO,MAA6B;GAC7E,IAAI,MAAM,YAAY,KAAK,KAAK,SAAS,CAAC;;EAE5C,MAAM,OAAO,YAAY,KAAK,OAAO;EAErC,MAAM,OAAO,KAAK;EAClB,MAAM,cAAc,MAAM,MAAM,eAAe,KAAA,EAAU;EAGzD,OADc;GAAC,KAAK;GAAQ;GAAa;GAAM,KAAK;GAAO,CAAC,QAAQ,YAA+B,QAAQ,QAAQ,CAAC,CAAC,KAAK,YAAY,QAAQ,SAAS,CAC3I,CAAC,KAAK,OAAO;;CAE5B,CAAC"}
|
package/extension.yaml
CHANGED
|
@@ -27,11 +27,29 @@ resources:
|
|
|
27
27
|
changelog: https://github.com/kubb-labs/kubb/blob/main/packages/parser-md/CHANGELOG.md
|
|
28
28
|
featured: false
|
|
29
29
|
intro: |-
|
|
30
|
-
`@kubb/parser-md`
|
|
30
|
+
`@kubb/parser-md` lets Kubb emit `.md` and `.markdown` files. Register it alongside `parserTs` and any plugin that writes a markdown source will have its output serialized automatically.
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
The parser joins source blocks with blank lines. When `file.meta.frontmatter` is set, it prepends the YAML envelope — no separate `yaml` dependency needed. Pair it with `parserTs` when a generator emits both TypeScript and documentation files side by side.
|
|
33
|
+
options:
|
|
34
|
+
- name: frontmatter
|
|
35
|
+
type: 'Record<string, unknown> | null'
|
|
36
|
+
required: false
|
|
37
|
+
default: 'undefined'
|
|
38
|
+
description: |-
|
|
39
|
+
Set `frontmatter` on `file.meta` inside a plugin to have the parser prepend a YAML frontmatter block. Any serializable key-value object works.
|
|
40
|
+
codeBlock:
|
|
41
|
+
lang: typescript
|
|
42
|
+
title: plugin example
|
|
43
|
+
twoslash: false
|
|
44
|
+
code: |-
|
|
45
|
+
createFile({
|
|
46
|
+
baseName: 'README.md',
|
|
47
|
+
path: `${config.output.path}/README.md`,
|
|
48
|
+
meta: {
|
|
49
|
+
frontmatter: { title: 'API Reference', layout: 'doc' },
|
|
50
|
+
},
|
|
51
|
+
sources: [...],
|
|
52
|
+
})
|
|
35
53
|
examples:
|
|
36
54
|
- name: Standalone markdown
|
|
37
55
|
files:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/parser-md",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.27",
|
|
4
4
|
"description": "Markdown source file parser for Kubb. Converts the universal AST to `.md` source and renders YAML frontmatter via the `print` helper.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"codegen",
|
|
@@ -41,6 +41,16 @@
|
|
|
41
41
|
"access": "public",
|
|
42
42
|
"registry": "https://registry.npmjs.org/"
|
|
43
43
|
},
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"yaml": "^2.9.0",
|
|
46
|
+
"@kubb/core": "5.0.0-beta.27"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@internals/utils": "0.0.0"
|
|
50
|
+
},
|
|
51
|
+
"engines": {
|
|
52
|
+
"node": ">=22"
|
|
53
|
+
},
|
|
44
54
|
"scripts": {
|
|
45
55
|
"build": "tsdown",
|
|
46
56
|
"clean": "npx rimraf ./dist",
|
|
@@ -51,16 +61,5 @@
|
|
|
51
61
|
"start": "tsdown --watch",
|
|
52
62
|
"test": "vitest --passWithNoTests",
|
|
53
63
|
"typecheck": "tsc -p ./tsconfig.json --noEmit --emitDeclarationOnly false"
|
|
54
|
-
},
|
|
55
|
-
"dependencies": {
|
|
56
|
-
"@kubb/ast": "workspace:*",
|
|
57
|
-
"@kubb/core": "workspace:*",
|
|
58
|
-
"yaml": "catalog:"
|
|
59
|
-
},
|
|
60
|
-
"devDependencies": {
|
|
61
|
-
"@internals/utils": "workspace:*"
|
|
62
|
-
},
|
|
63
|
-
"engines": {
|
|
64
|
-
"node": ">=22"
|
|
65
64
|
}
|
|
66
|
-
}
|
|
65
|
+
}
|
package/src/parserMd.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { extractStringsFromNodes } from '@kubb/ast'
|
|
1
|
+
import { ast } from '@kubb/core'
|
|
3
2
|
import { defineParser } from '@kubb/core'
|
|
4
3
|
import { print, type PrintInput } from './utils.ts'
|
|
5
4
|
|
|
@@ -37,13 +36,13 @@ export type MdMeta = {
|
|
|
37
36
|
export const parserMd = defineParser({
|
|
38
37
|
name: 'markdown',
|
|
39
38
|
extNames: ['.md', '.markdown'],
|
|
40
|
-
print(...parts: PrintInput
|
|
39
|
+
print(...parts: Array<PrintInput>) {
|
|
41
40
|
return print(...parts)
|
|
42
41
|
},
|
|
43
42
|
parse(file) {
|
|
44
|
-
const sourceParts: string
|
|
43
|
+
const sourceParts: Array<string> = []
|
|
45
44
|
for (const source of file.sources) {
|
|
46
|
-
const text = extractStringsFromNodes(source.nodes as Array<CodeNode>)
|
|
45
|
+
const text = ast.extractStringsFromNodes(source.nodes as Array<ast.CodeNode>)
|
|
47
46
|
if (text) sourceParts.push(text.trimEnd())
|
|
48
47
|
}
|
|
49
48
|
const body = sourceParts.join('\n\n')
|
package/src/utils.ts
CHANGED
|
@@ -35,7 +35,7 @@ export function printFrontmatter(data: Record<string, unknown> | null | undefine
|
|
|
35
35
|
* ```
|
|
36
36
|
*/
|
|
37
37
|
export function print(...parts: Array<PrintInput | null | undefined>): string {
|
|
38
|
-
const rendered: string
|
|
38
|
+
const rendered: Array<string> = []
|
|
39
39
|
for (const part of parts) {
|
|
40
40
|
if (part === null || part === undefined || part === '') continue
|
|
41
41
|
const text = typeof part === 'string' ? part : printFrontmatter(part)
|