@temelj/mdx 0.5.0 → 0.7.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/esm/compiler.js +4 -11
- package/esm/plugins/heading-id/plugin.js +5 -7
- package/esm/plugins/remove-imports-exports.js +2 -2
- package/esm/plugins/syntax-highlight/code-meta.js +7 -7
- package/esm/plugins/syntax-highlight/plugin.js +2 -2
- package/esm/plugins/tree-processor/plugin.js +4 -5
- package/package.json +7 -9
- package/types/compiler.d.ts +5 -13
- package/types/compiler.d.ts.map +1 -1
- package/types/plugins/heading-id/plugin.d.ts +5 -2
- package/types/plugins/heading-id/plugin.d.ts.map +1 -1
- package/types/plugins/remove-imports-exports.d.ts +5 -2
- package/types/plugins/remove-imports-exports.d.ts.map +1 -1
- package/types/plugins/syntax-highlight/plugin.d.ts +5 -2
- package/types/plugins/syntax-highlight/plugin.d.ts.map +1 -1
- package/types/plugins/tree-processor/plugin.d.ts +5 -2
- package/types/plugins/tree-processor/plugin.d.ts.map +1 -1
- package/types/types.d.ts +0 -4
- package/types/types.d.ts.map +1 -1
package/esm/compiler.js
CHANGED
|
@@ -49,7 +49,7 @@ export class MdxCompiler {
|
|
|
49
49
|
}
|
|
50
50
|
return this;
|
|
51
51
|
}
|
|
52
|
-
async compile(source, { frontmatterOnly = false, mdxOptions
|
|
52
|
+
async compile(source, { frontmatterOnly = false, mdxOptions } = {}, frontmatterSchema) {
|
|
53
53
|
const vfile = new VFile({
|
|
54
54
|
value: source,
|
|
55
55
|
// Needed so vfile doesn't need to access fs.
|
|
@@ -80,16 +80,9 @@ export class MdxCompiler {
|
|
|
80
80
|
});
|
|
81
81
|
compiled = compiledFile.value.toString();
|
|
82
82
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
frontmatter = frontmatterSchema.parse(vfile.data.matter);
|
|
87
|
-
}
|
|
88
|
-
else if ("kind" in frontmatterSchema && frontmatterSchema.kind === "schema") {
|
|
89
|
-
const valibot = await import("valibot");
|
|
90
|
-
frontmatter = valibot.parse(frontmatterSchema, vfile.data.matter);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
83
|
+
const frontmatter = frontmatterSchema === undefined
|
|
84
|
+
? (vfile.data.matter ?? {})
|
|
85
|
+
: frontmatterSchema.parse(vfile.data.matter ?? {});
|
|
93
86
|
return {
|
|
94
87
|
compiled,
|
|
95
88
|
frontmatter: frontmatter,
|
|
@@ -4,18 +4,16 @@ import { visit } from "unist-util-visit";
|
|
|
4
4
|
/**
|
|
5
5
|
* A rehype plugin that adds IDs to heading tags.
|
|
6
6
|
*/
|
|
7
|
-
export
|
|
7
|
+
export const headingIdPlugin = ({ prefix } = {}) => {
|
|
8
8
|
const slugger = new GithubSlugger();
|
|
9
9
|
return (tree) => {
|
|
10
10
|
slugger.reset();
|
|
11
|
-
visit(tree, "element", visitor)
|
|
12
|
-
|
|
13
|
-
if (!parent || index === null || !node.tagName.startsWith("h")) {
|
|
11
|
+
visit(tree, "element", function visitor(node, index, parent) {
|
|
12
|
+
if (!parent || index === null || !node.tagName.startsWith("h"))
|
|
14
13
|
return;
|
|
15
|
-
}
|
|
16
14
|
const id = (prefix ?? "") + slugger.slug(hastToString(node));
|
|
17
15
|
node.properties.id = id;
|
|
18
|
-
}
|
|
16
|
+
});
|
|
19
17
|
return tree;
|
|
20
18
|
};
|
|
21
|
-
}
|
|
19
|
+
};
|
|
@@ -2,9 +2,9 @@ import { remove } from "unist-util-remove";
|
|
|
2
2
|
/**
|
|
3
3
|
* A remark plugin which removes all import and export statements.
|
|
4
4
|
*/
|
|
5
|
-
export
|
|
5
|
+
export const removeImportsExportsPlugin = () => {
|
|
6
6
|
return (tree) => {
|
|
7
7
|
remove(tree, "mdxjsEsm");
|
|
8
8
|
return tree;
|
|
9
9
|
};
|
|
10
|
-
}
|
|
10
|
+
};
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { parseNumericRange } from "@temelj/iterator";
|
|
2
|
-
import
|
|
2
|
+
import { z } from "zod";
|
|
3
3
|
export function extractCodeMeta(node) {
|
|
4
4
|
const meta = node?.data?.meta ?? node?.properties?.metastring ?? "";
|
|
5
5
|
return parseMetaString(meta);
|
|
6
6
|
}
|
|
7
|
-
const metaSchema =
|
|
8
|
-
highlight:
|
|
9
|
-
showLineNumbers:
|
|
10
|
-
commandLine:
|
|
11
|
-
fileName:
|
|
7
|
+
const metaSchema = z.object({
|
|
8
|
+
highlight: z.optional(z.string()),
|
|
9
|
+
showLineNumbers: z.optional(z.union([z.boolean(), z.string()])),
|
|
10
|
+
commandLine: z.optional(z.union([z.boolean(), z.string()])),
|
|
11
|
+
fileName: z.optional(z.string()),
|
|
12
12
|
});
|
|
13
13
|
function parseMetaString(meta) {
|
|
14
14
|
let raw;
|
|
@@ -18,7 +18,7 @@ function parseMetaString(meta) {
|
|
|
18
18
|
catch {
|
|
19
19
|
return {};
|
|
20
20
|
}
|
|
21
|
-
const parsed =
|
|
21
|
+
const parsed = metaSchema.parse(raw);
|
|
22
22
|
const options = {};
|
|
23
23
|
if (parsed.highlight !== undefined) {
|
|
24
24
|
options.highlight = { lineRange: parseNumericRange(parsed.highlight) };
|
|
@@ -7,7 +7,7 @@ import { extractCodeMeta } from "./code-meta.js";
|
|
|
7
7
|
/**
|
|
8
8
|
* A plugin that highlights code blocks using Shiki.
|
|
9
9
|
*/
|
|
10
|
-
export
|
|
10
|
+
export const syntaxHighlightPlugin = (options = {}) => {
|
|
11
11
|
return async (tree) => {
|
|
12
12
|
const promises = [];
|
|
13
13
|
async function visitor(node, index, parent) {
|
|
@@ -121,7 +121,7 @@ export function syntaxHighlightPlugin(options = {}) {
|
|
|
121
121
|
await Promise.all(promises);
|
|
122
122
|
return tree;
|
|
123
123
|
};
|
|
124
|
-
}
|
|
124
|
+
};
|
|
125
125
|
function getNodeLanguage(node) {
|
|
126
126
|
if (!Array.isArray(node.properties.className)) {
|
|
127
127
|
return undefined;
|
|
@@ -3,18 +3,17 @@ import { visit } from "unist-util-visit";
|
|
|
3
3
|
* A plugin that allows to process MDX tree nodes.
|
|
4
4
|
* It can be async or sync.
|
|
5
5
|
*/
|
|
6
|
-
export
|
|
6
|
+
export const treeProcessorPlugin = ({ process } = { process: () => { } }) => {
|
|
7
7
|
return async (tree) => {
|
|
8
8
|
const promises = [];
|
|
9
|
-
function
|
|
9
|
+
visit(tree, "element", function visitor(node, index, parent) {
|
|
10
10
|
const p = process(node, index, parent);
|
|
11
11
|
if (p instanceof Promise ||
|
|
12
12
|
Object.prototype.toString.call(p) === "[object Promise]") {
|
|
13
13
|
promises.push(p);
|
|
14
14
|
}
|
|
15
|
-
}
|
|
16
|
-
visit(tree, "element", visitElement);
|
|
15
|
+
});
|
|
17
16
|
await Promise.allSettled(promises);
|
|
18
17
|
return tree;
|
|
19
18
|
};
|
|
20
|
-
}
|
|
19
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@temelj/mdx",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Utilities for working with MDX.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mdx"
|
|
@@ -20,28 +20,26 @@
|
|
|
20
20
|
"import": {
|
|
21
21
|
"types": "./types/mod.d.ts",
|
|
22
22
|
"default": "./esm/mod.js"
|
|
23
|
-
}
|
|
24
|
-
"types": "./types/mod.d.ts"
|
|
23
|
+
}
|
|
25
24
|
}
|
|
26
25
|
},
|
|
27
26
|
"dependencies": {
|
|
28
|
-
"@temelj/iterator": "^0.
|
|
27
|
+
"@temelj/iterator": "^0.7.0",
|
|
29
28
|
"@mdx-js/mdx": "^3.1.0",
|
|
30
|
-
"@shikijs/transformers": "^3.
|
|
29
|
+
"@shikijs/transformers": "^3.8.0",
|
|
31
30
|
"@types/hast": "^3.0.4",
|
|
32
31
|
"github-slugger": "^2.0.0",
|
|
33
32
|
"hast": "^1.0.0",
|
|
34
33
|
"hast-util-to-string": "^3.0.1",
|
|
35
34
|
"remark-frontmatter": "^5.0.0",
|
|
36
35
|
"remark-gfm": "^4.0.1",
|
|
37
|
-
"shiki": "^3.
|
|
36
|
+
"shiki": "^3.8.0",
|
|
38
37
|
"unified": "^11.0.5",
|
|
39
38
|
"unist-util-remove": "^4.0.0",
|
|
40
39
|
"unist-util-visit": "^5.0.0",
|
|
41
40
|
"vfile": "^6.0.3",
|
|
42
|
-
"vfile-matter": "^5.0.
|
|
43
|
-
"zod": "^
|
|
44
|
-
"valibot": "^1.0.0-rc.1"
|
|
41
|
+
"vfile-matter": "^5.0.1",
|
|
42
|
+
"zod": "^4.0.5"
|
|
45
43
|
},
|
|
46
44
|
"devDependencies": {
|
|
47
45
|
"@types/node": "^20.9.0"
|
package/types/compiler.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { type CompileOptions as MdxJsCompileOptions } from "@mdx-js/mdx";
|
|
2
2
|
import remarkFrontmatterPlugin from "remark-frontmatter";
|
|
3
3
|
import remarkGfmPlugin from "remark-gfm";
|
|
4
|
-
import type
|
|
4
|
+
import type { Plugin } from "unified";
|
|
5
5
|
import type { z } from "zod";
|
|
6
|
-
import type {
|
|
6
|
+
import type { HastNode } from "./types.js";
|
|
7
7
|
export { remarkFrontmatterPlugin, remarkGfmPlugin };
|
|
8
8
|
/**
|
|
9
9
|
* Represents the source content for an MDX document.
|
|
@@ -16,14 +16,6 @@ export interface MdxCompileOptions {
|
|
|
16
16
|
frontmatterOnly?: boolean | undefined;
|
|
17
17
|
mdxOptions?: MdxJsCompileOptions;
|
|
18
18
|
}
|
|
19
|
-
/**
|
|
20
|
-
* The input frontmatter schema.
|
|
21
|
-
*/
|
|
22
|
-
export type FrontmatterInput = z.AnyZodObject | v.ObjectSchema<v.ObjectEntries, undefined>;
|
|
23
|
-
/**
|
|
24
|
-
* The output frontmatter type for a schema.
|
|
25
|
-
*/
|
|
26
|
-
export type FrontmatterOutput<T extends z.AnyZodObject | v.ObjectSchema<v.ObjectEntries, undefined>> = T extends z.ZodSchema ? z.infer<T> : T extends v.BaseSchema<unknown, unknown, v.BaseIssue<unknown>> ? v.InferOutput<T> : never;
|
|
27
19
|
/**
|
|
28
20
|
* The result of compiling an MDX document.
|
|
29
21
|
* Compiled content is optional, because sometimes we only need the frontmatter.
|
|
@@ -40,8 +32,8 @@ export declare class MdxCompiler {
|
|
|
40
32
|
private readonly remarkPlugins;
|
|
41
33
|
private readonly rehypePlugins;
|
|
42
34
|
constructor(mdxOptions?: MdxJsCompileOptions);
|
|
43
|
-
withRemarkPlugin<TOptions>(plugin:
|
|
44
|
-
withRehypePlugin<TOptions>(plugin:
|
|
45
|
-
compile<TFrontmatterSchema extends
|
|
35
|
+
withRemarkPlugin<TOptions>(plugin: Plugin<[TOptions?], HastNode, HastNode>, options?: TOptions): MdxCompiler;
|
|
36
|
+
withRehypePlugin<TOptions>(plugin: Plugin<[TOptions?], HastNode, HastNode>, options?: TOptions): MdxCompiler;
|
|
37
|
+
compile<TFrontmatterSchema extends z.ZodSchema>(source: MdxSource, { frontmatterOnly, mdxOptions }?: MdxCompileOptions, frontmatterSchema?: TFrontmatterSchema): Promise<MdxArtifact<z.output<TFrontmatterSchema>>>;
|
|
46
38
|
}
|
|
47
39
|
//# sourceMappingURL=compiler.d.ts.map
|
package/types/compiler.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compiler.d.ts","sourceRoot":"","sources":["../src/compiler.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,cAAc,IAAI,mBAAmB,EAC3C,MAAM,aAAa,CAAC;AACrB,OAAO,uBAAuB,MAAM,oBAAoB,CAAC;AACzD,OAAO,eAAe,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"compiler.d.ts","sourceRoot":"","sources":["../src/compiler.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,cAAc,IAAI,mBAAmB,EAC3C,MAAM,aAAa,CAAC;AACrB,OAAO,uBAAuB,MAAM,oBAAoB,CAAC;AACzD,OAAO,eAAe,MAAM,YAAY,CAAC;AAGzC,OAAO,KAAK,EAA4B,MAAM,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,OAAO,EAAE,uBAAuB,EAAE,eAAe,EAAE,CAAC;AAEpD;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,UAAU,CAAC;AAE5C;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,eAAe,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IACtC,UAAU,CAAC,EAAE,mBAAmB,CAAC;CAClC;AAED;;;GAGG;AACH,MAAM,WAAW,WAAW,CAAC,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IACjE,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,WAAW,EAAE,YAAY,CAAC;CAC3B;AAED;;GAEG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAsB;IACjD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAgB;IAC9C,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAgB;gBAE3B,UAAU,GAAE,mBAAwB;IAMhD,gBAAgB,CAAC,QAAQ,EAC9B,MAAM,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,EAC/C,OAAO,CAAC,EAAE,QAAQ,GACjB,WAAW;IASP,gBAAgB,CAAC,QAAQ,EAC9B,MAAM,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,QAAQ,EAAE,QAAQ,CAAC,EAC/C,OAAO,CAAC,EAAE,QAAQ,GACjB,WAAW;IASD,OAAO,CAAC,kBAAkB,SAAS,CAAC,CAAC,SAAS,EACzD,MAAM,EAAE,SAAS,EACjB,EAAE,eAAuB,EAAE,UAAU,EAAE,GAAE,iBAAsB,EAC/D,iBAAiB,CAAC,EAAE,kBAAkB,GACrC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC,CAAC;CA2CtD"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Plugin } from "unified";
|
|
2
|
+
import type { HastNode } from "../../types.js";
|
|
2
3
|
/**
|
|
3
4
|
* Options for {@linkcode headingIdPlugin}.
|
|
4
5
|
*/
|
|
@@ -9,5 +10,7 @@ export interface HeadingIdPluginOptions {
|
|
|
9
10
|
/**
|
|
10
11
|
* A rehype plugin that adds IDs to heading tags.
|
|
11
12
|
*/
|
|
12
|
-
export declare
|
|
13
|
+
export declare const headingIdPlugin: Plugin<[
|
|
14
|
+
HeadingIdPluginOptions?
|
|
15
|
+
], HastNode, HastNode>;
|
|
13
16
|
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../src/plugins/heading-id/plugin.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../src/plugins/heading-id/plugin.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEtC,OAAO,KAAK,EAAe,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE5D;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,8BAA8B;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,MAAM,CAClC;IAAC,sBAAsB,CAAC;CAAC,EACzB,QAAQ,EACR,QAAQ,CAoBT,CAAC"}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Plugin } from "unified";
|
|
2
|
+
import type { HastNode } from "../types.js";
|
|
2
3
|
/**
|
|
3
4
|
* A remark plugin which removes all import and export statements.
|
|
4
5
|
*/
|
|
5
|
-
export declare
|
|
6
|
+
export declare const removeImportsExportsPlugin: Plugin<[
|
|
7
|
+
unknown
|
|
8
|
+
], HastNode, HastNode>;
|
|
6
9
|
//# sourceMappingURL=remove-imports-exports.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remove-imports-exports.d.ts","sourceRoot":"","sources":["../../src/plugins/remove-imports-exports.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"remove-imports-exports.d.ts","sourceRoot":"","sources":["../../src/plugins/remove-imports-exports.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEtC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAE5C;;GAEG;AACH,eAAO,MAAM,0BAA0B,EAAE,MAAM,CAC7C;IAAC,OAAO;CAAC,EACT,QAAQ,EACR,QAAQ,CAMT,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type BundledLanguage, type BundledTheme, type CodeToHastOptions } from "shiki";
|
|
2
2
|
import { type TransformerNotationHighlightOptions } from "@shikijs/transformers";
|
|
3
|
-
import type {
|
|
3
|
+
import type { Plugin } from "unified";
|
|
4
|
+
import type { HastNode } from "../../types.js";
|
|
4
5
|
type ShikiHastOptions = Partial<CodeToHastOptions<BundledLanguage, BundledTheme>>;
|
|
5
6
|
type SyntaxDataAttribute = "source-code" | "language" | "line-count";
|
|
6
7
|
/**
|
|
@@ -49,6 +50,8 @@ export interface SyntaxHighlightPluginOptions {
|
|
|
49
50
|
/**
|
|
50
51
|
* A plugin that highlights code blocks using Shiki.
|
|
51
52
|
*/
|
|
52
|
-
export declare
|
|
53
|
+
export declare const syntaxHighlightPlugin: Plugin<[
|
|
54
|
+
SyntaxHighlightPluginOptions?
|
|
55
|
+
], HastNode, HastNode>;
|
|
53
56
|
export {};
|
|
54
57
|
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../src/plugins/syntax-highlight/plugin.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,YAAY,EAEjB,KAAK,iBAAiB,EAEvB,MAAM,OAAO,CAAC;AAEf,OAAO,EAEL,KAAK,mCAAmC,EACzC,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../src/plugins/syntax-highlight/plugin.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,YAAY,EAEjB,KAAK,iBAAiB,EAEvB,MAAM,OAAO,CAAC;AAEf,OAAO,EAEL,KAAK,mCAAmC,EACzC,MAAM,uBAAuB,CAAC;AAE/B,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAGtC,OAAO,KAAK,EAAe,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAI5D,KAAK,gBAAgB,GAAG,OAAO,CAC7B,iBAAiB,CAAC,eAAe,EAAE,YAAY,CAAC,CACjD,CAAC;AAEF,KAAK,mBAAmB,GAAG,aAAa,GAAG,UAAU,GAAG,YAAY,CAAC;AAErE;;GAEG;AACH,MAAM,WAAW,4BAA4B;IAC3C;;;OAGG;IACH,qBAAqB,CAAC,EAAE,mBAAmB,EAAE,CAAC;IAE9C;;OAEG;IACH,SAAS,CAAC,EAAE;QACV,WAAW,CAAC,EAAE,mCAAmC,CAAC;KACnD,CAAC;IAEF;;OAEG;IACH,WAAW,CAAC,EAAE;QACZ;;;WAGG;QACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAC3B;;WAEG;QACH,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,CAAC;IAEF;;OAEG;IACH,WAAW,CAAC,EAAE;QACZ;;WAEG;QACH,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,CAAC;IAEF;;OAEG;IACH,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;CACrC;AAED;;GAEG;AACH,eAAO,MAAM,qBAAqB,EAAE,MAAM,CACxC;IAAC,4BAA4B,CAAC;CAAC,EAC/B,QAAQ,EACR,QAAQ,CA4KT,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Plugin } from "unified";
|
|
2
|
+
import type { HastElement, HastNode } from "../../types.js";
|
|
2
3
|
export type MdxTreeProcessor = (node: HastElement, index: number, parent: HastElement) => void | Promise<void>;
|
|
3
4
|
/**
|
|
4
5
|
* Options for {@linkcode treeProcessorPlugin}.
|
|
@@ -11,6 +12,8 @@ type TreeProcessorPluginOptions = {
|
|
|
11
12
|
* A plugin that allows to process MDX tree nodes.
|
|
12
13
|
* It can be async or sync.
|
|
13
14
|
*/
|
|
14
|
-
export declare
|
|
15
|
+
export declare const treeProcessorPlugin: Plugin<[
|
|
16
|
+
TreeProcessorPluginOptions?
|
|
17
|
+
], HastNode, HastNode>;
|
|
15
18
|
export {};
|
|
16
19
|
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../src/plugins/tree-processor/plugin.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../src/plugins/tree-processor/plugin.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEtC,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAE5D,MAAM,MAAM,gBAAgB,GAAG,CAC7B,IAAI,EAAE,WAAW,EACjB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,WAAW,KAChB,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAE1B;;GAEG;AACH,KAAK,0BAA0B,GAAG;IAChC,qBAAqB;IACrB,OAAO,EAAE,gBAAgB,CAAC;CAC3B,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,mBAAmB,EAAE,MAAM,CACtC;IAAC,0BAA0B,CAAC;CAAC,EAC7B,QAAQ,EACR,QAAQ,CA2BT,CAAC"}
|
package/types/types.d.ts
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
1
|
import type { Element, Node } from "hast";
|
|
2
|
-
import type { CompileResults, Processor } from "unified";
|
|
3
2
|
export type { Element as HastElement, Node as HastNode };
|
|
4
|
-
type MaybePromise<T> = T | Promise<T> | PromiseLike<T>;
|
|
5
|
-
type Plugin<TParameters extends unknown[] = [], TInput extends string | Node | undefined = Node, TOutput = TInput> = (this: Processor, ...parameters: TParameters) => MaybePromise<TInput extends string ? TOutput extends Node | undefined ? undefined | void : never : TOutput extends CompileResults ? TInput extends Node | undefined ? undefined | void : never : Transformer<TInput extends Node ? TInput : Node, TOutput extends Node ? TOutput : Node> | undefined | void>;
|
|
6
|
-
export type PluginFactory<TParameters extends unknown[] = [], TInput extends string | Node | undefined = Node, TOutput = TInput> = (parameters?: TParameters) => MaybePromise<Plugin<TParameters, TInput, TOutput>>;
|
|
7
3
|
//# sourceMappingURL=types.d.ts.map
|
package/types/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAE1C,YAAY,EAAE,OAAO,IAAI,WAAW,EAAE,IAAI,IAAI,QAAQ,EAAE,CAAC"}
|