@reslide-dev/mdx 0.1.1 → 0.2.1
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/dist/index.d.mts +13 -1
- package/dist/index.mjs +42 -1
- package/package.json +13 -13
package/dist/index.d.mts
CHANGED
|
@@ -1075,6 +1075,18 @@ declare function remarkClick(): (tree: Root) => void;
|
|
|
1075
1075
|
*/
|
|
1076
1076
|
declare function remarkMark(): (tree: Root) => void;
|
|
1077
1077
|
//#endregion
|
|
1078
|
+
//#region src/remark-directive-fallback.d.ts
|
|
1079
|
+
/**
|
|
1080
|
+
* Remark plugin that converts remaining (unprocessed) directive nodes
|
|
1081
|
+
* back to plain text. This prevents `remark-directive` from eating
|
|
1082
|
+
* colon-prefixed patterns like time notations (13:00), port numbers
|
|
1083
|
+
* (localhost:3000), or unknown directives.
|
|
1084
|
+
*
|
|
1085
|
+
* Should be placed **after** `remarkClick` and `remarkMark` in the
|
|
1086
|
+
* plugin pipeline so that it only touches leftovers.
|
|
1087
|
+
*/
|
|
1088
|
+
declare function remarkDirectiveFallback(): (tree: Root) => void;
|
|
1089
|
+
//#endregion
|
|
1078
1090
|
//#region src/compile.d.ts
|
|
1079
1091
|
interface CompileResult {
|
|
1080
1092
|
/** Compiled JavaScript code string (ESM) */
|
|
@@ -1111,4 +1123,4 @@ declare function compileMdxSlides(source: string, options?: {
|
|
|
1111
1123
|
rehypePlugins?: unknown[];
|
|
1112
1124
|
}): Promise<CompileResult>;
|
|
1113
1125
|
//#endregion
|
|
1114
|
-
export { type CompileResult, type SlideMetadata, compileMdxSlides, parseSlideMetadata, remarkClick, remarkMark, remarkSlides };
|
|
1126
|
+
export { type CompileResult, type SlideMetadata, compileMdxSlides, parseSlideMetadata, remarkClick, remarkDirectiveFallback, remarkMark, remarkSlides };
|
package/dist/index.mjs
CHANGED
|
@@ -289,6 +289,46 @@ function parseDirectiveName(name) {
|
|
|
289
289
|
return null;
|
|
290
290
|
}
|
|
291
291
|
//#endregion
|
|
292
|
+
//#region src/remark-directive-fallback.ts
|
|
293
|
+
function isDirectiveNode(node) {
|
|
294
|
+
if (typeof node !== "object" || node === null) return false;
|
|
295
|
+
const n = node;
|
|
296
|
+
return n.type === "textDirective" || n.type === "leafDirective";
|
|
297
|
+
}
|
|
298
|
+
function directiveToText(node) {
|
|
299
|
+
let text = `${node.type === "leafDirective" ? "::" : ":"}${node.name}`;
|
|
300
|
+
if (node.children.length > 0) {
|
|
301
|
+
const content = node.children.map((c) => c.value ?? "").join("");
|
|
302
|
+
if (content) text += `[${content}]`;
|
|
303
|
+
}
|
|
304
|
+
if (node.attributes && Object.keys(node.attributes).length > 0) {
|
|
305
|
+
const attrs = Object.entries(node.attributes).map(([k, v]) => v ? `${k}="${v}"` : k).join(" ");
|
|
306
|
+
text += `{${attrs}}`;
|
|
307
|
+
}
|
|
308
|
+
return text;
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Remark plugin that converts remaining (unprocessed) directive nodes
|
|
312
|
+
* back to plain text. This prevents `remark-directive` from eating
|
|
313
|
+
* colon-prefixed patterns like time notations (13:00), port numbers
|
|
314
|
+
* (localhost:3000), or unknown directives.
|
|
315
|
+
*
|
|
316
|
+
* Should be placed **after** `remarkClick` and `remarkMark` in the
|
|
317
|
+
* plugin pipeline so that it only touches leftovers.
|
|
318
|
+
*/
|
|
319
|
+
function remarkDirectiveFallback() {
|
|
320
|
+
return (tree) => {
|
|
321
|
+
visit(tree, (node, index, parent) => {
|
|
322
|
+
if (!isDirectiveNode(node)) return;
|
|
323
|
+
if (!parent || typeof index !== "number") return;
|
|
324
|
+
parent.children[index] = {
|
|
325
|
+
type: "text",
|
|
326
|
+
value: directiveToText(node)
|
|
327
|
+
};
|
|
328
|
+
});
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
//#endregion
|
|
292
332
|
//#region src/compile.ts
|
|
293
333
|
/**
|
|
294
334
|
* Parse frontmatter from MDX source without compiling.
|
|
@@ -324,6 +364,7 @@ async function compileMdxSlides(source, options) {
|
|
|
324
364
|
remarkSlides,
|
|
325
365
|
remarkClick,
|
|
326
366
|
remarkMark,
|
|
367
|
+
remarkDirectiveFallback,
|
|
327
368
|
...options?.remarkPlugins ?? []
|
|
328
369
|
],
|
|
329
370
|
rehypePlugins: [
|
|
@@ -356,4 +397,4 @@ function countSlides(source) {
|
|
|
356
397
|
return Math.max(1, parts.filter((p) => p.trim().length > 0).length);
|
|
357
398
|
}
|
|
358
399
|
//#endregion
|
|
359
|
-
export { compileMdxSlides, parseSlideMetadata, remarkClick, remarkMark, remarkSlides };
|
|
400
|
+
export { compileMdxSlides, parseSlideMetadata, remarkClick, remarkDirectiveFallback, remarkMark, remarkSlides };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reslide-dev/mdx",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Remark/rehype plugins for reslide MDX preprocessing",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"files": [
|
|
@@ -15,28 +15,28 @@
|
|
|
15
15
|
"access": "public"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@mdx-js/mdx": "
|
|
18
|
+
"@mdx-js/mdx": "3.1.1",
|
|
19
19
|
"@shikijs/rehype": "4.0.2",
|
|
20
20
|
"@shikijs/transformers": "4.0.2",
|
|
21
|
-
"rehype-katex": "
|
|
22
|
-
"remark-frontmatter": "
|
|
21
|
+
"rehype-katex": "7.0.1",
|
|
22
|
+
"remark-frontmatter": "5.0.0",
|
|
23
23
|
"remark-gfm": "4.0.1",
|
|
24
|
-
"remark-math": "
|
|
25
|
-
"unist-util-visit": "
|
|
24
|
+
"remark-math": "6.0.0",
|
|
25
|
+
"unist-util-visit": "5.1.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@types/mdast": "
|
|
29
|
-
"@types/unist": "
|
|
30
|
-
"remark": "
|
|
28
|
+
"@types/mdast": "4.0.4",
|
|
29
|
+
"@types/unist": "3.0.3",
|
|
30
|
+
"remark": "15.0.1",
|
|
31
31
|
"remark-directive": "4.0.0",
|
|
32
|
-
"remark-frontmatter": "
|
|
33
|
-
"remark-mdx": "
|
|
34
|
-
"unified": "
|
|
32
|
+
"remark-frontmatter": "5.0.0",
|
|
33
|
+
"remark-mdx": "3.1.1",
|
|
34
|
+
"unified": "11.0.5",
|
|
35
35
|
"vite-plus": "latest",
|
|
36
36
|
"vitest": "npm:@voidzero-dev/vite-plus-test@latest"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
|
-
"remark-directive": "
|
|
39
|
+
"remark-directive": "4.0.0"
|
|
40
40
|
},
|
|
41
41
|
"inlinedDependencies": {
|
|
42
42
|
"@types/mdast": "4.0.4",
|