@temelj/mdx 0.1.5

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) 2024 Flinect
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,41 @@
1
+ <p align="center">
2
+ <h1 align="center" style="text-decoration:none;">@temelj/mdx</h1>
3
+ <br/>
4
+ <p align="center">
5
+ Utilities for working with MDX.
6
+ </p>
7
+ </p>
8
+
9
+ <p align="center">
10
+ <a href="https://twitter.com/tinrab" rel="nofollow"><img src="https://img.shields.io/badge/created%20by-@tinrab-1d9bf0.svg" alt="Created by Tin Rabzelj"></a>
11
+ <a href="https://jsr.io/@temelj/mdx" rel="nofollow"><img src="https://jsr.io/badges/@temelj/mdx" alt="jsr"></a>
12
+ <a href="https://opensource.org/licenses/MIT" rel="nofollow"><img src="https://img.shields.io/github/license/flinect/temelj" alt="License"></a>
13
+ </p>
14
+
15
+ <div align="center">
16
+ <a href="https://jsr.io/@temelj/mdx">jsr</a>
17
+ <span>&nbsp;&nbsp;•&nbsp;&nbsp;</span>
18
+ <a href="https://www.npmjs.com/package/@temelj/mdx">npm</a>
19
+ <span>&nbsp;&nbsp;•&nbsp;&nbsp;</span>
20
+ <a href="https://github.com/flinect/temelj/issues/new">Issues</a>
21
+ <span>&nbsp;&nbsp;•&nbsp;&nbsp;</span>
22
+ <a href="https://twitter.com/tinrab">@tinrab</a>
23
+ <br />
24
+ </div>
25
+
26
+ <br/>
27
+ <br/>
28
+
29
+ # Installation
30
+
31
+ ```sh
32
+ # npm
33
+ $ npm install @temelj/mdx
34
+ # jsr
35
+ $ deno add jsr:@temelj/mdx # or jsr add @temelj/mdx
36
+ ```
37
+
38
+ # About
39
+
40
+ This package is part of [Temelj](https://github.com/flinect/temelj) - a big
41
+ standard library for TypeScript.
@@ -0,0 +1,71 @@
1
+ import { compile as compileMdxJs, } from "@mdx-js/mdx";
2
+ import remarkFrontmatterPlugin from "remark-frontmatter";
3
+ import remarkGfmPlugin from "remark-gfm";
4
+ import { VFile } from "vfile";
5
+ import { matter } from "vfile-matter";
6
+ export { remarkFrontmatterPlugin, remarkGfmPlugin };
7
+ export class MdxCompiler {
8
+ constructor(mdxOptions = {}) {
9
+ Object.defineProperty(this, "mdxOptions", {
10
+ enumerable: true,
11
+ configurable: true,
12
+ writable: true,
13
+ value: void 0
14
+ });
15
+ Object.defineProperty(this, "remarkPlugins", {
16
+ enumerable: true,
17
+ configurable: true,
18
+ writable: true,
19
+ value: void 0
20
+ });
21
+ Object.defineProperty(this, "rehypePlugins", {
22
+ enumerable: true,
23
+ configurable: true,
24
+ writable: true,
25
+ value: void 0
26
+ });
27
+ this.mdxOptions = mdxOptions;
28
+ this.remarkPlugins = [remarkFrontmatterPlugin, remarkGfmPlugin];
29
+ this.rehypePlugins = [];
30
+ }
31
+ withRemarkPlugin(plugin, options) {
32
+ if (options === undefined) {
33
+ this.remarkPlugins.push(plugin);
34
+ }
35
+ else {
36
+ this.remarkPlugins.push([plugin, options]);
37
+ }
38
+ return this;
39
+ }
40
+ withRehypePlugin(plugin, options) {
41
+ if (options === undefined) {
42
+ this.rehypePlugins.push(plugin);
43
+ }
44
+ else {
45
+ this.rehypePlugins.push([plugin, options]);
46
+ }
47
+ return this;
48
+ }
49
+ async compile(source, { frontmatterOnly = false, mdxOptions } = {}) {
50
+ const vfile = new VFile({
51
+ value: source,
52
+ // Needed so vfile doesn't access fs
53
+ cwd: "/",
54
+ path: "/",
55
+ message: {},
56
+ messages: {},
57
+ });
58
+ matter(vfile, { strip: true });
59
+ let compiled;
60
+ if (!frontmatterOnly) {
61
+ compiled = await compileMdxJs(vfile, {
62
+ remarkPlugins: this.remarkPlugins,
63
+ rehypePlugins: this.rehypePlugins,
64
+ outputFormat: "function-body",
65
+ ...(this.mdxOptions ?? {}),
66
+ ...(mdxOptions ?? {}),
67
+ });
68
+ }
69
+ return { compiled, frontmatter: (vfile.data.matter ?? {}) };
70
+ }
71
+ }
package/esm/mod.js ADDED
@@ -0,0 +1,3 @@
1
+ export * from "./plugins/mod.js";
2
+ export * from "./types.js";
3
+ export * from "./compiler.js";
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
@@ -0,0 +1,21 @@
1
+ import GithubSlugger from "github-slugger";
2
+ import { toString as hastToString } from "hast-util-to-string";
3
+ import { visit } from "unist-util-visit";
4
+ /**
5
+ * A rehype plugin that adds IDs to heading tags.
6
+ */
7
+ export function headingIdPlugin({ prefix, } = {}) {
8
+ const slugger = new GithubSlugger();
9
+ return (tree) => {
10
+ slugger.reset();
11
+ visit(tree, "element", visitor);
12
+ function visitor(node, index, parent) {
13
+ if (!parent || index === null || !node.tagName.startsWith("h")) {
14
+ return;
15
+ }
16
+ const id = (prefix ?? "") + slugger.slug(hastToString(node));
17
+ node.properties.id = id;
18
+ }
19
+ return tree;
20
+ };
21
+ }
@@ -0,0 +1,4 @@
1
+ export * from "./heading-id/plugin.js";
2
+ export * from "./syntax-highlight/plugin.js";
3
+ export * from "./tree-processor/plugin.js";
4
+ export * from "./remove-imports-exports.js";
@@ -0,0 +1,10 @@
1
+ import { remove } from "unist-util-remove";
2
+ /**
3
+ * A remark plugin which removes all import and export statements.
4
+ */
5
+ export function removeImportsExportsPlugin() {
6
+ return (tree) => {
7
+ remove(tree, "mdxjsEsm");
8
+ return tree;
9
+ };
10
+ }
@@ -0,0 +1,50 @@
1
+ import { z } from "zod";
2
+ import { parseNumericRange } from "@temelj/iterator";
3
+ export function extractCodeMeta(node) {
4
+ const meta = node?.data?.meta ?? node?.properties?.metastring ?? "";
5
+ return parseMetaString(meta);
6
+ }
7
+ const metaSchema = z.object({
8
+ highlight: z.string().optional(),
9
+ showLineNumbers: z.boolean().default(false),
10
+ commandLine: z.string().optional(),
11
+ fileName: z.string().optional(),
12
+ });
13
+ 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 (typeof parsed.fileName === "string") {
47
+ options.fileName = parsed.fileName.trim();
48
+ }
49
+ return options;
50
+ }
@@ -0,0 +1,106 @@
1
+ import { toString as hastToString } from "hast-util-to-string";
2
+ import { codeToHast, } from "shiki";
3
+ import { visit } from "unist-util-visit";
4
+ import { transformerNotationHighlight, } from "@shikijs/transformers";
5
+ import { numericRangeContains } from "@temelj/iterator";
6
+ import { extractCodeMeta } from "./code-meta.js";
7
+ export function syntaxHighlightPlugin(options = {}) {
8
+ return async (tree) => {
9
+ const promises = [];
10
+ async function visitor(node, index, parent) {
11
+ if (!parent || index === null || node.tagName !== "pre") {
12
+ return;
13
+ }
14
+ const codeNode = node.children[0];
15
+ if (!codeNode ||
16
+ codeNode.type !== "element" ||
17
+ codeNode.tagName !== "code" ||
18
+ !codeNode.properties) {
19
+ return;
20
+ }
21
+ const lang = getNodeLanguage(codeNode);
22
+ if (typeof lang !== "string") {
23
+ return;
24
+ }
25
+ const meta = extractCodeMeta(codeNode);
26
+ const sourceCode = hastToString(codeNode).trim();
27
+ const hastOptions = {
28
+ tokenizeTimeLimit: 10_000,
29
+ lang,
30
+ themes: {
31
+ light: "github-light-default",
32
+ dark: "github-dark-default",
33
+ },
34
+ ...(options.shikiCodeToHastOptions ?? {}),
35
+ };
36
+ if (hastOptions.transformers === undefined) {
37
+ hastOptions.transformers = [];
38
+ }
39
+ if (options.highlight) {
40
+ hastOptions.transformers.push(transformerNotationHighlight(options.highlight.transformer));
41
+ }
42
+ hastOptions.transformers.push({
43
+ code(node) {
44
+ if (options.languageClassNamePrefix) {
45
+ this.addClassToHast(node, `${options.languageClassNamePrefix}${lang}`);
46
+ }
47
+ let lineNumber = 1;
48
+ for (const line of node.children.filter((node) => node.type === "element")) {
49
+ line.properties["data-line"] = lineNumber;
50
+ if (options.highlight) {
51
+ if (meta.highlight &&
52
+ numericRangeContains(meta.highlight.lineRange, lineNumber)) {
53
+ this.addClassToHast(line, options.highlight.transformer?.classActiveLine ??
54
+ "highlighted");
55
+ }
56
+ }
57
+ if (options.lineNumbers &&
58
+ meta.showLineNumbers &&
59
+ (meta.showLineNumbers.lineRange.length === 0 ||
60
+ numericRangeContains(meta.showLineNumbers.lineRange, lineNumber))) {
61
+ this.addClassToHast(line, options.lineNumbers.className ?? "line-number");
62
+ }
63
+ if (options.commandLine &&
64
+ meta.commandLine &&
65
+ numericRangeContains(meta.commandLine.commandRange, lineNumber)) {
66
+ this.addClassToHast(line, options.commandLine.className ?? "line-command");
67
+ }
68
+ lineNumber++;
69
+ }
70
+ if (meta.showLineNumbers) {
71
+ if (typeof node.properties.style !== "string") {
72
+ node.properties.style = "";
73
+ }
74
+ node.properties.style += `--${options.lineNumbers?.widthVariableName ?? "line-number-width"}:${1 + Math.floor(Math.log10(this.lines.length))}ch;`;
75
+ }
76
+ },
77
+ });
78
+ const hast = await codeToHast(sourceCode, hastOptions);
79
+ // Insert highlighted code into parent
80
+ const hastPre = hast.children[0];
81
+ parent.children.splice(index, 1, {
82
+ ...hastPre,
83
+ properties: {
84
+ ...hastPre.properties,
85
+ dataFileName: meta.fileName,
86
+ },
87
+ });
88
+ }
89
+ visit(tree, "element", (node, index, parent) => {
90
+ promises.push(visitor(node, index, parent));
91
+ });
92
+ await Promise.all(promises);
93
+ return tree;
94
+ };
95
+ }
96
+ function getNodeLanguage(node) {
97
+ if (!Array.isArray(node.properties.className)) {
98
+ return undefined;
99
+ }
100
+ const prefix = "language-";
101
+ const language = node.properties.className.find((name) => typeof name === "string" && name.startsWith(prefix));
102
+ if (typeof language === "string") {
103
+ return language.slice(prefix.length);
104
+ }
105
+ return language;
106
+ }
@@ -0,0 +1,16 @@
1
+ import { visit } from "unist-util-visit";
2
+ export function treeProcessorPlugin({ process } = { process: () => { } }) {
3
+ return async (tree) => {
4
+ const promises = [];
5
+ function visitElement(node, index, parent) {
6
+ const p = process(node, index, parent);
7
+ if (p instanceof Promise ||
8
+ Object.prototype.toString.call(p) === "[object Promise]") {
9
+ promises.push(p);
10
+ }
11
+ }
12
+ visit(tree, "element", visitElement);
13
+ await Promise.allSettled(promises);
14
+ return tree;
15
+ };
16
+ }
package/esm/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@temelj/mdx",
3
+ "version": "0.1.5",
4
+ "description": "Utilities for working with MDX.",
5
+ "keywords": [
6
+ "mdx"
7
+ ],
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/flinect/temelj.git"
11
+ },
12
+ "license": "MIT",
13
+ "bugs": {
14
+ "url": "https://github.com/flinect/temelj/issues"
15
+ },
16
+ "module": "./esm/mod.js",
17
+ "types": "./types/mod.d.ts",
18
+ "exports": {
19
+ ".": {
20
+ "import": {
21
+ "types": "./types/mod.d.ts",
22
+ "default": "./esm/mod.js"
23
+ }
24
+ }
25
+ },
26
+ "dependencies": {
27
+ "@mdx-js/mdx": "^3.1.0",
28
+ "@shikijs/transformers": "^1.23.1",
29
+ "github-slugger": "^2.0.0",
30
+ "hast": "^1.0.0",
31
+ "hast-util-to-string": "^3.0.1",
32
+ "remark-frontmatter": "^5.0.0",
33
+ "remark-gfm": "^4.0.0",
34
+ "shiki": "^1.23.1",
35
+ "unified": "^11.0.5",
36
+ "unist-util-remove": "^4.0.0",
37
+ "unist-util-visit": "^5.0.0",
38
+ "vfile": "^6.0.3",
39
+ "vfile-matter": "^5.0.0",
40
+ "zod": "^3.23.8",
41
+ "@temelj/iterator": "^0.2.0",
42
+ "@types/hast": "^3.0.4"
43
+ },
44
+ "devDependencies": {
45
+ "@types/node": "^20.9.0"
46
+ },
47
+ "_generatedBy": "dnt@dev"
48
+ }
@@ -0,0 +1,25 @@
1
+ import { type CompileOptions as MdxJsCompileOptions } from "@mdx-js/mdx";
2
+ import remarkFrontmatterPlugin from "remark-frontmatter";
3
+ import remarkGfmPlugin from "remark-gfm";
4
+ import { VFile } from "vfile";
5
+ import type { PluginFactory } from "./types.js";
6
+ export { remarkFrontmatterPlugin, remarkGfmPlugin };
7
+ export type MdxSource = string | Uint8Array;
8
+ export interface MdxCompileOptions {
9
+ frontmatterOnly?: boolean | undefined;
10
+ mdxOptions?: MdxJsCompileOptions;
11
+ }
12
+ export interface MdxArtifact<TFrontmatter = Record<string, unknown>> {
13
+ compiled?: VFile | undefined;
14
+ frontmatter: TFrontmatter;
15
+ }
16
+ export declare class MdxCompiler {
17
+ private readonly mdxOptions;
18
+ private readonly remarkPlugins;
19
+ private readonly rehypePlugins;
20
+ constructor(mdxOptions?: MdxCompileOptions);
21
+ withRemarkPlugin<TOptions>(plugin: (options?: TOptions) => PluginFactory, options?: TOptions): MdxCompiler;
22
+ withRehypePlugin<TOptions>(plugin: (options?: TOptions) => PluginFactory, options?: TOptions): MdxCompiler;
23
+ compile<TFrontmatter = Record<string, unknown>>(source: MdxSource, { frontmatterOnly, mdxOptions }?: MdxCompileOptions): Promise<MdxArtifact<TFrontmatter>>;
24
+ }
25
+ //# sourceMappingURL=compiler.d.ts.map
@@ -0,0 +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;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAI9B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD,OAAO,EAAE,uBAAuB,EAAE,eAAe,EAAE,CAAC;AAEpD,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,UAAU,CAAC;AAE5C,MAAM,WAAW,iBAAiB;IAChC,eAAe,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IACtC,UAAU,CAAC,EAAE,mBAAmB,CAAC;CAClC;AAED,MAAM,WAAW,WAAW,CAAC,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IACjE,QAAQ,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC;IAC7B,WAAW,EAAE,YAAY,CAAC;CAC3B;AAED,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAoB;IAC/C,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAgB;IAC9C,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAgB;gBAG5C,UAAU,GAAE,iBAAsB;IAO7B,gBAAgB,CAAC,QAAQ,EAC9B,MAAM,EAAE,CAAC,OAAO,CAAC,EAAE,QAAQ,KAAK,aAAa,EAC7C,OAAO,CAAC,EAAE,QAAQ,GACjB,WAAW;IASP,gBAAgB,CAAC,QAAQ,EAC9B,MAAM,EAAE,CAAC,OAAO,CAAC,EAAE,QAAQ,KAAK,aAAa,EAC7C,OAAO,CAAC,EAAE,QAAQ,GACjB,WAAW;IASD,OAAO,CAAC,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACzD,MAAM,EAAE,SAAS,EACjB,EAAE,eAAuB,EAAE,UAAU,EAAE,GAAE,iBAAsB,GAC9D,OAAO,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC;CAwBtC"}
package/types/mod.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export * from "./plugins/mod.js";
2
+ export * from "./types.js";
3
+ export * from "./compiler.js";
4
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC;AAC3B,cAAc,eAAe,CAAC"}
@@ -0,0 +1,13 @@
1
+ import type { PluginFactory } from "../../types.js";
2
+ /**
3
+ * Options for {@linkcode headingIdPlugin}.
4
+ */
5
+ export interface HeadingIdPluginOptions {
6
+ /** Prefix for title slugs. */
7
+ prefix?: string;
8
+ }
9
+ /**
10
+ * A rehype plugin that adds IDs to heading tags.
11
+ */
12
+ export declare function headingIdPlugin({ prefix, }?: HeadingIdPluginOptions): PluginFactory;
13
+ //# sourceMappingURL=plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../src/plugins/heading-id/plugin.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAyB,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE3E;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,8BAA8B;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,EAC9B,MAAM,GACP,GAAE,sBAA2B,GAAG,aAAa,CAuB7C"}
@@ -0,0 +1,5 @@
1
+ export * from "./heading-id/plugin.js";
2
+ export * from "./syntax-highlight/plugin.js";
3
+ export * from "./tree-processor/plugin.js";
4
+ export * from "./remove-imports-exports.js";
5
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/plugins/mod.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC"}
@@ -0,0 +1,6 @@
1
+ import type { PluginFactory } from "../types.js";
2
+ /**
3
+ * A remark plugin which removes all import and export statements.
4
+ */
5
+ export declare function removeImportsExportsPlugin(): PluginFactory;
6
+ //# sourceMappingURL=remove-imports-exports.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"remove-imports-exports.d.ts","sourceRoot":"","sources":["../../src/plugins/remove-imports-exports.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAY,aAAa,EAAE,MAAM,aAAa,CAAC;AAE3D;;GAEG;AACH,wBAAgB,0BAA0B,IAAI,aAAa,CAK1D"}
@@ -0,0 +1,19 @@
1
+ import { type NumericRange } from "@temelj/iterator";
2
+ import type { HastElement } from "../../types.js";
3
+ export interface MdxCodeMeta {
4
+ highlight?: MdxCodeMetaHighlightLine;
5
+ showLineNumbers?: MdxCodeMetaLineNumbers;
6
+ commandLine?: MdxCodeMetaCommandLine;
7
+ fileName?: string;
8
+ }
9
+ export type MdxCodeMetaHighlightLine = {
10
+ lineRange: NumericRange;
11
+ };
12
+ export type MdxCodeMetaLineNumbers = {
13
+ lineRange: NumericRange;
14
+ };
15
+ export type MdxCodeMetaCommandLine = {
16
+ commandRange: NumericRange;
17
+ };
18
+ export declare function extractCodeMeta(node: HastElement): MdxCodeMeta;
19
+ //# sourceMappingURL=code-meta.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"code-meta.d.ts","sourceRoot":"","sources":["../../../src/plugins/syntax-highlight/code-meta.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,YAAY,EAAqB,MAAM,kBAAkB,CAAC;AAExE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAElD,MAAM,WAAW,WAAW;IAC1B,SAAS,CAAC,EAAE,wBAAwB,CAAC;IACrC,eAAe,CAAC,EAAE,sBAAsB,CAAC;IACzC,WAAW,CAAC,EAAE,sBAAsB,CAAC;IACrC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,MAAM,wBAAwB,GAAG;IACrC,SAAS,EAAE,YAAY,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACnC,SAAS,EAAE,YAAY,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACnC,YAAY,EAAE,YAAY,CAAC;CAC5B,CAAC;AAEF,wBAAgB,eAAe,CAAC,IAAI,EAAE,WAAW,GAAG,WAAW,CAG9D"}
@@ -0,0 +1,24 @@
1
+ import { type BundledLanguage, type BundledTheme, type CodeToHastOptions } from "shiki";
2
+ import { type TransformerNotationHighlightOptions } from "@shikijs/transformers";
3
+ import type { PluginFactory } from "../../types.js";
4
+ type ShikiCodeToHastOptions = Partial<CodeToHastOptions<BundledLanguage, BundledTheme>>;
5
+ /**
6
+ * Options for {@linkcode syntaxHighlightPlugin}.
7
+ */
8
+ export interface SyntaxHighlightPluginOptions {
9
+ languageClassNamePrefix?: string;
10
+ highlight?: {
11
+ transformer?: TransformerNotationHighlightOptions;
12
+ };
13
+ lineNumbers?: {
14
+ widthVariableName?: string;
15
+ className?: string;
16
+ };
17
+ commandLine?: {
18
+ className?: string;
19
+ };
20
+ shikiCodeToHastOptions?: ShikiCodeToHastOptions;
21
+ }
22
+ export declare function syntaxHighlightPlugin(options?: SyntaxHighlightPluginOptions): PluginFactory;
23
+ export {};
24
+ //# sourceMappingURL=plugin.d.ts.map
@@ -0,0 +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,EACvB,MAAM,OAAO,CAAC;AAEf,OAAO,EAEL,KAAK,mCAAmC,EACzC,MAAM,uBAAuB,CAAC;AAG/B,OAAO,KAAK,EAAyB,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAG3E,KAAK,sBAAsB,GAAG,OAAO,CACnC,iBAAiB,CAAC,eAAe,EAAE,YAAY,CAAC,CACjD,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,4BAA4B;IAC3C,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,SAAS,CAAC,EAAE;QACV,WAAW,CAAC,EAAE,mCAAmC,CAAC;KACnD,CAAC;IACF,WAAW,CAAC,EAAE;QACZ,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,CAAC;IACF,WAAW,CAAC,EAAE;QACZ,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,CAAC;IACF,sBAAsB,CAAC,EAAE,sBAAsB,CAAC;CACjD;AAED,wBAAgB,qBAAqB,CACnC,OAAO,GAAE,4BAAiC,GACzC,aAAa,CAqJf"}
@@ -0,0 +1,12 @@
1
+ import type { HastElement, PluginFactory } from "../../types.js";
2
+ export type MdxTreeProcessor = (node: HastElement, index: number, parent: HastElement) => void | Promise<void>;
3
+ /**
4
+ * Options for {@linkcode treeProcessorPlugin}.
5
+ */
6
+ type TreeProcessorPluginOptions = {
7
+ /** The processor. */
8
+ process: MdxTreeProcessor;
9
+ };
10
+ export declare function treeProcessorPlugin({ process }?: TreeProcessorPluginOptions): PluginFactory;
11
+ export {};
12
+ //# sourceMappingURL=plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../../src/plugins/tree-processor/plugin.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAY,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE3E,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,wBAAgB,mBAAmB,CACjC,EAAE,OAAO,EAAE,GAAE,0BAAkD,GAC9D,aAAa,CAuBf"}
@@ -0,0 +1,7 @@
1
+ import type { Element, Node } from "hast";
2
+ import type { CompileResults, Processor } from "unified";
3
+ 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
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +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;AAC1C,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEzD,YAAY,EAAE,OAAO,IAAI,WAAW,EAAE,IAAI,IAAI,QAAQ,EAAE,CAAC;AAEzD,KAAK,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC;AAEvD,KAAK,MAAM,CACT,WAAW,SAAS,OAAO,EAAE,GAAG,EAAE,EAClC,MAAM,SAAS,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,IAAI,EAC/C,OAAO,GAAG,MAAM,IACd,CACF,IAAI,EAAE,SAAS,EACf,GAAG,UAAU,EAAE,WAAW,KACvB,YAAY,CACf,MAAM,SAAS,MAAM,GAAG,OAAO,SAAS,IAAI,GAAG,SAAS,GAAG,SAAS,GAAG,IAAI,GACvE,KAAK,GACL,OAAO,SAAS,cAAc,GAC5B,MAAM,SAAS,IAAI,GAAG,SAAS,GAAG,SAAS,GAAG,IAAI,GAClD,KAAK,GAEL,WAAW,CACX,MAAM,SAAS,IAAI,GAAG,MAAM,GAAG,IAAI,EACnC,OAAO,SAAS,IAAI,GAAG,OAAO,GAAG,IAAI,CACtC,GACC,SAAS,GACT,IAAI,CACX,CAAC;AAEF,MAAM,MAAM,aAAa,CACvB,WAAW,SAAS,OAAO,EAAE,GAAG,EAAE,EAClC,MAAM,SAAS,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,IAAI,EAC/C,OAAO,GAAG,MAAM,IACd,CACF,UAAU,CAAC,EAAE,WAAW,KACrB,YAAY,CAAC,MAAM,CAAC,WAAW,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC"}