@temelj/mdx 0.1.7 → 0.1.9
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.
|
@@ -6,8 +6,8 @@ export function extractCodeMeta(node) {
|
|
|
6
6
|
}
|
|
7
7
|
const metaSchema = z.object({
|
|
8
8
|
highlight: z.string().optional(),
|
|
9
|
-
showLineNumbers: z.boolean().
|
|
10
|
-
commandLine: z.string().optional(),
|
|
9
|
+
showLineNumbers: z.boolean().or(z.string()).optional(),
|
|
10
|
+
commandLine: z.boolean().or(z.string()).optional(),
|
|
11
11
|
fileName: z.string().optional(),
|
|
12
12
|
});
|
|
13
13
|
function parseMetaString(meta) {
|
|
@@ -43,7 +43,7 @@ function parseMetaString(meta) {
|
|
|
43
43
|
options.commandLine = { commandRange: [] };
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
|
-
if (
|
|
46
|
+
if (parsed.fileName !== undefined) {
|
|
47
47
|
options.fileName = parsed.fileName.trim();
|
|
48
48
|
}
|
|
49
49
|
return options;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { toString as hastToString } from "hast-util-to-string";
|
|
2
|
-
import { codeToHast, } from "shiki";
|
|
2
|
+
import { codeToHast, ShikiError, } from "shiki";
|
|
3
3
|
import { visit } from "unist-util-visit";
|
|
4
4
|
import { transformerNotationHighlight, } from "@shikijs/transformers";
|
|
5
5
|
import { numericRangeContains } from "@temelj/iterator";
|
|
@@ -65,7 +65,8 @@ export function syntaxHighlightPlugin(options = {}) {
|
|
|
65
65
|
}
|
|
66
66
|
if (options.commandLine &&
|
|
67
67
|
meta.commandLine &&
|
|
68
|
-
|
|
68
|
+
(meta.commandLine.commandRange.length === 0 ||
|
|
69
|
+
numericRangeContains(meta.commandLine.commandRange, lineIndex))) {
|
|
69
70
|
this.addClassToHast(line, options.commandLine.className ?? "line-command");
|
|
70
71
|
}
|
|
71
72
|
lineIndex++;
|
|
@@ -78,16 +79,27 @@ export function syntaxHighlightPlugin(options = {}) {
|
|
|
78
79
|
}
|
|
79
80
|
},
|
|
80
81
|
});
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
82
|
+
try {
|
|
83
|
+
const hast = await codeToHast(sourceCode, hastOptions);
|
|
84
|
+
// Insert highlighted code into parent
|
|
85
|
+
const hastPre = hast.children[0];
|
|
86
|
+
parent.children.splice(index, 1, {
|
|
87
|
+
...hastPre,
|
|
88
|
+
properties: {
|
|
89
|
+
...hastPre.properties,
|
|
90
|
+
dataFileName: meta.fileName,
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
if (error instanceof ShikiError) {
|
|
96
|
+
if (error.message.includes("Language `math` is not included in this bundle")) {
|
|
97
|
+
// Skip if the block is math block.
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
throw error;
|
|
102
|
+
}
|
|
91
103
|
}
|
|
92
104
|
visit(tree, "element", (node, index, parent) => {
|
|
93
105
|
promises.push(visitor(node, index, parent));
|
package/package.json
CHANGED
package/types/compiler.d.ts
CHANGED
|
@@ -11,9 +11,9 @@ export type MdxSource = string | Uint8Array;
|
|
|
11
11
|
/**
|
|
12
12
|
* Options for compiling an MDX document.
|
|
13
13
|
*/
|
|
14
|
-
export interface MdxCompileOptions<TFrontmatter
|
|
14
|
+
export interface MdxCompileOptions<TFrontmatter extends z.ZodSchema> {
|
|
15
15
|
frontmatterOnly?: boolean | undefined;
|
|
16
|
-
frontmatterSchema?:
|
|
16
|
+
frontmatterSchema?: TFrontmatter;
|
|
17
17
|
mdxOptions?: MdxJsCompileOptions;
|
|
18
18
|
}
|
|
19
19
|
/**
|
|
@@ -34,6 +34,6 @@ export declare class MdxCompiler {
|
|
|
34
34
|
constructor(mdxOptions?: MdxJsCompileOptions);
|
|
35
35
|
withRemarkPlugin<TOptions>(plugin: (options?: TOptions) => PluginFactory, options?: TOptions): MdxCompiler;
|
|
36
36
|
withRehypePlugin<TOptions>(plugin: (options?: TOptions) => PluginFactory, options?: TOptions): MdxCompiler;
|
|
37
|
-
compile<
|
|
37
|
+
compile<TFrontmatterSchema extends z.ZodSchema>(source: MdxSource, { frontmatterOnly, frontmatterSchema, mdxOptions }?: MdxCompileOptions<TFrontmatterSchema>): Promise<MdxArtifact<z.output<TFrontmatterSchema>>>;
|
|
38
38
|
}
|
|
39
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;AAIzC,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD,OAAO,EAAE,uBAAuB,EAAE,eAAe,EAAE,CAAC;AAEpD;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,UAAU,CAAC;AAE5C;;GAEG;AACH,MAAM,WAAW,iBAAiB,
|
|
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;AAIzC,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAE7B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CA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@@ -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,
|
|
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;AAG/B,OAAO,KAAK,EAAyB,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAG3E,KAAK,gBAAgB,GAAG,OAAO,CAC7B,iBAAiB,CAAC,eAAe,EAAE,YAAY,CAAC,CACjD,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,4BAA4B;IAC3C;;OAEG;IACH,uBAAuB,CAAC,EAAE,MAAM,CAAC;IAEjC;;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,wBAAgB,qBAAqB,CACnC,OAAO,GAAE,4BAAiC,GACzC,aAAa,CA8Jf"}
|