fumadocs-core 11.0.6 → 11.0.8

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.
@@ -0,0 +1,45 @@
1
+ // src/mdx-plugins/remark-heading.ts
2
+ import Slugger from "github-slugger";
3
+ import { visit } from "unist-util-visit";
4
+ var slugger = new Slugger();
5
+ var regex = new RegExp("\\s*\\[#(?<slug>[^]+?)]\\s*$");
6
+ function remarkHeading({
7
+ slug: defaultSlug,
8
+ customId = true
9
+ } = {}) {
10
+ return (root, file) => {
11
+ const toc = [];
12
+ slugger.reset();
13
+ visit(root, "heading", (heading) => {
14
+ var _a;
15
+ const node = heading.children.at(-1);
16
+ if (!node || node.type !== "text")
17
+ return;
18
+ heading.data || (heading.data = {});
19
+ (_a = heading.data).hProperties || (_a.hProperties = {});
20
+ let id = heading.data.hProperties.id;
21
+ if (!id && customId) {
22
+ const match = regex.exec(node.value);
23
+ if (match == null ? void 0 : match[1]) {
24
+ id = match[1];
25
+ node.value = node.value.slice(0, match.index);
26
+ }
27
+ }
28
+ if (!id) {
29
+ id = defaultSlug ? defaultSlug(root, heading, node.value) : slugger.slug(node.value);
30
+ }
31
+ heading.data.hProperties.id = id;
32
+ toc.push({
33
+ title: node.value,
34
+ url: `#${id}`,
35
+ depth: heading.depth
36
+ });
37
+ return "skip";
38
+ });
39
+ file.data.toc = toc;
40
+ };
41
+ }
42
+
43
+ export {
44
+ remarkHeading
45
+ };
@@ -61,12 +61,18 @@ declare module 'mdast' {
61
61
  }
62
62
  interface RemarkHeadingOptions {
63
63
  slug?: (root: Root$1, heading: Heading, text: string) => string;
64
+ /**
65
+ * Allow custom headings ids
66
+ *
67
+ * @defaultValue `true`
68
+ */
69
+ customId?: boolean;
64
70
  }
65
71
  /**
66
72
  * Add heading ids and extract TOC
67
73
  *
68
74
  * Attach an array of `TOCItemType` to `file.data.toc`
69
75
  */
70
- declare function remarkHeading(options?: RemarkHeadingOptions): Transformer<Root$1, Root$1>;
76
+ declare function remarkHeading({ slug: defaultSlug, customId, }?: RemarkHeadingOptions): Transformer<Root$1, Root$1>;
71
77
 
72
78
  export { type CodeBlockIcon, type RehypeCodeOptions, type RemarkHeadingOptions, type RemarkImageOptions, rehypeCode, rehypeCodeDefaultOptions, remarkHeading, remarkImage, transformerIcon };
@@ -1,7 +1,6 @@
1
1
  import {
2
- flattenNode,
3
2
  remarkHeading
4
- } from "../chunk-KI4HQIXJ.js";
3
+ } from "../chunk-5BST7EWT.js";
5
4
  import {
6
5
  slash
7
6
  } from "../chunk-UWEEHUJV.js";
@@ -456,6 +455,17 @@ import { remark } from "remark";
456
455
  import remarkGfm from "remark-gfm";
457
456
  import remarkMdx from "remark-mdx";
458
457
  import { visit as visit3 } from "unist-util-visit";
458
+
459
+ // src/mdx-plugins/remark-utils.ts
460
+ function flattenNode(node) {
461
+ if ("children" in node)
462
+ return node.children.map((child) => flattenNode(child)).join("");
463
+ if ("value" in node)
464
+ return node.value;
465
+ return "";
466
+ }
467
+
468
+ // src/mdx-plugins/remark-structure.ts
459
469
  var slugger = new Slugger();
460
470
  function remarkStructure({
461
471
  types = ["paragraph", "blockquote", "heading"]
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  remarkHeading
3
- } from "../chunk-KI4HQIXJ.js";
3
+ } from "../chunk-5BST7EWT.js";
4
4
  import {
5
5
  __async
6
6
  } from "../chunk-WEAGW6MQ.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-core",
3
- "version": "11.0.6",
3
+ "version": "11.0.8",
4
4
  "description": "The library for building a documentation website in Next.js",
5
5
  "keywords": [
6
6
  "NextJs",
@@ -1,49 +0,0 @@
1
- // src/mdx-plugins/remark-heading.ts
2
- import Slugger from "github-slugger";
3
- import { visit } from "unist-util-visit";
4
-
5
- // src/mdx-plugins/remark-utils.ts
6
- function flattenNode(node) {
7
- if ("children" in node)
8
- return node.children.map((child) => flattenNode(child)).join("");
9
- if ("value" in node)
10
- return node.value;
11
- return "";
12
- }
13
-
14
- // src/mdx-plugins/remark-heading.ts
15
- var slugger = new Slugger();
16
- function remarkHeading(options = {}) {
17
- return (node, file) => {
18
- const toc = [];
19
- slugger.reset();
20
- visit(node, "heading", (heading) => {
21
- var _a, _b;
22
- heading.data || (heading.data = {});
23
- (_a = heading.data).hProperties || (_a.hProperties = {});
24
- const text = flattenNode(heading);
25
- const id = (_b = heading.data.hProperties.id) != null ? _b : options.slug ? options.slug(node, heading, text) : defaultSlug(text);
26
- heading.data.hProperties.id = id;
27
- toc.push({
28
- title: text,
29
- url: `#${id}`,
30
- depth: heading.depth
31
- });
32
- return "skip";
33
- });
34
- file.data.toc = toc;
35
- };
36
- }
37
- function defaultSlug(text) {
38
- if (text.endsWith("}")) {
39
- const start = text.lastIndexOf("{");
40
- if (start !== -1 && text[start - 1] !== "\\")
41
- return text.substring(start + 1, text.length - 1);
42
- }
43
- return slugger.slug(text);
44
- }
45
-
46
- export {
47
- flattenNode,
48
- remarkHeading
49
- };