fumadocs-core 16.6.4 → 16.6.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.
@@ -9,5 +9,6 @@ type DynamicLinkProps = LinkProps;
9
9
  * It supports dynamic hrefs, which means you can use `/[lang]/my-page` with `dynamicHrefs` enabled
10
10
  */
11
11
  declare const DynamicLink: react.ForwardRefExoticComponent<LinkProps & react.RefAttributes<HTMLAnchorElement>>;
12
+ declare function updateHref(href: string, params: Record<string, string | string[]>): string;
12
13
  //#endregion
13
- export { DynamicLink, DynamicLink as default, DynamicLinkProps };
14
+ export { DynamicLink, DynamicLink as default, DynamicLinkProps, updateHref };
@@ -15,18 +15,20 @@ const DynamicLink = forwardRef(({ href, ...props }, ref) => {
15
15
  const params = useParams();
16
16
  return /* @__PURE__ */ jsx(Link, {
17
17
  ref,
18
- href: useMemo(() => {
19
- return href?.replace(/\[.*]/, (key) => {
20
- const mappedKey = key.slice(1, -1);
21
- const value = mappedKey in params ? params[mappedKey] : void 0;
22
- if (!value) return "";
23
- return typeof value === "string" ? value : value.join("/");
24
- });
25
- }, [params, href]),
18
+ href: useMemo(() => href ? updateHref(href, params) : href, [params, href]),
26
19
  ...props
27
20
  });
28
21
  });
29
22
  DynamicLink.displayName = "DynamicLink";
23
+ function updateHref(href, params) {
24
+ return href.replace(/\[(.*)]\/?/, (match, key) => {
25
+ const hasEndingSlash = match[match.length - 1] === "/";
26
+ const value = key in params ? params[key] : void 0;
27
+ if (!value) return "";
28
+ const replacement = typeof value === "string" ? value : value.join("/");
29
+ return hasEndingSlash ? `${replacement}/` : replacement;
30
+ });
31
+ }
30
32
 
31
33
  //#endregion
32
- export { DynamicLink, DynamicLink as default };
34
+ export { DynamicLink, DynamicLink as default, updateHref };
@@ -1,5 +1,5 @@
1
- import { BlockContent, Text } from "mdast";
2
1
  import { MdxJsxAttribute, MdxJsxFlowElement } from "mdast-util-mdx";
2
+ import { BlockContent, Text } from "mdast";
3
3
 
4
4
  //#region src/mdx-plugins/codeblock-utils.d.ts
5
5
  interface CodeBlockTabsOptions {
@@ -1,6 +1,6 @@
1
+ import { MdxJsxFlowElement } from "mdast-util-mdx";
1
2
  import { Processor, Transformer } from "unified";
2
3
  import { Code, Root } from "mdast";
3
- import { MdxJsxFlowElement } from "mdast-util-mdx";
4
4
 
5
5
  //#region src/mdx-plugins/remark-code-tab.d.ts
6
6
  type TabType = keyof typeof Types;
@@ -1,6 +1,6 @@
1
+ import { MdxJsxFlowElement } from "mdast-util-mdx";
1
2
  import { Transformer } from "unified";
2
3
  import { Root } from "mdast";
3
- import { MdxJsxFlowElement } from "mdast-util-mdx";
4
4
 
5
5
  //#region src/mdx-plugins/remark-mdx-files.d.ts
6
6
  interface FileNode {
@@ -1,7 +1,7 @@
1
+ import { MdxJsxAttribute, MdxJsxExpressionAttribute, MdxJsxFlowElement, MdxJsxTextElement } from "mdast-util-mdx";
1
2
  import { Options } from "mdast-util-to-markdown";
2
3
  import { PluggableList, Processor, Transformer } from "unified";
3
4
  import { Nodes, Root } from "mdast";
4
- import { MdxJsxAttribute, MdxJsxExpressionAttribute, MdxJsxFlowElement, MdxJsxTextElement } from "mdast-util-mdx";
5
5
 
6
6
  //#region src/mdx-plugins/remark-structure.d.ts
7
7
  interface StructuredDataHeading {
@@ -3,6 +3,7 @@ import { remarkHeading } from "./remark-heading.js";
3
3
  import { remark } from "remark";
4
4
  import { visit } from "unist-util-visit";
5
5
  import remarkGfm from "remark-gfm";
6
+ import { mdxToMarkdown } from "mdast-util-mdx";
6
7
  import { toMarkdown } from "mdast-util-to-markdown";
7
8
 
8
9
  //#region src/mdx-plugins/remark-structure.ts
@@ -40,10 +41,10 @@ function remarkStructure({ types = remarkStructureDefaultOptions.types, mdxTypes
40
41
  };
41
42
  let lastHeading;
42
43
  if (file.data.frontmatter) {
43
- const frontmatter = file.data.frontmatter;
44
- if (frontmatter._openapi?.structuredData) {
45
- data.headings.push(...frontmatter._openapi.structuredData.headings);
46
- data.contents.push(...frontmatter._openapi.structuredData.contents);
44
+ const openapiData = file.data.frontmatter._openapi?.structuredData;
45
+ if (openapiData) {
46
+ data.headings.push(...openapiData.headings);
47
+ data.contents.push(...openapiData.contents);
47
48
  }
48
49
  }
49
50
  const stringifierCtx = { addContent(...content) {
@@ -108,12 +109,11 @@ function defaultStringifier(config = {}) {
108
109
  return "children-only";
109
110
  }
110
111
  return true;
111
- } } = config;
112
+ }, ...customExtension } = config;
112
113
  function modHandler(handler, ctx) {
113
114
  return function(node, parent, state, info) {
114
- const { structuredData, _string } = node.data ?? {};
115
- if (structuredData) ctx.addContent(...structuredData.contents);
116
- if (_string) return typeof _string === "function" ? _string() : _string;
115
+ if (node.data?.structuredData) ctx.addContent(...node.data.structuredData.contents);
116
+ if (node.data?._string) return typeof node.data._string === "function" ? node.data._string() : node.data._string;
117
117
  const visibility = filterElement(node);
118
118
  if (visibility === false) return "";
119
119
  switch (node.type) {
@@ -146,7 +146,7 @@ function defaultStringifier(config = {}) {
146
146
  }
147
147
  };
148
148
  }
149
- const handlers = {
149
+ const customToMarkdown = { handlers: {
150
150
  link(node, _, state, info) {
151
151
  return state.containerPhrasing(node, info);
152
152
  },
@@ -160,20 +160,21 @@ function defaultStringifier(config = {}) {
160
160
  const handlers = state.handlers;
161
161
  for (const k in handlers) handlers[k] = modHandler(handlers[k], node.ctx);
162
162
  return state.handle(node.root, void 0, state, info);
163
- },
164
- ...config.handlers
165
- };
163
+ }
164
+ } };
166
165
  return function(root, ctx) {
167
- const defaultExtensions = this.data("toMarkdownExtensions") ?? [];
168
166
  return toMarkdown({
169
167
  type: "_custom",
170
168
  root,
171
169
  ctx
172
170
  }, {
173
171
  ...this.data("settings"),
174
- ...config,
175
- extensions: config.extensions ? [...defaultExtensions, ...config.extensions] : defaultExtensions,
176
- handlers
172
+ extensions: [
173
+ mdxToMarkdown(),
174
+ ...this.data("toMarkdownExtensions") ?? [],
175
+ customToMarkdown,
176
+ customExtension
177
+ ]
177
178
  });
178
179
  };
179
180
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-core",
3
- "version": "16.6.4",
3
+ "version": "16.6.5",
4
4
  "description": "The React.js library for building a documentation website",
5
5
  "keywords": [
6
6
  "Docs",