fumadocs-core 15.7.2 → 15.7.4

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.
@@ -24,25 +24,24 @@ function remarkHeading({
24
24
  visit(root, "heading", (heading) => {
25
25
  heading.data ||= {};
26
26
  heading.data.hProperties ||= {};
27
- let id = heading.data.hProperties.id;
27
+ const props = heading.data.hProperties;
28
28
  const lastNode = heading.children.at(-1);
29
- if (!id && lastNode?.type === "text" && customId) {
29
+ if (lastNode?.type === "text" && customId) {
30
30
  const match = regex.exec(lastNode.value);
31
31
  if (match?.[1]) {
32
- id = match[1];
32
+ props.id = match[1];
33
33
  lastNode.value = lastNode.value.slice(0, match.index);
34
34
  }
35
35
  }
36
36
  let flattened = null;
37
- if (!id) {
37
+ if (!props.id) {
38
38
  flattened ??= flattenNode(heading);
39
- id = defaultSlug ? defaultSlug(root, heading, flattened) : slugger.slug(flattened);
39
+ props.id = defaultSlug ? defaultSlug(root, heading, flattened) : slugger.slug(flattened);
40
40
  }
41
- heading.data.hProperties.id = id;
42
41
  if (generateToc) {
43
42
  toc.push({
44
43
  title: flattened ?? flattenNode(heading),
45
- url: `#${id}`,
44
+ url: `#${props.id}`,
46
45
  depth: heading.depth
47
46
  });
48
47
  }
@@ -1,9 +1,9 @@
1
- import {
2
- createI18nMiddleware
3
- } from "../chunk-KLUGJRZC.js";
4
1
  import {
5
2
  defineI18n
6
3
  } from "../chunk-HUTQC33E.js";
4
+ import {
5
+ createI18nMiddleware
6
+ } from "../chunk-KLUGJRZC.js";
7
7
  import "../chunk-JSBRDJBE.js";
8
8
  export {
9
9
  createI18nMiddleware,
@@ -3,10 +3,10 @@ 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, Code, BlockContent, Text } from 'mdast';
7
- export { a as StructureOptions, S as StructuredData, r as remarkStructure, s as structure } from '../remark-structure-DVje0Sib.js';
8
- export { R as RemarkHeadingOptions, r as remarkHeading } from '../remark-heading-BPCoYwjn.js';
9
- import { MdxJsxFlowElement, MdxJsxAttribute } from 'mdast-util-mdx-jsx';
6
+ import { Root as Root$1, BlockContent, Text } from 'mdast';
7
+ export { a as StructureOptions, S as StructuredData, r as remarkStructure, s as structure } from '../remark-structure-DkCXCzpD.js';
8
+ export { a as RemarkCodeTabOptions, R as RemarkHeadingOptions, b as remarkCodeTab, r as remarkHeading } from '../remark-code-tab-DmyIyi6m.js';
9
+ import { MdxJsxAttribute, MdxJsxFlowElement } from 'mdast-util-mdx-jsx';
10
10
 
11
11
  interface CodeBlockIcon {
12
12
  viewBox: string;
@@ -122,26 +122,6 @@ interface RehypeTocOptions {
122
122
  }
123
123
  declare function rehypeToc(this: Processor, { exportToc }?: RehypeTocOptions): Transformer<Root, Root>;
124
124
 
125
- type TabType = keyof typeof Types;
126
- interface RemarkCodeTabOptions {
127
- Tabs?: TabType;
128
- /**
129
- * Parse MDX in tab values
130
- *
131
- * @defaultValue false
132
- */
133
- parseMdx?: boolean;
134
- }
135
- declare const Types: {
136
- CodeBlockTabs: {
137
- convert(processor: Processor, nodes: Code[], withMdx?: boolean, withParent?: boolean): MdxJsxFlowElement;
138
- };
139
- Tabs: {
140
- convert(processor: Processor, nodes: Code[], withMdx?: boolean, withParent?: boolean): MdxJsxFlowElement;
141
- };
142
- };
143
- declare function remarkCodeTab(this: Processor, options?: RemarkCodeTabOptions): Transformer<Root$1, Root$1>;
144
-
145
125
  interface RemarkStepsOptions {
146
126
  /**
147
127
  * Class name for steps container
@@ -213,4 +193,4 @@ interface CodeBlockAttributes<Name extends string = string> {
213
193
  */
214
194
  declare function parseCodeBlockAttributes<Name extends string = string>(meta: string, allowedNames?: Name[]): CodeBlockAttributes<Name>;
215
195
 
216
- export { type CodeBlockAttributes, type CodeBlockIcon, type CodeBlockTabsOptions, type RehypeCodeOptions, type RehypeTocOptions, type RemarkAdmonitionOptions, type RemarkCodeTabOptions, type RemarkImageOptions, type RemarkNpmOptions, type RemarkStepsOptions, generateCodeBlockTabs, parseCodeBlockAttributes, rehypeCode, rehypeCodeDefaultOptions, rehypeToc, remarkAdmonition, remarkCodeTab, remarkImage, remarkNpm, remarkSteps, transformerIcon, transformerTab };
196
+ export { type CodeBlockAttributes, type CodeBlockIcon, type CodeBlockTabsOptions, type RehypeCodeOptions, type RehypeTocOptions, type RemarkAdmonitionOptions, type RemarkImageOptions, type RemarkNpmOptions, type RemarkStepsOptions, generateCodeBlockTabs, parseCodeBlockAttributes, rehypeCode, rehypeCodeDefaultOptions, rehypeToc, remarkAdmonition, remarkImage, remarkNpm, remarkSteps, transformerIcon, transformerTab };
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  flattenNode,
3
3
  remarkHeading
4
- } from "../chunk-Y2774T3B.js";
4
+ } from "../chunk-QMATWJ5F.js";
5
5
  import {
6
6
  joinPath,
7
7
  slash
@@ -318,7 +318,8 @@ function rehypeCode(_options = {}) {
318
318
  options.experimentalJSEngine ? "js" : "oniguruma",
319
319
  {
320
320
  themes: "themes" in options ? Object.values(options.themes).filter(Boolean) : [options.theme],
321
- langs: options.langs ?? (options.lazy ? ["ts", "tsx"] : Object.keys(bundledLanguages))
321
+ langs: options.langs ?? (options.lazy ? ["ts", "tsx"] : Object.keys(bundledLanguages)),
322
+ langAlias: options.langAlias
322
323
  }
323
324
  );
324
325
  const transformer = highlighter.then(
@@ -569,7 +570,6 @@ import Slugger from "github-slugger";
569
570
  import { remark } from "remark";
570
571
  import remarkGfm from "remark-gfm";
571
572
  import { visit as visit2 } from "unist-util-visit";
572
- var slugger = new Slugger();
573
573
  function remarkStructure({
574
574
  types = [
575
575
  "heading",
@@ -583,6 +583,7 @@ function remarkStructure({
583
583
  return ["TypeTable", "Callout"].includes(node.name);
584
584
  }
585
585
  } = {}) {
586
+ const slugger = new Slugger();
586
587
  if (Array.isArray(allowedMdxAttributes)) {
587
588
  const arr = allowedMdxAttributes;
588
589
  allowedMdxAttributes = (_node, attribute) => attribute.type === "mdxJsxAttribute" && arr.includes(attribute.name);
@@ -594,7 +595,7 @@ function remarkStructure({
594
595
  return (node, file) => {
595
596
  slugger.reset();
596
597
  const data = { contents: [], headings: [] };
597
- let lastHeading = "";
598
+ let lastHeading;
598
599
  if (file.data.frontmatter) {
599
600
  const frontmatter = file.data.frontmatter;
600
601
  if (frontmatter._openapi?.structuredData) {
@@ -747,7 +748,7 @@ function rehypeToc({ exportToc = true } = {}) {
747
748
  const output = [];
748
749
  visit4(tree, ["h1", "h2", "h3", "h4", "h5", "h6"], (element) => {
749
750
  const id = element.properties.id;
750
- if (!id) return "skip";
751
+ if (typeof id !== "string") return "skip";
751
752
  let isTocOnly = false;
752
753
  const last = element.children.at(-1);
753
754
  if (last?.type === "text" && last.value.endsWith(TocOnlyTag)) {
@@ -867,7 +868,6 @@ function rehypeToc({ exportToc = true } = {}) {
867
868
 
868
869
  // src/mdx-plugins/remark-code-tab.ts
869
870
  import { visit as visit5 } from "unist-util-visit";
870
- var TabRegex = /tab="(.+?)"/;
871
871
  var Tabs = {
872
872
  convert(processor, nodes, withMdx = false, withParent = true) {
873
873
  const names = processTabValue(nodes);
@@ -976,62 +976,27 @@ var Tabs = {
976
976
  var CodeBlockTabs = {
977
977
  convert(processor, nodes, withMdx = false, withParent = true) {
978
978
  const names = processTabValue(nodes);
979
- const children = [
980
- {
981
- type: "mdxJsxFlowElement",
982
- name: "CodeBlockTabsList",
983
- attributes: [],
984
- children: names.map((name) => {
985
- return {
986
- type: "mdxJsxFlowElement",
987
- name: "CodeBlockTabsTrigger",
988
- attributes: [
989
- {
990
- type: "mdxJsxAttribute",
991
- name: "value",
992
- value: name
993
- }
994
- ],
995
- children: [
996
- withMdx ? (
997
- // eslint-disable-next-line @typescript-eslint/no-explicit-any -- needed
998
- mdxToAst(processor, name)
999
- ) : {
1000
- type: "text",
1001
- value: name
1002
- }
1003
- ]
1004
- };
1005
- })
1006
- },
1007
- ...nodes.map((node, i) => {
1008
- return {
1009
- type: "mdxJsxFlowElement",
1010
- name: "CodeBlockTab",
1011
- attributes: [
1012
- {
1013
- type: "mdxJsxAttribute",
1014
- name: "value",
1015
- value: names[i]
1016
- }
1017
- ],
1018
- children: [node]
1019
- };
1020
- })
1021
- ];
1022
- if (!withParent) return createFragment(children);
1023
- return {
1024
- type: "mdxJsxFlowElement",
1025
- name: "CodeBlockTabs",
1026
- attributes: [
1027
- {
1028
- type: "mdxJsxAttribute",
1029
- name: "defaultValue",
1030
- value: names[0]
1031
- }
1032
- ],
1033
- children
1034
- };
979
+ const node = generateCodeBlockTabs({
980
+ defaultValue: names[0],
981
+ triggers: names.map((name) => ({
982
+ value: name,
983
+ children: [
984
+ withMdx ? (
985
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- needed
986
+ mdxToAst(processor, name)
987
+ ) : {
988
+ type: "text",
989
+ value: name
990
+ }
991
+ ]
992
+ })),
993
+ tabs: nodes.map((node2, i) => ({
994
+ value: names[i],
995
+ children: [node2]
996
+ }))
997
+ });
998
+ if (!withParent) return createFragment(node.children);
999
+ return node;
1035
1000
  }
1036
1001
  };
1037
1002
  var Types = {
@@ -1041,58 +1006,58 @@ var Types = {
1041
1006
  function remarkCodeTab(options = {}) {
1042
1007
  const { parseMdx = false, Tabs: Tabs2 = "CodeBlockTabs" } = options;
1043
1008
  return (tree) => {
1009
+ const ignored = /* @__PURE__ */ new WeakSet();
1044
1010
  visit5(tree, (node) => {
1045
- if (!("children" in node)) return;
1046
- let start = -1;
1047
- let i = 0;
1011
+ if (!("children" in node) || ignored.has(node)) return "skip";
1048
1012
  let localTabs = Tabs2;
1049
1013
  let localParseMdx = parseMdx;
1050
1014
  let withParent = true;
1051
1015
  if (node.type === "mdxJsxFlowElement" && node.name && node.name in Types) {
1052
1016
  withParent = false;
1053
1017
  localTabs = node.name;
1054
- if (node.name === "Tabs") {
1018
+ if (node.name === "Tabs" && localParseMdx) {
1055
1019
  localParseMdx = node.attributes.every(
1056
1020
  (attribute) => attribute.type !== "mdxJsxAttribute" || attribute.name !== "items"
1057
1021
  );
1058
1022
  }
1059
1023
  }
1060
- while (i < node.children.length) {
1061
- const child = node.children[i];
1062
- const isSwitcher = child.type === "code" && child.meta && child.meta.match(TabRegex);
1063
- if (isSwitcher && start === -1) {
1064
- start = i;
1024
+ let start = -1;
1025
+ let end = 0;
1026
+ const close = () => {
1027
+ if (start === -1 || start === end) return;
1028
+ const replacement = Types[localTabs].convert(
1029
+ this,
1030
+ node.children.slice(start, end),
1031
+ localParseMdx,
1032
+ withParent
1033
+ );
1034
+ ignored.add(replacement);
1035
+ node.children.splice(start, end - start, replacement);
1036
+ end = start;
1037
+ start = -1;
1038
+ };
1039
+ for (; end < node.children.length; end++) {
1040
+ const child = node.children[end];
1041
+ if (child.type !== "code" || !child.meta) {
1042
+ close();
1043
+ continue;
1065
1044
  }
1066
- const isLast = i === node.children.length - 1;
1067
- if (start !== -1 && (isLast || !isSwitcher)) {
1068
- const end = isSwitcher ? i + 1 : i;
1069
- const targets = node.children.slice(start, end);
1070
- const replacement = Types[localTabs].convert(
1071
- this,
1072
- targets,
1073
- localParseMdx,
1074
- withParent
1075
- );
1076
- node.children.splice(start, end - start, replacement);
1077
- if (isLast) break;
1078
- i = start + 1;
1079
- start = -1;
1080
- } else {
1081
- i++;
1045
+ const meta = parseCodeBlockAttributes(child.meta, ["tab"]);
1046
+ if (!meta.attributes.tab) {
1047
+ close();
1048
+ continue;
1082
1049
  }
1050
+ if (start === -1) start = end;
1051
+ child.meta = meta.rest;
1052
+ child.data ??= {};
1053
+ child.data.tab = meta.attributes.tab;
1083
1054
  }
1055
+ close();
1084
1056
  });
1085
1057
  };
1086
1058
  }
1087
1059
  function processTabValue(nodes) {
1088
- return nodes.map((node, i) => {
1089
- let title = `Tab ${i + 1}`;
1090
- node.meta = node.meta?.replace(TabRegex, (_, value) => {
1091
- title = value;
1092
- return "";
1093
- });
1094
- return title;
1095
- });
1060
+ return nodes.map((node, i) => node.data?.tab ?? `Tab ${i + 1}`);
1096
1061
  }
1097
1062
  function mdxToAst(processor, name) {
1098
1063
  const node = processor.parse(name);
@@ -0,0 +1,57 @@
1
+ import { Root, Heading, Code } from 'mdast';
2
+ import { Transformer, Processor } from 'unified';
3
+ import { MdxJsxFlowElement } from 'mdast-util-mdx-jsx';
4
+
5
+ declare module 'mdast' {
6
+ interface HeadingData extends Data {
7
+ hProperties?: {
8
+ id?: string;
9
+ };
10
+ }
11
+ }
12
+ interface RemarkHeadingOptions {
13
+ slug?: (root: Root, heading: Heading, text: string) => string;
14
+ /**
15
+ * Allow custom headings ids
16
+ *
17
+ * @defaultValue true
18
+ */
19
+ customId?: boolean;
20
+ /**
21
+ * Attach an array of `TOCItemType` to `file.data.toc`
22
+ *
23
+ * @defaultValue true
24
+ */
25
+ generateToc?: boolean;
26
+ }
27
+ /**
28
+ * Add heading ids and extract TOC
29
+ */
30
+ declare function remarkHeading({ slug: defaultSlug, customId, generateToc, }?: RemarkHeadingOptions): Transformer<Root, Root>;
31
+
32
+ type TabType = keyof typeof Types;
33
+ interface RemarkCodeTabOptions {
34
+ Tabs?: TabType;
35
+ /**
36
+ * Parse MDX in tab values
37
+ *
38
+ * @defaultValue false
39
+ */
40
+ parseMdx?: boolean;
41
+ }
42
+ declare module 'mdast' {
43
+ interface CodeData {
44
+ tab?: string;
45
+ }
46
+ }
47
+ declare const Types: {
48
+ CodeBlockTabs: {
49
+ convert(processor: Processor, nodes: Code[], withMdx?: boolean, withParent?: boolean): MdxJsxFlowElement;
50
+ };
51
+ Tabs: {
52
+ convert(processor: Processor, nodes: Code[], withMdx?: boolean, withParent?: boolean): MdxJsxFlowElement;
53
+ };
54
+ };
55
+ declare function remarkCodeTab(this: Processor, options?: RemarkCodeTabOptions): Transformer<Root, Root>;
56
+
57
+ export { type RemarkHeadingOptions as R, type RemarkCodeTabOptions as a, remarkCodeTab as b, remarkHeading as r };
@@ -42,6 +42,11 @@ declare module 'mdast' {
42
42
  _string?: string[];
43
43
  }
44
44
  }
45
+ declare module 'vfile' {
46
+ interface DataMap {
47
+ structuredData: StructuredData;
48
+ }
49
+ }
45
50
  /**
46
51
  * Attach structured data to VFile, you can access via `vfile.data.structuredData`.
47
52
  */
@@ -1,5 +1,5 @@
1
1
  import { Algoliasearch } from 'algoliasearch';
2
- import { S as StructuredData } from '../remark-structure-DVje0Sib.js';
2
+ import { S as StructuredData } from '../remark-structure-DkCXCzpD.js';
3
3
  import 'mdast';
4
4
  import 'unified';
5
5
  import 'mdast-util-mdx-jsx';
@@ -1,5 +1,5 @@
1
1
  import { AnyOrama } from '@orama/orama';
2
- import '../remark-structure-DVje0Sib.js';
2
+ import '../remark-structure-DkCXCzpD.js';
3
3
  import { BaseIndex } from './algolia.js';
4
4
  import { LiteClient, SearchResponse } from 'algoliasearch/lite';
5
5
  import { OramaClient, ClientSearchParams } from '@oramacloud/client';
@@ -1,6 +1,6 @@
1
1
  import { CloudManager } from '@oramacloud/client';
2
- import { S as StructuredData } from '../remark-structure-DVje0Sib.js';
3
- import '../remark-heading-BPCoYwjn.js';
2
+ import { S as StructuredData } from '../remark-structure-DkCXCzpD.js';
3
+ import '../remark-code-tab-DmyIyi6m.js';
4
4
  import 'mdast';
5
5
  import 'unified';
6
6
  import 'mdast-util-mdx-jsx';
@@ -1,5 +1,5 @@
1
1
  import { TypedDocument, Orama, Language, RawData, create, SearchParams } from '@orama/orama';
2
- import { S as StructuredData } from '../remark-structure-DVje0Sib.js';
2
+ import { S as StructuredData } from '../remark-structure-DkCXCzpD.js';
3
3
  import { S as SortedResult } from '../shared-ORgOfXFw.js';
4
4
  export { H as HighlightedText, c as createContentHighlighter } from '../shared-ORgOfXFw.js';
5
5
  import { I18nConfig } from '../i18n/index.js';
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  remarkHeading
3
- } from "../chunk-Y2774T3B.js";
3
+ } from "../chunk-QMATWJ5F.js";
4
4
  import "../chunk-JSBRDJBE.js";
5
5
 
6
6
  // src/server/get-toc.ts
@@ -1,8 +1,3 @@
1
- import {
2
- joinPath,
3
- slash,
4
- splitPath
5
- } from "../chunk-3JSIVMCJ.js";
6
1
  import {
7
2
  basename,
8
3
  dirname,
@@ -10,6 +5,11 @@ import {
10
5
  parseFilePath,
11
6
  parseFolderPath
12
7
  } from "../chunk-7GNSIKII.js";
8
+ import {
9
+ joinPath,
10
+ slash,
11
+ splitPath
12
+ } from "../chunk-3JSIVMCJ.js";
13
13
  import "../chunk-JSBRDJBE.js";
14
14
 
15
15
  // src/source/page-tree/legacy.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-core",
3
- "version": "15.7.2",
3
+ "version": "15.7.4",
4
4
  "description": "The library for building a documentation website in Next.js",
5
5
  "keywords": [
6
6
  "NextJs",
@@ -1,31 +0,0 @@
1
- import { Root, Heading } from 'mdast';
2
- import { Transformer } from 'unified';
3
-
4
- declare module 'mdast' {
5
- interface HeadingData extends Data {
6
- hProperties?: {
7
- id?: string;
8
- };
9
- }
10
- }
11
- interface RemarkHeadingOptions {
12
- slug?: (root: Root, heading: Heading, text: string) => string;
13
- /**
14
- * Allow custom headings ids
15
- *
16
- * @defaultValue true
17
- */
18
- customId?: boolean;
19
- /**
20
- * Attach an array of `TOCItemType` to `file.data.toc`
21
- *
22
- * @defaultValue true
23
- */
24
- generateToc?: boolean;
25
- }
26
- /**
27
- * Add heading ids and extract TOC
28
- */
29
- declare function remarkHeading({ slug: defaultSlug, customId, generateToc, }?: RemarkHeadingOptions): Transformer<Root, Root>;
30
-
31
- export { type RemarkHeadingOptions as R, remarkHeading as r };