@temelj/mdx 0.8.0 → 0.8.2

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 (44) hide show
  1. package/dist/compiler.d.ts +28 -20
  2. package/dist/compiler.d.ts.map +1 -0
  3. package/dist/compiler.js +62 -71
  4. package/dist/compiler.js.map +1 -0
  5. package/dist/mod.d.ts +8 -3
  6. package/dist/mod.js +8 -3
  7. package/dist/plugins/heading-id/plugin.d.ts +12 -8
  8. package/dist/plugins/heading-id/plugin.d.ts.map +1 -0
  9. package/dist/plugins/heading-id/plugin.js +20 -15
  10. package/dist/plugins/heading-id/plugin.js.map +1 -0
  11. package/dist/plugins/mod.d.ts +5 -4
  12. package/dist/plugins/mod.js +6 -4
  13. package/dist/plugins/remove-imports-exports.d.ts +9 -5
  14. package/dist/plugins/remove-imports-exports.d.ts.map +1 -0
  15. package/dist/plugins/remove-imports-exports.js +13 -7
  16. package/dist/plugins/remove-imports-exports.js.map +1 -0
  17. package/dist/plugins/syntax-highlight/code-meta.d.ts +19 -14
  18. package/dist/plugins/syntax-highlight/code-meta.d.ts.map +1 -0
  19. package/dist/plugins/syntax-highlight/code-meta.js +31 -43
  20. package/dist/plugins/syntax-highlight/code-meta.js.map +1 -0
  21. package/dist/plugins/syntax-highlight/plugin.d.ts +43 -41
  22. package/dist/plugins/syntax-highlight/plugin.d.ts.map +1 -0
  23. package/dist/plugins/syntax-highlight/plugin.js +88 -129
  24. package/dist/plugins/syntax-highlight/plugin.js.map +1 -0
  25. package/dist/plugins/tree-processor/plugin.d.ts +11 -9
  26. package/dist/plugins/tree-processor/plugin.d.ts.map +1 -0
  27. package/dist/plugins/tree-processor/plugin.js +19 -16
  28. package/dist/plugins/tree-processor/plugin.js.map +1 -0
  29. package/dist/types.d.ts +2 -2
  30. package/dist/types.js +1 -1
  31. package/package.json +9 -4
  32. package/.turbo/turbo-build.log +0 -4
  33. package/compiler.test.ts +0 -117
  34. package/compiler.ts +0 -124
  35. package/mod.ts +0 -3
  36. package/plugins/heading-id/plugin.ts +0 -42
  37. package/plugins/mod.ts +0 -4
  38. package/plugins/remove-imports-exports.ts +0 -18
  39. package/plugins/syntax-highlight/code-meta.test.ts +0 -22
  40. package/plugins/syntax-highlight/code-meta.ts +0 -76
  41. package/plugins/syntax-highlight/plugin.ts +0 -266
  42. package/plugins/tree-processor/plugin.ts +0 -54
  43. package/tsconfig.json +0 -18
  44. package/types.ts +0 -3
@@ -1,38 +1,46 @@
1
- import { type CompileOptions as MdxJsCompileOptions } from "@mdx-js/mdx";
1
+ import { HastNode as Node } from "./types.js";
2
+ import { CompileOptions } from "@mdx-js/mdx";
2
3
  import remarkFrontmatterPlugin from "remark-frontmatter";
3
4
  import remarkGfmPlugin from "remark-gfm";
4
- import type { Plugin } from "unified";
5
- import type { z } from "zod";
6
- import type { HastNode } from "./types";
7
- export { remarkFrontmatterPlugin, remarkGfmPlugin };
5
+ import { z } from "zod";
6
+ import { Plugin } from "unified";
7
+
8
+ //#region src/compiler.d.ts
9
+
8
10
  /**
9
11
  * Represents the source content for an MDX document.
10
12
  */
11
- export type MdxSource = string | Uint8Array;
13
+ type MdxSource = string | Uint8Array;
12
14
  /**
13
15
  * Options for compiling an MDX document.
14
16
  */
15
- export interface MdxCompileOptions {
16
- frontmatterOnly?: boolean | undefined;
17
- mdxOptions?: MdxJsCompileOptions;
17
+ interface MdxCompileOptions {
18
+ frontmatterOnly?: boolean | undefined;
19
+ mdxOptions?: CompileOptions;
18
20
  }
19
21
  /**
20
22
  * The result of compiling an MDX document.
21
23
  * Compiled content is optional, because sometimes we only need the frontmatter.
22
24
  */
23
- export interface MdxArtifact<TFrontmatter = Record<string, unknown>> {
24
- compiled?: string | undefined;
25
- frontmatter: TFrontmatter;
25
+ interface MdxArtifact<TFrontmatter = Record<string, unknown>> {
26
+ compiled?: string | undefined;
27
+ frontmatter: TFrontmatter;
26
28
  }
27
29
  /**
28
30
  * A reusable compiler for compiling MDX.
29
31
  */
30
- export declare class MdxCompiler {
31
- private readonly mdxOptions;
32
- private readonly remarkPlugins;
33
- private readonly rehypePlugins;
34
- constructor(mdxOptions?: MdxJsCompileOptions);
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>>>;
32
+ declare class MdxCompiler {
33
+ private readonly mdxOptions;
34
+ private readonly remarkPlugins;
35
+ private readonly rehypePlugins;
36
+ constructor(mdxOptions?: CompileOptions);
37
+ withRemarkPlugin<TOptions>(plugin: Plugin<[TOptions?], Node, Node>, options?: TOptions): MdxCompiler;
38
+ withRehypePlugin<TOptions>(plugin: Plugin<[TOptions?], Node, Node>, options?: TOptions): MdxCompiler;
39
+ compile<TFrontmatterSchema extends z.ZodSchema>(source: MdxSource, {
40
+ frontmatterOnly,
41
+ mdxOptions
42
+ }?: MdxCompileOptions, frontmatterSchema?: TFrontmatterSchema): Promise<MdxArtifact<z.output<TFrontmatterSchema>>>;
38
43
  }
44
+ //#endregion
45
+ export { MdxArtifact, MdxCompileOptions, MdxCompiler, MdxSource, remarkFrontmatterPlugin, remarkGfmPlugin };
46
+ //# sourceMappingURL=compiler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compiler.d.ts","names":[],"sources":["../src/compiler.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;AAkBA;AAKA;AASiB,KAdL,SAAA,GAcgB,MAAA,GAdK,UAcW;AAQ5C;;;AAYgC,UA7Bf,iBAAA,CA6Be;EAAU,eAAA,CAAA,EAAA,OAAA,GAAA,SAAA;EAA9B,UAAA,CAAA,EA3BG,cA2BH;;;;;;AAYA,UAhCK,WAgCL,CAAA,eAhCgC,MAgChC,CAAA,MAAA,EAAA,OAAA,CAAA,CAAA,CAAA;EACE,QAAA,CAAA,EAAA,MAAA,GAAA,SAAA;EACT,WAAA,EAhCU,YAgCV;;;;;AAWwC,cArChC,WAAA,CAqCgC;EACrB,iBAAA,UAAA;EACU,iBAAA,aAAA;EAAP,iBAAA,aAAA;EAAd,WAAA,CAAA,UAAA,CAAA,EAlCoB,cAkCpB;EAAR,gBAAA,CAAA,QAAA,CAAA,CAAA,MAAA,EA3BO,MA2BP,CAAA,CA3Be,QA2Bf,CAAA,CAAA,EA3B2B,IA2B3B,EA3BqC,IA2BrC,CAAA,EAAA,OAAA,CAAA,EA1BS,QA0BT,CAAA,EAzBA,WAyBA;EAAO,gBAAA,CAAA,QAAA,CAAA,CAAA,MAAA,EAfA,MAeA,CAAA,CAfQ,QAeR,CAAA,CAAA,EAfoB,IAepB,EAf8B,IAe9B,CAAA,EAAA,OAAA,CAAA,EAdE,QAcF,CAAA,EAbP,WAaO;qCAJsC,CAAA,CAAE,mBACxC;;;MACiC,uCACrB,qBACnB,QAAQ,YAAY,CAAA,CAAE,OAAO"}
package/dist/compiler.js CHANGED
@@ -1,76 +1,67 @@
1
- import { compile as compileMdxJs, } from "@mdx-js/mdx";
1
+ import { compile } from "@mdx-js/mdx";
2
2
  import remarkFrontmatterPlugin from "remark-frontmatter";
3
3
  import remarkGfmPlugin from "remark-gfm";
4
4
  import { VFile } from "vfile";
5
5
  import { matter } from "vfile-matter";
6
- export { remarkFrontmatterPlugin, remarkGfmPlugin };
6
+
7
+ //#region src/compiler.ts
7
8
  /**
8
- * A reusable compiler for compiling MDX.
9
- */
10
- export class MdxCompiler {
11
- mdxOptions;
12
- remarkPlugins;
13
- rehypePlugins;
14
- constructor(mdxOptions = {}) {
15
- this.mdxOptions = mdxOptions;
16
- this.remarkPlugins = [remarkFrontmatterPlugin, remarkGfmPlugin];
17
- this.rehypePlugins = [];
18
- }
19
- withRemarkPlugin(plugin, options) {
20
- if (options === undefined) {
21
- this.remarkPlugins.push(plugin);
22
- }
23
- else {
24
- this.remarkPlugins.push([plugin, options]);
25
- }
26
- return this;
27
- }
28
- withRehypePlugin(plugin, options) {
29
- if (options === undefined) {
30
- this.rehypePlugins.push(plugin);
31
- }
32
- else {
33
- this.rehypePlugins.push([plugin, options]);
34
- }
35
- return this;
36
- }
37
- async compile(source, { frontmatterOnly = false, mdxOptions } = {}, frontmatterSchema) {
38
- const vfile = new VFile({
39
- value: source,
40
- // Needed so vfile doesn't need to access fs.
41
- cwd: "/",
42
- path: "/",
43
- message: {},
44
- messages: {},
45
- });
46
- matter(vfile, { strip: true });
47
- const remarkPlugins = [
48
- ...this.remarkPlugins,
49
- ...(this.mdxOptions?.remarkPlugins ?? []),
50
- ...(mdxOptions?.remarkPlugins ?? []),
51
- ];
52
- const rehypePlugins = [
53
- ...this.rehypePlugins,
54
- ...(this.mdxOptions?.rehypePlugins ?? []),
55
- ...(mdxOptions?.rehypePlugins ?? []),
56
- ];
57
- let compiled;
58
- if (!frontmatterOnly) {
59
- const compiledFile = await compileMdxJs(vfile, {
60
- outputFormat: "function-body",
61
- ...(this.mdxOptions ?? {}),
62
- ...(mdxOptions ?? {}),
63
- remarkPlugins,
64
- rehypePlugins,
65
- });
66
- compiled = compiledFile.value.toString();
67
- }
68
- const frontmatter = frontmatterSchema === undefined
69
- ? (vfile.data.matter ?? {})
70
- : frontmatterSchema.parse(vfile.data.matter ?? {});
71
- return {
72
- compiled,
73
- frontmatter: frontmatter,
74
- };
75
- }
76
- }
9
+ * A reusable compiler for compiling MDX.
10
+ */
11
+ var MdxCompiler = class {
12
+ mdxOptions;
13
+ remarkPlugins;
14
+ rehypePlugins;
15
+ constructor(mdxOptions = {}) {
16
+ this.mdxOptions = mdxOptions;
17
+ this.remarkPlugins = [remarkFrontmatterPlugin, remarkGfmPlugin];
18
+ this.rehypePlugins = [];
19
+ }
20
+ withRemarkPlugin(plugin, options) {
21
+ if (options === void 0) this.remarkPlugins.push(plugin);
22
+ else this.remarkPlugins.push([plugin, options]);
23
+ return this;
24
+ }
25
+ withRehypePlugin(plugin, options) {
26
+ if (options === void 0) this.rehypePlugins.push(plugin);
27
+ else this.rehypePlugins.push([plugin, options]);
28
+ return this;
29
+ }
30
+ async compile(source, { frontmatterOnly = false, mdxOptions } = {}, frontmatterSchema) {
31
+ const vfile = new VFile({
32
+ value: source,
33
+ cwd: "/",
34
+ path: "/",
35
+ message: {},
36
+ messages: {}
37
+ });
38
+ matter(vfile, { strip: true });
39
+ const remarkPlugins = [
40
+ ...this.remarkPlugins,
41
+ ...this.mdxOptions?.remarkPlugins ?? [],
42
+ ...mdxOptions?.remarkPlugins ?? []
43
+ ];
44
+ const rehypePlugins = [
45
+ ...this.rehypePlugins,
46
+ ...this.mdxOptions?.rehypePlugins ?? [],
47
+ ...mdxOptions?.rehypePlugins ?? []
48
+ ];
49
+ let compiled;
50
+ if (!frontmatterOnly) compiled = (await compile(vfile, {
51
+ outputFormat: "function-body",
52
+ ...this.mdxOptions ?? {},
53
+ ...mdxOptions ?? {},
54
+ remarkPlugins,
55
+ rehypePlugins
56
+ })).value.toString();
57
+ const frontmatter = frontmatterSchema === void 0 ? vfile.data.matter ?? {} : frontmatterSchema.parse(vfile.data.matter ?? {});
58
+ return {
59
+ compiled,
60
+ frontmatter
61
+ };
62
+ }
63
+ };
64
+
65
+ //#endregion
66
+ export { MdxCompiler, remarkFrontmatterPlugin, remarkGfmPlugin };
67
+ //# sourceMappingURL=compiler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compiler.js","names":["compiled: string | undefined","compileMdxJs"],"sources":["../src/compiler.ts"],"sourcesContent":["import {\n compile as compileMdxJs,\n type CompileOptions as MdxJsCompileOptions,\n} from \"@mdx-js/mdx\";\nimport remarkFrontmatterPlugin from \"remark-frontmatter\";\nimport remarkGfmPlugin from \"remark-gfm\";\nimport type { Pluggable, PluggableList, Plugin } from \"unified\";\nimport { VFile } from \"vfile\";\nimport { matter } from \"vfile-matter\";\nimport type { z } from \"zod\";\n\nimport type { HastNode } from \"./types\";\n\nexport { remarkFrontmatterPlugin, remarkGfmPlugin };\n\n/**\n * Represents the source content for an MDX document.\n */\nexport type MdxSource = string | Uint8Array;\n\n/**\n * Options for compiling an MDX document.\n */\nexport interface MdxCompileOptions {\n frontmatterOnly?: boolean | undefined;\n mdxOptions?: MdxJsCompileOptions;\n}\n\n/**\n * The result of compiling an MDX document.\n * Compiled content is optional, because sometimes we only need the frontmatter.\n */\nexport interface MdxArtifact<TFrontmatter = Record<string, unknown>> {\n compiled?: string | undefined;\n frontmatter: TFrontmatter;\n}\n\n/**\n * A reusable compiler for compiling MDX.\n */\nexport class MdxCompiler {\n private readonly mdxOptions: MdxJsCompileOptions;\n private readonly remarkPlugins: PluggableList;\n private readonly rehypePlugins: PluggableList;\n\n public constructor(mdxOptions: MdxJsCompileOptions = {}) {\n this.mdxOptions = mdxOptions;\n this.remarkPlugins = [remarkFrontmatterPlugin, remarkGfmPlugin];\n this.rehypePlugins = [];\n }\n\n public withRemarkPlugin<TOptions>(\n plugin: Plugin<[TOptions?], HastNode, HastNode>,\n options?: TOptions,\n ): MdxCompiler {\n if (options === undefined) {\n this.remarkPlugins.push(plugin as Pluggable);\n } else {\n this.remarkPlugins.push([plugin, options] as Pluggable);\n }\n return this;\n }\n\n public withRehypePlugin<TOptions>(\n plugin: Plugin<[TOptions?], HastNode, HastNode>,\n options?: TOptions,\n ): MdxCompiler {\n if (options === undefined) {\n this.rehypePlugins.push(plugin as Pluggable);\n } else {\n this.rehypePlugins.push([plugin, options] as Pluggable);\n }\n return this;\n }\n\n public async compile<TFrontmatterSchema extends z.ZodSchema>(\n source: MdxSource,\n { frontmatterOnly = false, mdxOptions }: MdxCompileOptions = {},\n frontmatterSchema?: TFrontmatterSchema,\n ): Promise<MdxArtifact<z.output<TFrontmatterSchema>>> {\n const vfile = new VFile({\n value: source,\n // Needed so vfile doesn't need to access fs.\n cwd: \"/\",\n path: \"/\",\n message: {},\n messages: {},\n });\n matter(vfile, { strip: true });\n\n const remarkPlugins = [\n ...this.remarkPlugins,\n ...(this.mdxOptions?.remarkPlugins ?? []),\n ...(mdxOptions?.remarkPlugins ?? []),\n ];\n const rehypePlugins = [\n ...this.rehypePlugins,\n ...(this.mdxOptions?.rehypePlugins ?? []),\n ...(mdxOptions?.rehypePlugins ?? []),\n ];\n\n let compiled: string | undefined;\n if (!frontmatterOnly) {\n const compiledFile = await compileMdxJs(vfile, {\n outputFormat: \"function-body\",\n ...(this.mdxOptions ?? {}),\n ...(mdxOptions ?? {}),\n remarkPlugins,\n rehypePlugins,\n });\n compiled = compiledFile.value.toString();\n }\n\n const frontmatter =\n frontmatterSchema === undefined\n ? (vfile.data.matter ?? {})\n : frontmatterSchema.parse(vfile.data.matter ?? {});\n\n return {\n compiled,\n frontmatter: frontmatter as z.output<TFrontmatterSchema>,\n };\n }\n}\n"],"mappings":";;;;;;;;;;AAwCA,IAAa,cAAb,MAAyB;CACvB,AAAiB;CACjB,AAAiB;CACjB,AAAiB;CAEjB,AAAO,YAAY,aAAkC,EAAE,EAAE;AACvD,OAAK,aAAa;AAClB,OAAK,gBAAgB,CAAC,yBAAyB,gBAAgB;AAC/D,OAAK,gBAAgB,EAAE;;CAGzB,AAAO,iBACL,QACA,SACa;AACb,MAAI,YAAY,OACd,MAAK,cAAc,KAAK,OAAoB;MAE5C,MAAK,cAAc,KAAK,CAAC,QAAQ,QAAQ,CAAc;AAEzD,SAAO;;CAGT,AAAO,iBACL,QACA,SACa;AACb,MAAI,YAAY,OACd,MAAK,cAAc,KAAK,OAAoB;MAE5C,MAAK,cAAc,KAAK,CAAC,QAAQ,QAAQ,CAAc;AAEzD,SAAO;;CAGT,MAAa,QACX,QACA,EAAE,kBAAkB,OAAO,eAAkC,EAAE,EAC/D,mBACoD;EACpD,MAAM,QAAQ,IAAI,MAAM;GACtB,OAAO;GAEP,KAAK;GACL,MAAM;GACN,SAAS,EAAE;GACX,UAAU,EAAE;GACb,CAAC;AACF,SAAO,OAAO,EAAE,OAAO,MAAM,CAAC;EAE9B,MAAM,gBAAgB;GACpB,GAAG,KAAK;GACR,GAAI,KAAK,YAAY,iBAAiB,EAAE;GACxC,GAAI,YAAY,iBAAiB,EAAE;GACpC;EACD,MAAM,gBAAgB;GACpB,GAAG,KAAK;GACR,GAAI,KAAK,YAAY,iBAAiB,EAAE;GACxC,GAAI,YAAY,iBAAiB,EAAE;GACpC;EAED,IAAIA;AACJ,MAAI,CAAC,gBAQH,aAPqB,MAAMC,QAAa,OAAO;GAC7C,cAAc;GACd,GAAI,KAAK,cAAc,EAAE;GACzB,GAAI,cAAc,EAAE;GACpB;GACA;GACD,CAAC,EACsB,MAAM,UAAU;EAG1C,MAAM,cACJ,sBAAsB,SACjB,MAAM,KAAK,UAAU,EAAE,GACxB,kBAAkB,MAAM,MAAM,KAAK,UAAU,EAAE,CAAC;AAEtD,SAAO;GACL;GACa;GACd"}
package/dist/mod.d.ts CHANGED
@@ -1,3 +1,8 @@
1
- export * from "./plugins/mod";
2
- export * from "./types";
3
- export * from "./compiler";
1
+ import { HastElement as Element, HastNode as Node } from "./types.js";
2
+ import { MdxArtifact, MdxCompileOptions, MdxCompiler, MdxSource, remarkFrontmatterPlugin, remarkGfmPlugin } from "./compiler.js";
3
+ import { HeadingIdPluginOptions, headingIdPlugin } from "./plugins/heading-id/plugin.js";
4
+ import { SyntaxHighlightPluginOptions, syntaxHighlightPlugin } from "./plugins/syntax-highlight/plugin.js";
5
+ import { MdxTreeProcessor, treeProcessorPlugin } from "./plugins/tree-processor/plugin.js";
6
+ import { removeImportsExportsPlugin } from "./plugins/remove-imports-exports.js";
7
+ import "./plugins/mod.js";
8
+ export { Element as HastElement, Node as HastNode, HeadingIdPluginOptions, MdxArtifact, MdxCompileOptions, MdxCompiler, MdxSource, MdxTreeProcessor, SyntaxHighlightPluginOptions, headingIdPlugin, remarkFrontmatterPlugin, remarkGfmPlugin, removeImportsExportsPlugin, syntaxHighlightPlugin, treeProcessorPlugin };
package/dist/mod.js CHANGED
@@ -1,3 +1,8 @@
1
- export * from "./plugins/mod";
2
- export * from "./types";
3
- export * from "./compiler";
1
+ import { MdxCompiler, remarkFrontmatterPlugin, remarkGfmPlugin } from "./compiler.js";
2
+ import { headingIdPlugin } from "./plugins/heading-id/plugin.js";
3
+ import { syntaxHighlightPlugin } from "./plugins/syntax-highlight/plugin.js";
4
+ import { treeProcessorPlugin } from "./plugins/tree-processor/plugin.js";
5
+ import { removeImportsExportsPlugin } from "./plugins/remove-imports-exports.js";
6
+ import "./plugins/mod.js";
7
+
8
+ export { MdxCompiler, headingIdPlugin, remarkFrontmatterPlugin, remarkGfmPlugin, removeImportsExportsPlugin, syntaxHighlightPlugin, treeProcessorPlugin };
@@ -1,15 +1,19 @@
1
- import type { Plugin } from "unified";
2
- import type { HastNode } from "../../types";
1
+ import { HastNode as Node } from "../../types.js";
2
+ import { Plugin } from "unified";
3
+
4
+ //#region src/plugins/heading-id/plugin.d.ts
5
+
3
6
  /**
4
7
  * Options for {@linkcode headingIdPlugin}.
5
8
  */
6
- export interface HeadingIdPluginOptions {
7
- /** Prefix for title slugs. */
8
- prefix?: string;
9
+ interface HeadingIdPluginOptions {
10
+ /** Prefix for title slugs. */
11
+ prefix?: string;
9
12
  }
10
13
  /**
11
14
  * A rehype plugin that adds IDs to heading tags.
12
15
  */
13
- export declare const headingIdPlugin: Plugin<[
14
- HeadingIdPluginOptions?
15
- ], HastNode, HastNode>;
16
+ declare const headingIdPlugin: Plugin<[HeadingIdPluginOptions?], Node, Node>;
17
+ //#endregion
18
+ export { HeadingIdPluginOptions, headingIdPlugin };
19
+ //# sourceMappingURL=plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.d.ts","names":[],"sources":["../../../src/plugins/heading-id/plugin.ts"],"sourcesContent":[],"mappings":";;;;;;;AAUA;AAQa,UARI,sBAAA,CA+BhB;EAtBE;EACD,MAAA,CAAA,EAAA,MAAA;;;;;cAFW,iBAAiB,QAC3B,0BACD,MACA"}
@@ -1,19 +1,24 @@
1
1
  import GithubSlugger from "github-slugger";
2
- import { toString as hastToString } from "hast-util-to-string";
2
+ import { toString } from "hast-util-to-string";
3
3
  import { visit } from "unist-util-visit";
4
+
5
+ //#region src/plugins/heading-id/plugin.ts
4
6
  /**
5
- * A rehype plugin that adds IDs to heading tags.
6
- */
7
- export const headingIdPlugin = ({ prefix } = {}) => {
8
- const slugger = new GithubSlugger();
9
- return (tree) => {
10
- slugger.reset();
11
- visit(tree, "element", function visitor(node, index, parent) {
12
- if (!parent || index === null || !node.tagName.startsWith("h"))
13
- return;
14
- const id = (prefix ?? "") + slugger.slug(hastToString(node));
15
- node.properties.id = id;
16
- });
17
- return tree;
18
- };
7
+ * A rehype plugin that adds IDs to heading tags.
8
+ */
9
+ const headingIdPlugin = ({ prefix } = {}) => {
10
+ const slugger = new GithubSlugger();
11
+ return (tree) => {
12
+ slugger.reset();
13
+ visit(tree, "element", function visitor(node, index, parent) {
14
+ if (!parent || index === null || !node.tagName.startsWith("h")) return;
15
+ const id = (prefix ?? "") + slugger.slug(toString(node));
16
+ node.properties.id = id;
17
+ });
18
+ return tree;
19
+ };
19
20
  };
21
+
22
+ //#endregion
23
+ export { headingIdPlugin };
24
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","names":["headingIdPlugin: Plugin<\n [HeadingIdPluginOptions?],\n HastNode,\n HastNode\n>","hastToString"],"sources":["../../../src/plugins/heading-id/plugin.ts"],"sourcesContent":["import GithubSlugger from \"github-slugger\";\nimport { toString as hastToString } from \"hast-util-to-string\";\nimport { visit } from \"unist-util-visit\";\nimport type { Plugin } from \"unified\";\n\nimport type { HastElement, HastNode } from \"../../types\";\n\n/**\n * Options for {@linkcode headingIdPlugin}.\n */\nexport interface HeadingIdPluginOptions {\n /** Prefix for title slugs. */\n prefix?: string;\n}\n\n/**\n * A rehype plugin that adds IDs to heading tags.\n */\nexport const headingIdPlugin: Plugin<\n [HeadingIdPluginOptions?],\n HastNode,\n HastNode\n> = ({ prefix } = {}) => {\n const slugger = new GithubSlugger();\n return (tree) => {\n slugger.reset();\n visit(\n tree,\n \"element\",\n function visitor(\n node: HastElement,\n index: number,\n parent: HastElement,\n ): void {\n if (!parent || index === null || !node.tagName.startsWith(\"h\")) return;\n const id = (prefix ?? \"\") + slugger.slug(hastToString(node));\n node.properties.id = id;\n },\n );\n return tree;\n };\n};\n"],"mappings":";;;;;;;;AAkBA,MAAaA,mBAIR,EAAE,WAAW,EAAE,KAAK;CACvB,MAAM,UAAU,IAAI,eAAe;AACnC,SAAQ,SAAS;AACf,UAAQ,OAAO;AACf,QACE,MACA,WACA,SAAS,QACP,MACA,OACA,QACM;AACN,OAAI,CAAC,UAAU,UAAU,QAAQ,CAAC,KAAK,QAAQ,WAAW,IAAI,CAAE;GAChE,MAAM,MAAM,UAAU,MAAM,QAAQ,KAAKC,SAAa,KAAK,CAAC;AAC5D,QAAK,WAAW,KAAK;IAExB;AACD,SAAO"}
@@ -1,4 +1,5 @@
1
- export * from "./heading-id/plugin";
2
- export * from "./syntax-highlight/plugin";
3
- export * from "./tree-processor/plugin";
4
- export * from "./remove-imports-exports";
1
+ import { HeadingIdPluginOptions, headingIdPlugin } from "./heading-id/plugin.js";
2
+ import { SyntaxHighlightPluginOptions, syntaxHighlightPlugin } from "./syntax-highlight/plugin.js";
3
+ import { MdxTreeProcessor, treeProcessorPlugin } from "./tree-processor/plugin.js";
4
+ import { removeImportsExportsPlugin } from "./remove-imports-exports.js";
5
+ export { HeadingIdPluginOptions, MdxTreeProcessor, SyntaxHighlightPluginOptions, headingIdPlugin, removeImportsExportsPlugin, syntaxHighlightPlugin, treeProcessorPlugin };
@@ -1,4 +1,6 @@
1
- export * from "./heading-id/plugin";
2
- export * from "./syntax-highlight/plugin";
3
- export * from "./tree-processor/plugin";
4
- export * from "./remove-imports-exports";
1
+ import { headingIdPlugin } from "./heading-id/plugin.js";
2
+ import { syntaxHighlightPlugin } from "./syntax-highlight/plugin.js";
3
+ import { treeProcessorPlugin } from "./tree-processor/plugin.js";
4
+ import { removeImportsExportsPlugin } from "./remove-imports-exports.js";
5
+
6
+ export { headingIdPlugin, removeImportsExportsPlugin, syntaxHighlightPlugin, treeProcessorPlugin };
@@ -1,8 +1,12 @@
1
- import type { Plugin } from "unified";
2
- import type { HastNode } from "../types";
1
+ import { HastNode as Node } from "../types.js";
2
+ import { Plugin } from "unified";
3
+
4
+ //#region src/plugins/remove-imports-exports.d.ts
5
+
3
6
  /**
4
7
  * A remark plugin which removes all import and export statements.
5
8
  */
6
- export declare const removeImportsExportsPlugin: Plugin<[
7
- unknown
8
- ], HastNode, HastNode>;
9
+ declare const removeImportsExportsPlugin: Plugin<[unknown], Node, Node>;
10
+ //#endregion
11
+ export { removeImportsExportsPlugin };
12
+ //# sourceMappingURL=remove-imports-exports.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remove-imports-exports.d.ts","names":[],"sources":["../../src/plugins/remove-imports-exports.ts"],"sourcesContent":[],"mappings":";;;;;;;AAQA;AAEE,cAFW,0BAEX,EAFuC,MAEvC,CAAA,CACA,OAAA,CAHuC,EAEvC,IAFuC,EAGvC,IAHuC,CAAA"}
@@ -1,10 +1,16 @@
1
1
  import { remove } from "unist-util-remove";
2
+
3
+ //#region src/plugins/remove-imports-exports.ts
2
4
  /**
3
- * A remark plugin which removes all import and export statements.
4
- */
5
- export const removeImportsExportsPlugin = () => {
6
- return (tree) => {
7
- remove(tree, "mdxjsEsm");
8
- return tree;
9
- };
5
+ * A remark plugin which removes all import and export statements.
6
+ */
7
+ const removeImportsExportsPlugin = () => {
8
+ return (tree) => {
9
+ remove(tree, "mdxjsEsm");
10
+ return tree;
11
+ };
10
12
  };
13
+
14
+ //#endregion
15
+ export { removeImportsExportsPlugin };
16
+ //# sourceMappingURL=remove-imports-exports.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remove-imports-exports.js","names":["removeImportsExportsPlugin: Plugin<\n [unknown],\n HastNode,\n HastNode\n>"],"sources":["../../src/plugins/remove-imports-exports.ts"],"sourcesContent":["import { remove } from \"unist-util-remove\";\nimport type { Plugin } from \"unified\";\n\nimport type { HastNode } from \"../types\";\n\n/**\n * A remark plugin which removes all import and export statements.\n */\nexport const removeImportsExportsPlugin: Plugin<\n [unknown],\n HastNode,\n HastNode\n> = () => {\n return (tree: HastNode) => {\n remove(tree, \"mdxjsEsm\");\n return tree;\n };\n};\n"],"mappings":";;;;;;AAQA,MAAaA,mCAIH;AACR,SAAQ,SAAmB;AACzB,SAAO,MAAM,WAAW;AACxB,SAAO"}
@@ -1,18 +1,23 @@
1
- import { type NumericRange } from "@temelj/iterator";
2
- import type { HastElement } from "../../types";
3
- export interface MdxCodeMeta {
4
- highlight?: MdxCodeMetaHighlightLine;
5
- showLineNumbers?: MdxCodeMetaLineNumbers;
6
- commandLine?: MdxCodeMetaCommandLine;
7
- fileName?: string;
1
+ import { HastElement as Element } from "../../types.js";
2
+ import { NumericRange } from "@temelj/iterator";
3
+
4
+ //#region src/plugins/syntax-highlight/code-meta.d.ts
5
+ interface MdxCodeMeta {
6
+ highlight?: MdxCodeMetaHighlightLine;
7
+ showLineNumbers?: MdxCodeMetaLineNumbers;
8
+ commandLine?: MdxCodeMetaCommandLine;
9
+ fileName?: string;
8
10
  }
9
- export type MdxCodeMetaHighlightLine = {
10
- lineRange: NumericRange;
11
+ type MdxCodeMetaHighlightLine = {
12
+ lineRange: NumericRange;
11
13
  };
12
- export type MdxCodeMetaLineNumbers = {
13
- lineRange: NumericRange;
14
+ type MdxCodeMetaLineNumbers = {
15
+ lineRange: NumericRange;
14
16
  };
15
- export type MdxCodeMetaCommandLine = {
16
- commandRange: NumericRange;
17
+ type MdxCodeMetaCommandLine = {
18
+ commandRange: NumericRange;
17
19
  };
18
- export declare function extractCodeMeta(node: HastElement): MdxCodeMeta;
20
+ declare function extractCodeMeta(node: Element): MdxCodeMeta;
21
+ //#endregion
22
+ export { MdxCodeMeta, MdxCodeMetaCommandLine, MdxCodeMetaHighlightLine, MdxCodeMetaLineNumbers, extractCodeMeta };
23
+ //# sourceMappingURL=code-meta.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"code-meta.d.ts","names":[],"sources":["../../../src/plugins/syntax-highlight/code-meta.ts"],"sourcesContent":[],"mappings":";;;;UAKiB,WAAA;cACH;EADG,eAAW,CAAA,EAER,sBAFQ;EACd,WAAA,CAAA,EAEE,sBAFF;EACM,QAAA,CAAA,EAAA,MAAA;;AACkB,KAI1B,wBAAA,GAJ0B;EAI1B,SAAA,EACC,YADD;AAIZ,CAAA;AAIY,KAJA,sBAAA,GAIsB;EAIlB,SAAA,EAPH,YAOkB;;KAJnB,sBAAA;gBACI;;iBAGA,eAAA,OAAsB,UAAc"}
@@ -1,50 +1,38 @@
1
1
  import { parseNumericRange } from "@temelj/iterator";
2
2
  import { z } from "zod";
3
- export function extractCodeMeta(node) {
4
- const meta = node?.data?.meta ?? node?.properties?.metastring ?? "";
5
- return parseMetaString(meta);
3
+
4
+ //#region src/plugins/syntax-highlight/code-meta.ts
5
+ function extractCodeMeta(node) {
6
+ return parseMetaString(node?.data?.meta ?? node?.properties?.metastring ?? "");
6
7
  }
7
8
  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()),
9
+ highlight: z.optional(z.string()),
10
+ showLineNumbers: z.optional(z.union([z.boolean(), z.string()])),
11
+ commandLine: z.optional(z.union([z.boolean(), z.string()])),
12
+ fileName: z.optional(z.string())
12
13
  });
13
14
  function parseMetaString(meta) {
14
- let raw;
15
- try {
16
- raw = JSON.parse(meta.trim());
17
- }
18
- catch {
19
- return {};
20
- }
21
- const parsed = metaSchema.parse(raw);
22
- const options = {};
23
- if (parsed.highlight !== undefined) {
24
- options.highlight = { lineRange: parseNumericRange(parsed.highlight) };
25
- }
26
- if (parsed.showLineNumbers !== undefined) {
27
- if (typeof parsed.showLineNumbers === "string") {
28
- options.showLineNumbers = {
29
- lineRange: parseNumericRange(parsed.showLineNumbers),
30
- };
31
- }
32
- else if (parsed.showLineNumbers) {
33
- options.showLineNumbers = { lineRange: [] };
34
- }
35
- }
36
- if (parsed.commandLine !== undefined) {
37
- if (typeof parsed.commandLine === "string") {
38
- options.commandLine = {
39
- commandRange: parseNumericRange(parsed.commandLine),
40
- };
41
- }
42
- else if (parsed.commandLine) {
43
- options.commandLine = { commandRange: [] };
44
- }
45
- }
46
- if (parsed.fileName !== undefined) {
47
- options.fileName = parsed.fileName.trim();
48
- }
49
- return options;
15
+ let raw;
16
+ try {
17
+ raw = JSON.parse(meta.trim());
18
+ } catch {
19
+ return {};
20
+ }
21
+ const parsed = metaSchema.parse(raw);
22
+ const options = {};
23
+ if (parsed.highlight !== void 0) options.highlight = { lineRange: parseNumericRange(parsed.highlight) };
24
+ if (parsed.showLineNumbers !== void 0) {
25
+ if (typeof parsed.showLineNumbers === "string") options.showLineNumbers = { lineRange: parseNumericRange(parsed.showLineNumbers) };
26
+ else if (parsed.showLineNumbers) options.showLineNumbers = { lineRange: [] };
27
+ }
28
+ if (parsed.commandLine !== void 0) {
29
+ if (typeof parsed.commandLine === "string") options.commandLine = { commandRange: parseNumericRange(parsed.commandLine) };
30
+ else if (parsed.commandLine) options.commandLine = { commandRange: [] };
31
+ }
32
+ if (parsed.fileName !== void 0) options.fileName = parsed.fileName.trim();
33
+ return options;
50
34
  }
35
+
36
+ //#endregion
37
+ export { extractCodeMeta };
38
+ //# sourceMappingURL=code-meta.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"code-meta.js","names":["raw: unknown","options: MdxCodeMeta"],"sources":["../../../src/plugins/syntax-highlight/code-meta.ts"],"sourcesContent":["import { type NumericRange, parseNumericRange } from \"@temelj/iterator\";\nimport { z } from \"zod\";\n\nimport type { HastElement } from \"../../types\";\n\nexport interface MdxCodeMeta {\n highlight?: MdxCodeMetaHighlightLine;\n showLineNumbers?: MdxCodeMetaLineNumbers;\n commandLine?: MdxCodeMetaCommandLine;\n fileName?: string;\n}\n\nexport type MdxCodeMetaHighlightLine = {\n lineRange: NumericRange;\n};\n\nexport type MdxCodeMetaLineNumbers = {\n lineRange: NumericRange;\n};\n\nexport type MdxCodeMetaCommandLine = {\n commandRange: NumericRange;\n};\n\nexport function extractCodeMeta(node: HastElement): MdxCodeMeta {\n const meta = node?.data?.meta ?? node?.properties?.metastring ?? \"\";\n return parseMetaString(meta as string);\n}\n\nconst metaSchema = z.object({\n highlight: z.optional(z.string()),\n showLineNumbers: z.optional(z.union([z.boolean(), z.string()])),\n commandLine: z.optional(z.union([z.boolean(), z.string()])),\n fileName: z.optional(z.string()),\n});\n\nfunction parseMetaString(meta: string): MdxCodeMeta {\n let raw: unknown;\n try {\n raw = JSON.parse(meta.trim());\n } catch {\n return {};\n }\n const parsed = metaSchema.parse(raw);\n const options: MdxCodeMeta = {};\n\n if (parsed.highlight !== undefined) {\n options.highlight = { lineRange: parseNumericRange(parsed.highlight) };\n }\n\n if (parsed.showLineNumbers !== undefined) {\n if (typeof parsed.showLineNumbers === \"string\") {\n options.showLineNumbers = {\n lineRange: parseNumericRange(parsed.showLineNumbers),\n };\n } else if (parsed.showLineNumbers) {\n options.showLineNumbers = { lineRange: [] };\n }\n }\n\n if (parsed.commandLine !== undefined) {\n if (typeof parsed.commandLine === \"string\") {\n options.commandLine = {\n commandRange: parseNumericRange(parsed.commandLine),\n };\n } else if (parsed.commandLine) {\n options.commandLine = { commandRange: [] };\n }\n }\n\n if (parsed.fileName !== undefined) {\n options.fileName = parsed.fileName.trim();\n }\n\n return options;\n}\n"],"mappings":";;;;AAwBA,SAAgB,gBAAgB,MAAgC;AAE9D,QAAO,gBADM,MAAM,MAAM,QAAQ,MAAM,YAAY,cAAc,GAC3B;;AAGxC,MAAM,aAAa,EAAE,OAAO;CAC1B,WAAW,EAAE,SAAS,EAAE,QAAQ,CAAC;CACjC,iBAAiB,EAAE,SAAS,EAAE,MAAM,CAAC,EAAE,SAAS,EAAE,EAAE,QAAQ,CAAC,CAAC,CAAC;CAC/D,aAAa,EAAE,SAAS,EAAE,MAAM,CAAC,EAAE,SAAS,EAAE,EAAE,QAAQ,CAAC,CAAC,CAAC;CAC3D,UAAU,EAAE,SAAS,EAAE,QAAQ,CAAC;CACjC,CAAC;AAEF,SAAS,gBAAgB,MAA2B;CAClD,IAAIA;AACJ,KAAI;AACF,QAAM,KAAK,MAAM,KAAK,MAAM,CAAC;SACvB;AACN,SAAO,EAAE;;CAEX,MAAM,SAAS,WAAW,MAAM,IAAI;CACpC,MAAMC,UAAuB,EAAE;AAE/B,KAAI,OAAO,cAAc,OACvB,SAAQ,YAAY,EAAE,WAAW,kBAAkB,OAAO,UAAU,EAAE;AAGxE,KAAI,OAAO,oBAAoB,QAC7B;MAAI,OAAO,OAAO,oBAAoB,SACpC,SAAQ,kBAAkB,EACxB,WAAW,kBAAkB,OAAO,gBAAgB,EACrD;WACQ,OAAO,gBAChB,SAAQ,kBAAkB,EAAE,WAAW,EAAE,EAAE;;AAI/C,KAAI,OAAO,gBAAgB,QACzB;MAAI,OAAO,OAAO,gBAAgB,SAChC,SAAQ,cAAc,EACpB,cAAc,kBAAkB,OAAO,YAAY,EACpD;WACQ,OAAO,YAChB,SAAQ,cAAc,EAAE,cAAc,EAAE,EAAE;;AAI9C,KAAI,OAAO,aAAa,OACtB,SAAQ,WAAW,OAAO,SAAS,MAAM;AAG3C,QAAO"}