fumadocs-core 11.0.5 → 11.0.6
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.
|
@@ -13,7 +13,7 @@ function flattenNode(node) {
|
|
|
13
13
|
|
|
14
14
|
// src/mdx-plugins/remark-heading.ts
|
|
15
15
|
var slugger = new Slugger();
|
|
16
|
-
function remarkHeading() {
|
|
16
|
+
function remarkHeading(options = {}) {
|
|
17
17
|
return (node, file) => {
|
|
18
18
|
const toc = [];
|
|
19
19
|
slugger.reset();
|
|
@@ -22,7 +22,7 @@ function remarkHeading() {
|
|
|
22
22
|
heading.data || (heading.data = {});
|
|
23
23
|
(_a = heading.data).hProperties || (_a.hProperties = {});
|
|
24
24
|
const text = flattenNode(heading);
|
|
25
|
-
const id =
|
|
25
|
+
const id = (_b = heading.data.hProperties.id) != null ? _b : options.slug ? options.slug(node, heading, text) : defaultSlug(text);
|
|
26
26
|
heading.data.hProperties.id = id;
|
|
27
27
|
toc.push({
|
|
28
28
|
title: text,
|
|
@@ -34,6 +34,14 @@ function remarkHeading() {
|
|
|
34
34
|
file.data.toc = toc;
|
|
35
35
|
};
|
|
36
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
|
+
}
|
|
37
45
|
|
|
38
46
|
export {
|
|
39
47
|
flattenNode,
|
|
@@ -3,7 +3,7 @@ import { Root } from 'hast';
|
|
|
3
3
|
import { RehypeShikiOptions } from '@shikijs/rehype';
|
|
4
4
|
import { Processor, Transformer } from 'unified';
|
|
5
5
|
import { ShikiTransformer } from 'shiki';
|
|
6
|
-
import { Root as Root$1 } from 'mdast';
|
|
6
|
+
import { Root as Root$1, Heading } from 'mdast';
|
|
7
7
|
export { S as StructuredData, r as remarkStructure, s as structure } from '../remark-structure-RwYPDA6M.js';
|
|
8
8
|
|
|
9
9
|
interface CodeBlockIcon {
|
|
@@ -59,11 +59,14 @@ declare module 'mdast' {
|
|
|
59
59
|
};
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
|
+
interface RemarkHeadingOptions {
|
|
63
|
+
slug?: (root: Root$1, heading: Heading, text: string) => string;
|
|
64
|
+
}
|
|
62
65
|
/**
|
|
63
66
|
* Add heading ids and extract TOC
|
|
64
67
|
*
|
|
65
|
-
* Attach an array of `TOCItemType` to `
|
|
68
|
+
* Attach an array of `TOCItemType` to `file.data.toc`
|
|
66
69
|
*/
|
|
67
|
-
declare function remarkHeading(): Transformer<Root$1, Root$1>;
|
|
70
|
+
declare function remarkHeading(options?: RemarkHeadingOptions): Transformer<Root$1, Root$1>;
|
|
68
71
|
|
|
69
|
-
export { type CodeBlockIcon, type RehypeCodeOptions, type RemarkImageOptions, rehypeCode, rehypeCodeDefaultOptions, remarkHeading, remarkImage, transformerIcon };
|
|
72
|
+
export { type CodeBlockIcon, type RehypeCodeOptions, type RemarkHeadingOptions, type RemarkImageOptions, rehypeCode, rehypeCodeDefaultOptions, remarkHeading, remarkImage, transformerIcon };
|
package/dist/server/index.js
CHANGED