fumadocs-core 10.0.3 → 10.0.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.
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
// src/mdx-plugins/remark-heading.ts
|
|
2
2
|
import Slugger from "github-slugger";
|
|
3
|
-
|
|
4
|
-
// src/mdx-plugins/unist-visit.ts
|
|
5
|
-
import { visit as original } from "unist-util-visit";
|
|
6
|
-
var visit = original;
|
|
3
|
+
import { visit } from "unist-util-visit";
|
|
7
4
|
|
|
8
5
|
// src/mdx-plugins/remark-utils.ts
|
|
9
6
|
function flattenNode(node) {
|
|
@@ -20,14 +17,13 @@ function remarkHeading() {
|
|
|
20
17
|
return (node, file) => {
|
|
21
18
|
const toc = [];
|
|
22
19
|
slugger.reset();
|
|
23
|
-
visit(node,
|
|
20
|
+
visit(node, "heading", (heading) => {
|
|
24
21
|
var _a, _b;
|
|
25
22
|
heading.data || (heading.data = {});
|
|
26
23
|
(_a = heading.data).hProperties || (_a.hProperties = {});
|
|
27
24
|
const text = flattenNode(heading);
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
properties.id = id;
|
|
25
|
+
const id = slugger.slug((_b = heading.data.hProperties.id) != null ? _b : text);
|
|
26
|
+
heading.data.hProperties.id = id;
|
|
31
27
|
toc.push({
|
|
32
28
|
title: text,
|
|
33
29
|
url: `#${id}`,
|
|
@@ -40,7 +36,6 @@ function remarkHeading() {
|
|
|
40
36
|
}
|
|
41
37
|
|
|
42
38
|
export {
|
|
43
|
-
visit,
|
|
44
39
|
flattenNode,
|
|
45
40
|
remarkHeading
|
|
46
41
|
};
|
|
@@ -71,8 +71,12 @@ interface RemarkDynamicContentOptions {
|
|
|
71
71
|
*/
|
|
72
72
|
declare function remarkDynamicContent(options?: RemarkDynamicContentOptions): Transformer<Root$1, Root$1>;
|
|
73
73
|
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
declare module 'mdast' {
|
|
75
|
+
interface HeadingData extends Data {
|
|
76
|
+
hProperties?: {
|
|
77
|
+
id?: string;
|
|
78
|
+
};
|
|
79
|
+
}
|
|
76
80
|
}
|
|
77
81
|
/**
|
|
78
82
|
* Add heading ids and extract TOC
|
|
@@ -93,6 +97,7 @@ type RemarkInstallOptions = Partial<{
|
|
|
93
97
|
/**
|
|
94
98
|
* It generates the following structure from a code block with `package-install` as language
|
|
95
99
|
*
|
|
100
|
+
* @example
|
|
96
101
|
* ```tsx
|
|
97
102
|
* <Tabs items={["pnpm", "npm", "yarn"]}>
|
|
98
103
|
* <Tab value="pnpm">...</Tab>
|
|
@@ -102,4 +107,4 @@ type RemarkInstallOptions = Partial<{
|
|
|
102
107
|
*/
|
|
103
108
|
declare function remarkInstall({ Tab, Tabs, packageManagers, }?: RemarkInstallOptions): Transformer<Root$1, Root$1>;
|
|
104
109
|
|
|
105
|
-
export { type CodeBlockIcon, type
|
|
110
|
+
export { type CodeBlockIcon, type RehypeCodeOptions, type RemarkDynamicContentOptions, type RemarkImageOptions, type RemarkInstallOptions, rehypeCode, rehypeCodeDefaultOptions, remarkDynamicContent, remarkHeading, remarkImage, remarkInstall, transformerIcon };
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
flattenNode,
|
|
3
|
-
remarkHeading
|
|
4
|
-
|
|
5
|
-
} from "../chunk-M6ZDX3QR.js";
|
|
3
|
+
remarkHeading
|
|
4
|
+
} from "../chunk-D3Y6KNIC.js";
|
|
6
5
|
import {
|
|
7
6
|
slash
|
|
8
7
|
} from "../chunk-UWEEHUJV.js";
|
|
@@ -24,7 +23,7 @@ import {
|
|
|
24
23
|
} from "@shikijs/transformers";
|
|
25
24
|
|
|
26
25
|
// src/mdx-plugins/hast-utils.ts
|
|
27
|
-
function
|
|
26
|
+
function visit(node, tagNames, handler) {
|
|
28
27
|
if (node.type === "element") {
|
|
29
28
|
if (tagNames.includes(node.tagName)) {
|
|
30
29
|
handler(node);
|
|
@@ -33,7 +32,7 @@ function visit2(node, tagNames, handler) {
|
|
|
33
32
|
}
|
|
34
33
|
if ("children" in node)
|
|
35
34
|
node.children.forEach((n) => {
|
|
36
|
-
|
|
35
|
+
visit(n, tagNames, handler);
|
|
37
36
|
});
|
|
38
37
|
}
|
|
39
38
|
|
|
@@ -339,7 +338,7 @@ function rehypeCode(options = {}) {
|
|
|
339
338
|
const prefix = "language-";
|
|
340
339
|
const transformer = rehypeShiki.call(this, codeOptions);
|
|
341
340
|
return (root, vfile) => __async(this, null, function* () {
|
|
342
|
-
|
|
341
|
+
visit(root, ["pre"], (element) => {
|
|
343
342
|
var _a;
|
|
344
343
|
const head = element.children[0];
|
|
345
344
|
if (element.children.length === 0 || head.type !== "element" || head.tagName !== "code")
|
|
@@ -363,6 +362,7 @@ function rehypeCode(options = {}) {
|
|
|
363
362
|
// src/mdx-plugins/remark-image.ts
|
|
364
363
|
import { existsSync } from "fs";
|
|
365
364
|
import path from "path";
|
|
365
|
+
import { visit as visit2 } from "unist-util-visit";
|
|
366
366
|
var VALID_BLUR_EXT = [".jpeg", ".png", ".webp", ".avif", ".jpg"];
|
|
367
367
|
var EXTERNAL_URL_REGEX = /^https?:\/\//;
|
|
368
368
|
var PUBLIC_DIR = path.join(process.cwd(), "public");
|
|
@@ -371,7 +371,7 @@ function remarkImage({
|
|
|
371
371
|
} = {}) {
|
|
372
372
|
return (tree, _file, done) => {
|
|
373
373
|
const importsToInject = [];
|
|
374
|
-
|
|
374
|
+
visit2(tree, "image", (node) => {
|
|
375
375
|
var _a;
|
|
376
376
|
let url = decodeURI(node.url);
|
|
377
377
|
if (!url || EXTERNAL_URL_REGEX.test(url)) {
|
|
@@ -453,6 +453,7 @@ function remarkImage({
|
|
|
453
453
|
// src/mdx-plugins/remark-dynamic-content.ts
|
|
454
454
|
import fs from "fs";
|
|
455
455
|
import path2 from "path";
|
|
456
|
+
import { visit as visit3 } from "unist-util-visit";
|
|
456
457
|
var regex = new RegExp("^\\|reference:(?<path>.+)\\|");
|
|
457
458
|
function remarkDynamicContent(options = {}) {
|
|
458
459
|
const {
|
|
@@ -461,9 +462,9 @@ function remarkDynamicContent(options = {}) {
|
|
|
461
462
|
visit: filter = ["text", "code"]
|
|
462
463
|
} = options;
|
|
463
464
|
return (tree) => {
|
|
464
|
-
|
|
465
|
+
visit3(tree, filter, (node) => {
|
|
465
466
|
var _a;
|
|
466
|
-
if (!("value" in node) || typeof node.value
|
|
467
|
+
if (!("value" in node) || typeof node.value === "string")
|
|
467
468
|
return;
|
|
468
469
|
const result = regex.exec(node.value);
|
|
469
470
|
if ((_a = result == null ? void 0 : result.groups) == null ? void 0 : _a.path) {
|
|
@@ -482,6 +483,7 @@ import Slugger from "github-slugger";
|
|
|
482
483
|
import { remark } from "remark";
|
|
483
484
|
import remarkGfm from "remark-gfm";
|
|
484
485
|
import remarkMdx from "remark-mdx";
|
|
486
|
+
import { visit as visit4 } from "unist-util-visit";
|
|
485
487
|
var slugger = new Slugger();
|
|
486
488
|
function remarkStructure({
|
|
487
489
|
types = ["paragraph", "blockquote", "heading"]
|
|
@@ -490,8 +492,10 @@ function remarkStructure({
|
|
|
490
492
|
slugger.reset();
|
|
491
493
|
const data = { contents: [], headings: [] };
|
|
492
494
|
let lastHeading = "";
|
|
493
|
-
|
|
495
|
+
visit4(node, types, (element) => {
|
|
494
496
|
var _a, _b;
|
|
497
|
+
if (element.type === "root")
|
|
498
|
+
return;
|
|
495
499
|
const content = flattenNode(element).trim();
|
|
496
500
|
if (element.type === "heading") {
|
|
497
501
|
element.data || (element.data = {});
|
|
@@ -510,8 +514,8 @@ function remarkStructure({
|
|
|
510
514
|
heading: lastHeading,
|
|
511
515
|
content
|
|
512
516
|
});
|
|
517
|
+
return "skip";
|
|
513
518
|
}
|
|
514
|
-
return "skip";
|
|
515
519
|
});
|
|
516
520
|
file.data.structuredData = data;
|
|
517
521
|
};
|
|
@@ -522,6 +526,7 @@ function structure(content, remarkPlugins = [], options = {}) {
|
|
|
522
526
|
}
|
|
523
527
|
|
|
524
528
|
// src/mdx-plugins/remark-install.ts
|
|
529
|
+
import { visit as visit5 } from "unist-util-visit";
|
|
525
530
|
function remarkInstall({
|
|
526
531
|
Tab = "Tab",
|
|
527
532
|
Tabs = "Tabs",
|
|
@@ -532,7 +537,7 @@ function remarkInstall({
|
|
|
532
537
|
]
|
|
533
538
|
} = {}) {
|
|
534
539
|
return (tree) => {
|
|
535
|
-
|
|
540
|
+
visit5(tree, "code", (node) => {
|
|
536
541
|
if (node.lang !== "package-install")
|
|
537
542
|
return "skip";
|
|
538
543
|
const managers = packageManagers.map((manager) => manager(node.value));
|
package/dist/server/index.js
CHANGED