fumadocs-core 16.16.2 → 16.17.0

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.
Files changed (96) hide show
  1. package/dist/{advanced-Ct13khZr.js → advanced-cJMxLDd5.js} +7 -10
  2. package/dist/{algolia-C5o8qrQ1.d.ts → algolia-6p3_Zitq.d.ts} +3 -2
  3. package/dist/{build-doc-Cjg7QvFR.js → build-doc-C7HYXyRK.js} +2 -1
  4. package/dist/{client-BcR4jyFl.d.ts → client-4RUaXHFg.d.ts} +117 -61
  5. package/dist/{codeblock-utils-CyP8qsYv.d.ts → codeblock-utils-D4AMPi6B.d.ts} +1 -1
  6. package/dist/content/mdx/preset-bundler.d.ts +2 -2
  7. package/dist/content/mdx/preset-runtime.d.ts +2 -2
  8. package/dist/heading-id-CUA_RA6B.js +16 -0
  9. package/dist/highlight-SXtD3BKk.js +7 -0
  10. package/dist/i18n/middleware.js +2 -1
  11. package/dist/{index-Cyv18VFj.d.ts → index-B-xgXq2T.d.ts} +5 -5
  12. package/dist/index-BbTxYEFm.d.ts +53 -0
  13. package/dist/{index-CBtz3H2e.d.ts → index-CzLpE50a.d.ts} +13 -9
  14. package/dist/mcp.d.ts +2 -2
  15. package/dist/mdx-plugins/codeblock-utils.d.ts +1 -1
  16. package/dist/mdx-plugins/index.d.ts +6 -6
  17. package/dist/mdx-plugins/index.js +3 -3
  18. package/dist/mdx-plugins/rehype-code.core.js +1 -1
  19. package/dist/mdx-plugins/rehype-code.js +1 -1
  20. package/dist/mdx-plugins/rehype-toc.js +3 -3
  21. package/dist/mdx-plugins/remark-admonition.js +2 -3
  22. package/dist/mdx-plugins/remark-block-id.js +2 -3
  23. package/dist/mdx-plugins/remark-code-tab.js +5 -2
  24. package/dist/mdx-plugins/remark-directive-admonition.js +3 -3
  25. package/dist/mdx-plugins/remark-feedback-block.js +2 -4
  26. package/dist/mdx-plugins/remark-heading.js +5 -5
  27. package/dist/mdx-plugins/remark-image.js +8 -5
  28. package/dist/mdx-plugins/remark-llms.d.ts +2 -2
  29. package/dist/mdx-plugins/remark-llms.js +41 -62
  30. package/dist/mdx-plugins/remark-mdx-files.d.ts +1 -1
  31. package/dist/mdx-plugins/remark-mdx-files.js +16 -14
  32. package/dist/mdx-plugins/remark-mdx-mermaid.js +6 -3
  33. package/dist/mdx-plugins/remark-npm.js +6 -4
  34. package/dist/mdx-plugins/remark-steps.js +11 -6
  35. package/dist/mdx-plugins/remark-structure.d.ts +2 -2
  36. package/dist/mdx-plugins/remark-structure.js +111 -71
  37. package/dist/mdx-plugins/stringifier.d.ts +50 -2
  38. package/dist/mdx-plugins/stringifier.js +209 -84
  39. package/dist/meilisearch-DiRS8T7h.d.ts +52 -0
  40. package/dist/mixedbread-Df-Sw_4f.d.ts +76 -0
  41. package/dist/parse-BU3fTLtO.js +59 -0
  42. package/dist/{rehype-code.core-BFENmmvo.js → rehype-code.core-BwH0Kyry.js} +3 -4
  43. package/dist/remark-llms-cgVaxL_5.d.ts +56 -0
  44. package/dist/{remark-mdx-files-Buvxc-sa.d.ts → remark-mdx-files-NfjIpY1d.d.ts} +1 -1
  45. package/dist/{remark-structure-CnHwvNZr.d.ts → remark-structure-C4hp7I5L.d.ts} +21 -23
  46. package/dist/search/algolia.d.ts +1 -1
  47. package/dist/search/algolia.js +5 -3
  48. package/dist/search/client/algolia.d.ts +2 -2
  49. package/dist/search/client/algolia.js +39 -23
  50. package/dist/search/client/docs-search.d.ts +2 -0
  51. package/dist/search/client/docs-search.js +54 -0
  52. package/dist/search/client/fetch.d.ts +2 -2
  53. package/dist/search/client/fetch.js +41 -19
  54. package/dist/search/client/flexsearch-static.d.ts +2 -2
  55. package/dist/search/client/flexsearch-static.js +28 -16
  56. package/dist/search/client/meilisearch.d.ts +2 -20
  57. package/dist/search/client/meilisearch.js +59 -42
  58. package/dist/search/client/mixedbread.d.ts +3 -2
  59. package/dist/search/client/mixedbread.js +7 -43
  60. package/dist/search/client/orama-cloud-legacy.d.ts +2 -2
  61. package/dist/search/client/orama-cloud-legacy.js +96 -74
  62. package/dist/search/client/orama-cloud.d.ts +2 -2
  63. package/dist/search/client/orama-cloud.js +97 -75
  64. package/dist/search/client/orama-static.d.ts +2 -2
  65. package/dist/search/client/orama-static.js +47 -25
  66. package/dist/search/client.d.ts +2 -2
  67. package/dist/search/client.js +8 -97
  68. package/dist/search/flexsearch.d.ts +4 -3
  69. package/dist/search/flexsearch.js +2 -2
  70. package/dist/search/index.d.ts +2 -2
  71. package/dist/search/index.js +24 -14
  72. package/dist/search/meilisearch.d.ts +2 -50
  73. package/dist/search/meilisearch.js +6 -1
  74. package/dist/search/mixedbread.d.ts +3 -48
  75. package/dist/search/mixedbread.js +117 -42
  76. package/dist/search/orama-cloud-legacy.d.ts +3 -2
  77. package/dist/search/orama-cloud-legacy.js +3 -2
  78. package/dist/search/orama-cloud.d.ts +4 -3
  79. package/dist/search/orama-cloud.js +3 -2
  80. package/dist/search/server.d.ts +1 -1
  81. package/dist/search/server.js +3 -3
  82. package/dist/{server-B7eP2V3p.d.ts → server-BaG-Kb8Y.d.ts} +3 -3
  83. package/dist/source/dynamic.d.ts +1 -1
  84. package/dist/source/index.d.ts +1 -1
  85. package/dist/source/llms.d.ts +1 -1
  86. package/dist/source/llms.js +10 -11
  87. package/dist/source/plugins/lucide-icons.d.ts +1 -1
  88. package/dist/source/plugins/slugs.d.ts +1 -1
  89. package/dist/source/plugins/status-badges.d.ts +1 -1
  90. package/dist/use-search-Dy8lBrbN.js +93 -0
  91. package/dist/{utils-Yx0IL9eW.js → utils-2pZeFRk8.js} +12 -1
  92. package/dist/{utils-Bvy3V-fv.js → utils-CbSdov6X.js} +4 -5
  93. package/package.json +4 -3
  94. package/dist/index-BM36H-xw.d.ts +0 -36
  95. package/dist/remark-llms-DxglVo94.d.ts +0 -73
  96. package/dist/stringifier-B_QUcUyo.d.ts +0 -63
@@ -1,5 +1,5 @@
1
1
  import { defaultShikiFactory, wasmShikiFactory } from "../highlight/shiki/full.js";
2
- import { n as rehypeCodeDefaultOptions$1, r as transformerTab, t as createRehypeCode } from "../rehype-code.core-BFENmmvo.js";
2
+ import { n as rehypeCodeDefaultOptions$1, r as transformerTab, t as createRehypeCode } from "../rehype-code.core-BwH0Kyry.js";
3
3
  import { transformerIcon } from "./transformer-icon.js";
4
4
  //#region src/mdx-plugins/rehype-code.ts
5
5
  const rehypeCodeDefaultOptions = {
@@ -1,5 +1,4 @@
1
- import { a as toMdxExportRaw, r as handleTag } from "../utils-Yx0IL9eW.js";
2
- import { visit } from "unist-util-visit";
1
+ import { o as toMdxExportRaw, r as handleTag, s as walk } from "../utils-2pZeFRk8.js";
3
2
  import { toEstree } from "hast-util-to-estree";
4
3
  //#region src/mdx-plugins/rehype-toc.ts
5
4
  const TocOnlyTag = "[toc]";
@@ -31,7 +30,8 @@ function rehypeToc({ exportToc = true } = {}) {
31
30
  if (exportToc === false) return () => void 0;
32
31
  return (tree, file) => {
33
32
  const items = [];
34
- visit(tree, "element", (element, idx, parent) => {
33
+ walk(tree, (element, idx, parent) => {
34
+ if (element.type !== "element") return;
35
35
  if (!HeadingTags.has(element.tagName) || element.children.length === 0) return;
36
36
  const id = element.properties.id;
37
37
  if (typeof id !== "string") return "skip";
@@ -1,5 +1,4 @@
1
- import { t as flattenNode } from "../utils-Yx0IL9eW.js";
2
- import { visit } from "unist-util-visit";
1
+ import { s as walk, t as flattenNode } from "../utils-2pZeFRk8.js";
3
2
  //#region src/mdx-plugins/remark-admonition.ts
4
3
  /**
5
4
  * Remark Plugin to support Admonition syntax
@@ -61,7 +60,7 @@ function remarkAdmonition(options = {}) {
61
60
  }
62
61
  }
63
62
  return (tree) => {
64
- visit(tree, (node) => {
63
+ walk(tree, (node) => {
65
64
  if (!("children" in node)) return;
66
65
  replaceNodes(node.children);
67
66
  });
@@ -1,6 +1,5 @@
1
- import { t as flattenNode } from "../utils-Yx0IL9eW.js";
1
+ import { s as walk, t as flattenNode } from "../utils-2pZeFRk8.js";
2
2
  import Slugger from "github-slugger";
3
- import { visit } from "unist-util-visit";
4
3
  import { createHash } from "node:crypto";
5
4
  //#region src/mdx-plugins/remark-block-id.ts
6
5
  /**
@@ -19,7 +18,7 @@ function remarkBlockId({ generateId, addDataAttribute = "default", shouldGenerat
19
18
  } } = {}) {
20
19
  return (tree) => {
21
20
  const slugger = new Slugger();
22
- visit(tree, (node) => {
21
+ walk(tree, (node) => {
23
22
  if (node.type === "root" || node.data?.hProperties?.id) return;
24
23
  const resolved = shouldGenerate(node);
25
24
  if (resolved === false) return;
@@ -1,5 +1,5 @@
1
+ import { s as walk } from "../utils-2pZeFRk8.js";
1
2
  import { generateCodeBlockTabs, parseCodeBlockAttributes } from "./codeblock-utils.js";
2
- import { visit } from "unist-util-visit";
3
3
  //#region src/mdx-plugins/remark-code-tab.ts
4
4
  const Types = {
5
5
  CodeBlockTabs(processor, nodes, withMdx, withParent) {
@@ -117,7 +117,7 @@ const Types = {
117
117
  function remarkCodeTab(options = {}) {
118
118
  const { parseMdx = false, Tabs = "CodeBlockTabs" } = options;
119
119
  return (tree) => {
120
- visit(tree, (node) => {
120
+ walk(tree, (node) => {
121
121
  if (!("children" in node) || node.data?._code_tab_visited) return "skip";
122
122
  let localTabs = Tabs;
123
123
  let localParseMdx = parseMdx;
@@ -180,6 +180,9 @@ function processTabValue(nodes) {
180
180
  */
181
181
  function mdxToAst(processor, name) {
182
182
  const node = processor.parse(name);
183
+ walk(node, (child) => {
184
+ delete child.position;
185
+ });
183
186
  node.children = node.children.flatMap((child) => {
184
187
  if (child.type === "paragraph") return child.children;
185
188
  return child;
@@ -1,4 +1,4 @@
1
- import { visit } from "unist-util-visit";
1
+ import { s as walk } from "../utils-2pZeFRk8.js";
2
2
  //#region src/mdx-plugins/remark-directive-admonition.ts
3
3
  /**
4
4
  * Remark Plugin to support Admonition syntax in Docusaurus, useful for migrating from Docusaurus.
@@ -15,8 +15,8 @@ function remarkDirectiveAdmonition({ tags: { CalloutContainer = "CalloutContaine
15
15
  success: "success"
16
16
  } } = {}) {
17
17
  return (tree) => {
18
- visit(tree, "containerDirective", (node) => {
19
- if (!(node.name in types)) return;
18
+ walk(tree, (node) => {
19
+ if (node.type !== "containerDirective" || !(node.name in types)) return;
20
20
  const attributes = [{
21
21
  type: "mdxJsxAttribute",
22
22
  name: "type",
@@ -1,5 +1,4 @@
1
- import { t as flattenNode } from "../utils-Yx0IL9eW.js";
2
- import { visit } from "unist-util-visit";
1
+ import { s as walk, t as flattenNode } from "../utils-2pZeFRk8.js";
3
2
  import { createHash } from "node:crypto";
4
3
  //#region src/mdx-plugins/remark-feedback-block.ts
5
4
  /**
@@ -18,7 +17,7 @@ function remarkFeedbackBlock({ generateHash = ({ body }) => createHash("md5").up
18
17
  }, generateBody = true } = {}) {
19
18
  return (tree) => {
20
19
  const counts = /* @__PURE__ */ new Map();
21
- visit(tree, (node, index, parent) => {
20
+ walk(tree, (node, index, parent) => {
22
21
  if (node.type === "root" || !parent || typeof index !== "number") return;
23
22
  const resolved = resolve(node);
24
23
  if (resolved === false) return;
@@ -37,7 +36,6 @@ function remarkFeedbackBlock({ generateHash = ({ body }) => createHash("md5").up
37
36
  name: "id",
38
37
  value: id
39
38
  }],
40
- data: { _stringify: "children-only" },
41
39
  children: [node]
42
40
  };
43
41
  if (generateBody) wrapper.attributes.push({
@@ -1,8 +1,7 @@
1
- import { t as flattenNode } from "../utils-Yx0IL9eW.js";
1
+ import { s as walk, t as flattenNode } from "../utils-2pZeFRk8.js";
2
+ import { t as headingIdRegex } from "../heading-id-CUA_RA6B.js";
2
3
  import Slugger from "github-slugger";
3
- import { visit } from "unist-util-visit";
4
4
  //#region src/mdx-plugins/remark-heading.ts
5
- const regex = /\s*\[#(?<slug>[^]+?)]\s*$/;
6
5
  /**
7
6
  * Add heading ids and extract TOC
8
7
  */
@@ -15,13 +14,14 @@ function remarkHeading({ slug, customId = true, generateToc = true } = {}) {
15
14
  return (root, file) => {
16
15
  const toc = [];
17
16
  slugger?.reset();
18
- visit(root, "heading", (heading) => {
17
+ walk(root, (heading) => {
18
+ if (heading.type !== "heading") return;
19
19
  heading.data ||= {};
20
20
  heading.data.hProperties ||= {};
21
21
  const props = heading.data.hProperties;
22
22
  const lastNode = heading.children.at(-1);
23
23
  if (lastNode?.type === "text" && customId) {
24
- const match = regex.exec(lastNode.value);
24
+ const match = headingIdRegex.exec(lastNode.value);
25
25
  if (match?.[1]) {
26
26
  props.id = match[1];
27
27
  lastNode.value = lastNode.value.slice(0, match.index);
@@ -1,4 +1,5 @@
1
- import { visit } from "unist-util-visit";
1
+ import { s as walk } from "../utils-2pZeFRk8.js";
2
+ import { replaceSource } from "./stringifier.js";
2
3
  import * as path$1 from "node:path";
3
4
  import { fileURLToPath } from "node:url";
4
5
  //#region src/mdx-plugins/remark-image.ts
@@ -30,6 +31,7 @@ function remarkImage({ placeholder = "none", external = true, useImport = true,
30
31
  children: [],
31
32
  type: "mdxJsxFlowElement",
32
33
  name: "img",
34
+ position: node.position,
33
35
  attributes: [{
34
36
  type: "mdxJsxAttribute",
35
37
  name: "alt",
@@ -76,20 +78,21 @@ function remarkImage({ placeholder = "none", external = true, useImport = true,
76
78
  node.data.hProperties.width = size.width.toString();
77
79
  node.data.hProperties.height = size.height.toString();
78
80
  }
79
- visit(tree, "image", (node, idx, parent) => {
80
- if (typeof idx !== "number" || !parent) return;
81
+ walk(tree, (node, _, parent) => {
82
+ if (node.type !== "image" || !parent) return;
81
83
  const src = parseSrc(decodeURI(node.url), publicDir, file.dirname);
82
84
  if (!src) return;
83
85
  const task = updateImage(src, node).catch((e) => {
84
86
  if (onError === "ignore" || node.url.endsWith(".svg")) return;
85
87
  if (onError === "hide") {
86
- parent.children.splice(idx, 1);
88
+ replaceSource(file, node, "");
89
+ parent.children.splice(parent.children.indexOf(node), 1);
87
90
  return;
88
91
  }
89
92
  if (onError === "error") throw e;
90
93
  onError(e);
91
94
  }).then((res) => {
92
- if (res) parent.children[idx] = res;
95
+ if (res) parent.children[parent.children.indexOf(node)] = res;
93
96
  });
94
97
  promises.push(task);
95
98
  });
@@ -1,2 +1,2 @@
1
- import { n as placeholder, r as remarkLLMs, t as LLMsOptions } from "../remark-llms-DxglVo94.js";
2
- export { LLMsOptions, placeholder, remarkLLMs };
1
+ import { n as remarkLLMs, t as LLMsOptions } from "../remark-llms-cgVaxL_5.js";
2
+ export { LLMsOptions, remarkLLMs };
@@ -1,54 +1,52 @@
1
- import { i as toMdxExport } from "../utils-Yx0IL9eW.js";
2
- import { defaultStringifier } from "./stringifier.js";
3
- import { defaultHandlers } from "mdast-util-to-markdown";
1
+ import { a as toMdxExport, i as isJsxElement } from "../utils-2pZeFRk8.js";
2
+ import { n as stringifyHeadingId } from "../heading-id-CUA_RA6B.js";
3
+ import { createStringifier } from "./stringifier.js";
4
4
  //#region src/mdx-plugins/remark-llms.ts
5
+ const componentNameRegex = /^[A-Z][\w$]*$/;
5
6
  /**
6
- * generate `llms.txt` for markdown.
7
+ * Generate Markdown for LLMs from the authored source, other plugins can edit it with
8
+ * `replaceSource()` from `fumadocs-core/mdx-plugins/stringifier`.
7
9
  */
8
- function remarkLLMs({ as = "_markdown", headingIds = true, _data = false, mdxAsPlaceholder, output = "string", ...rest } = {}) {
10
+ function remarkLLMs({ as = "_markdown", headingIds = true, _data = false, mdxAsPlaceholder, output = "string", filterElement } = {}) {
9
11
  const jsx = output === "function";
10
- const stringifier = defaultStringifier({
11
- ...rest,
12
- filterElement(node) {
13
- switch (node.type) {
14
- case "mdxjsEsm": return false;
15
- default: return rest.filterElement?.(node) ?? true;
16
- }
17
- },
18
- stringify(node, parent, state, info, collect) {
19
- if (mdxAsPlaceholder && !collect) switch (node.type) {
20
- case "mdxJsxFlowElement":
21
- case "mdxJsxTextElement": if (node.name && mdxAsPlaceholder.includes(node.name)) return placeholder(node, parent, state, info);
12
+ return (tree, file) => {
13
+ const s = createStringifier(file);
14
+ const collect = [];
15
+ const visit = (nodes) => {
16
+ for (const node of nodes) {
17
+ const visibility = node.type === "mdxjsEsm" ? false : filterElement?.(node) ?? true;
18
+ if (visibility === false) {
19
+ s.replace(node, "");
20
+ continue;
21
+ }
22
+ if ("children" in node) visit(node.children);
23
+ if (visibility === "children-only") s.replace(node, (s) => s.inner(node));
24
+ else if (node.type === "heading") stringifyHeadingId(s, node, headingIds);
25
+ else if (isJsxElement(node) && node.name) {
26
+ if (!jsx && mdxAsPlaceholder?.includes(node.name)) s.replace(node, (s) => toPlaceholder(node, s.inner(node)));
27
+ else if (jsx && componentNameRegex.test(node.name)) s.replace(node, (s) => {
28
+ let children = s.inner(node);
29
+ if (children && node.type === "mdxJsxFlowElement") children = `\n${children}\n`;
30
+ return `\0${collect.push({
31
+ node,
32
+ children
33
+ }) - 1}\0`;
34
+ });
35
+ }
22
36
  }
23
- const custom = rest.stringify?.(node, parent, state, info, void 0);
24
- if (custom) return custom;
25
- if (collect) return collectJsx(node, state, info, collect);
26
- },
27
- handlers: {
28
- heading(node, _p, state, info) {
29
- const id = node.data?.hProperties?.id;
30
- const defaultValue = defaultHandlers.heading(node, _p, state, info);
31
- return headingIds && id ? `${defaultValue} [#${id}]` : defaultValue;
32
- },
33
- ...rest.handlers
34
- }
35
- });
36
- return (node, file) => {
37
+ };
38
+ visit(tree.children);
39
+ const text = s.stringify(tree).trim();
40
+ const value = text ? `${text}\n` : "";
37
41
  if (jsx) {
38
- const collect = [];
39
- const text = stringifier.call(this, node, collect);
40
- node.children.unshift(jsxToEstree(as, toJsxChunks(text, collect)));
42
+ tree.children.unshift(jsxToEstree(as, toJsxChunks(value, collect)));
41
43
  return;
42
44
  }
43
- const value = stringifier.call(this, node, void 0);
44
- node.children.unshift(toMdxExport(as, value));
45
+ tree.children.unshift(toMdxExport(as, value));
45
46
  if (_data) file.data.markdown = value;
46
47
  };
47
48
  }
48
- /**
49
- * Preserve AST data to render the MDX component at runtime, use `renderPlaceholder()` to render the placeholders.
50
- */
51
- function placeholder(node, _parent, state, info) {
49
+ function toPlaceholder(node, children) {
52
50
  const attributes = {};
53
51
  for (const attr of node.attributes) {
54
52
  if (attr.type === "mdxJsxExpressionAttribute") continue;
@@ -56,32 +54,13 @@ function placeholder(node, _parent, state, info) {
56
54
  }
57
55
  return `\0${JSON.stringify({
58
56
  name: node.name,
59
- children: state.containerPhrasing(node, info),
57
+ children,
60
58
  attributes
61
59
  })}\0`;
62
60
  }
63
- /**
64
- * `stringify` branch for the `function` output: collect the element and return a marker,
65
- * resolved later by `toJsxChunks()`. Only components (capitalized names) are kept.
66
- */
67
- function collectJsx(node, state, info, collect) {
68
- switch (node.type) {
69
- case "mdxJsxFlowElement":
70
- case "mdxJsxTextElement": {
71
- if (!node.name || !/^[A-Z][\w$]*$/.test(node.name)) return;
72
- const entry = {
73
- node,
74
- children: ""
75
- };
76
- const marker = `\0${collect.push(entry) - 1}\0`;
77
- entry.children = node.type === "mdxJsxTextElement" ? state.containerPhrasing(node, info) : state.containerFlow(node, info);
78
- return marker;
79
- }
80
- }
81
- }
82
61
  const Marker = /\0(\d+)\0/g;
83
62
  /**
84
- * Split stringified Markdown on the markers emitted by `collectJsx()` into
63
+ * Split stringified Markdown on the markers of kept JSX elements into
85
64
  * alternating text chunks and kept JSX elements, recursively for their children.
86
65
  */
87
66
  function toJsxChunks(text, collect) {
@@ -335,4 +314,4 @@ function programExpression(program) {
335
314
  if (statement?.type === "ExpressionStatement") return statement.expression;
336
315
  }
337
316
  //#endregion
338
- export { placeholder, remarkLLMs };
317
+ export { remarkLLMs };
@@ -1,2 +1,2 @@
1
- import { a as remarkMdxFiles, i as ToMdxOptions, n as FolderNode, r as RemarkMdxFilesOptions, t as FileNode } from "../remark-mdx-files-Buvxc-sa.js";
1
+ import { a as remarkMdxFiles, i as ToMdxOptions, n as FolderNode, r as RemarkMdxFilesOptions, t as FileNode } from "../remark-mdx-files-NfjIpY1d.js";
2
2
  export { FileNode, FolderNode, RemarkMdxFilesOptions, ToMdxOptions, remarkMdxFiles };
@@ -1,18 +1,18 @@
1
- import { visit } from "unist-util-visit";
1
+ import { s as walk } from "../utils-2pZeFRk8.js";
2
+ import { replaceSource } from "./stringifier.js";
2
3
  import path from "node:path";
3
4
  //#region src/mdx-plugins/remark-mdx-files.ts
4
5
  function parseFileTree(code) {
5
6
  const lines = code.split(/\r?\n/);
6
7
  const stack = /* @__PURE__ */ new Map();
8
+ let root;
7
9
  for (const line of lines) {
8
- let depth = 0;
9
- let name = line;
10
- let match;
11
- while (match = /(?:├──|│|└──)\s*/.exec(name)) {
12
- name = name.slice(match[0].length);
13
- depth++;
14
- }
10
+ const name = line.replace(/^[\s│├└─]+/, "");
15
11
  if (!name) continue;
12
+ const column = line.length - name.length;
13
+ let parent;
14
+ for (let i = column - 1; i >= 0 && !parent; i--) parent = stack.get(i);
15
+ const depth = parent ? parent.depth + 1 : 0;
16
16
  const node = name.endsWith("/") ? {
17
17
  type: "folder",
18
18
  name,
@@ -23,17 +23,18 @@ function parseFileTree(code) {
23
23
  name,
24
24
  depth
25
25
  };
26
- let parent;
27
- for (let i = depth - 1; i >= 0 && !parent; i--) parent = stack.get(i);
28
- stack.set(depth, node);
29
- if (!parent) continue;
26
+ stack.set(column, node);
27
+ if (!parent) {
28
+ root = node;
29
+ continue;
30
+ }
30
31
  if (parent.type === "file") Object.assign(parent, {
31
32
  type: "folder",
32
33
  children: []
33
34
  });
34
35
  parent.children.push(node);
35
36
  }
36
- return stack.get(0);
37
+ return root;
37
38
  }
38
39
  function defaultToMDX(node, options, depth = 0) {
39
40
  if (depth === 0) return {
@@ -98,11 +99,12 @@ function remarkMdxFiles(options = {}) {
98
99
  const baseDir = file.dirname ?? file.cwd;
99
100
  const cwd = dir ? path.join(baseDir, dir) : baseDir;
100
101
  const files = await glob(patterns, { cwd });
102
+ replaceSource(file, node, `\`\`\`\n${files.join("\n")}\n\`\`\``);
101
103
  Object.assign(node, toMdx(buildFileTreeFromGlob(cwd, files), { defaultOpenAll }));
102
104
  }
103
105
  return async (tree, file) => {
104
106
  const queue = [];
105
- visit(tree, ["code", "mdxJsxFlowElement"], (node) => {
107
+ walk(tree, (node) => {
106
108
  if (node.type === "code") {
107
109
  if (node.lang !== lang || !node.value) return;
108
110
  const fileTree = parseFileTree(node.value);
@@ -1,4 +1,5 @@
1
- import { visit } from "unist-util-visit";
1
+ import { s as walk } from "../utils-2pZeFRk8.js";
2
+ import { replaceSource } from "./stringifier.js";
2
3
  //#region src/mdx-plugins/remark-mdx-mermaid.ts
3
4
  function toMDX(code) {
4
5
  return {
@@ -17,9 +18,11 @@ function toMDX(code) {
17
18
  */
18
19
  function remarkMdxMermaid(options = {}) {
19
20
  const { lang = "mermaid" } = options;
20
- return (tree) => {
21
- visit(tree, "code", (node, idx, parent) => {
21
+ return (tree, file) => {
22
+ walk(tree, (node, idx, parent) => {
23
+ if (node.type !== "code") return;
22
24
  if (node.lang !== lang || !node.value || typeof idx !== "number" || !parent) return;
25
+ replaceSource(file, node, (s) => s.stringify(node));
23
26
  parent.children[idx] = toMDX(node.value);
24
27
  });
25
28
  };
@@ -1,5 +1,6 @@
1
+ import { s as walk } from "../utils-2pZeFRk8.js";
1
2
  import { generateCodeBlockTabs } from "./codeblock-utils.js";
2
- import { visit } from "unist-util-visit";
3
+ import { replaceSource } from "./stringifier.js";
3
4
  import convert from "npm-to-yarn";
4
5
  //#region src/mdx-plugins/remark-npm.ts
5
6
  function convertLines(cmd, to) {
@@ -26,9 +27,9 @@ function remarkNpm({ persist = false, packageManagers = [
26
27
  name: "bun"
27
28
  }
28
29
  ] } = {}) {
29
- return (tree) => {
30
- visit(tree, "code", (node, idx, parent) => {
31
- if (typeof idx !== "number" || !parent) return;
30
+ return (tree, file) => {
31
+ walk(tree, (node, idx, parent) => {
32
+ if (node.type !== "code" || typeof idx !== "number" || !parent) return;
32
33
  let code;
33
34
  switch (node.lang) {
34
35
  case "package-install":
@@ -67,6 +68,7 @@ function remarkNpm({ persist = false, packageManagers = [
67
68
  }]
68
69
  });
69
70
  }
71
+ replaceSource(file, node, (s) => s.stringify(node));
70
72
  parent.children[idx] = generateCodeBlockTabs(options);
71
73
  return "skip";
72
74
  });
@@ -1,8 +1,12 @@
1
- import { r as handleTag } from "../utils-Yx0IL9eW.js";
2
- import { visit } from "unist-util-visit";
1
+ import { r as handleTag, s as walk } from "../utils-2pZeFRk8.js";
2
+ import { replaceSource } from "./stringifier.js";
3
3
  //#region src/mdx-plugins/remark-steps.ts
4
4
  const StepRegex = /^(\d+)\.\s(.+)$/;
5
5
  const StepTag = "[step]";
6
+ function removeTag(text) {
7
+ const stripped = handleTag(text, StepTag);
8
+ return stripped === false ? text : stripped;
9
+ }
6
10
  /**
7
11
  * Convert headings in the format of `1. Hello World` into steps.
8
12
  */
@@ -32,7 +36,7 @@ function remarkSteps({ steps = "fd-steps", step = "fd-step" } = {}) {
32
36
  children
33
37
  };
34
38
  }
35
- function handleHeadingStep(node) {
39
+ function handleHeadingStep(node, file) {
36
40
  const head = node.children[0];
37
41
  if (head && head.type === "text") {
38
42
  const match = StepRegex.exec(head.value);
@@ -46,13 +50,14 @@ function remarkSteps({ steps = "fd-steps", step = "fd-step" } = {}) {
46
50
  const step = handleTag(tail.value, StepTag);
47
51
  if (step !== false) {
48
52
  tail.value = step;
53
+ replaceSource(file, tail, (s) => removeTag(s.stringify(tail)), "search");
49
54
  return true;
50
55
  }
51
56
  }
52
57
  return false;
53
58
  }
54
- return (tree) => {
55
- visit(tree, (parent) => {
59
+ return (tree, file) => {
60
+ walk(tree, (parent) => {
56
61
  if (!("children" in parent) || parent.type === "heading") return "skip";
57
62
  let startIdx = -1;
58
63
  let i = 0;
@@ -76,7 +81,7 @@ function remarkSteps({ steps = "fd-steps", step = "fd-step" } = {}) {
76
81
  continue;
77
82
  }
78
83
  }
79
- if (!handleHeadingStep(node)) {
84
+ if (!handleHeadingStep(node, file)) {
80
85
  onEnd();
81
86
  continue;
82
87
  }
@@ -1,2 +1,2 @@
1
- import { a as defaultStringifier, c as structure, i as StructuredData, n as StringifyOptions, o as remarkStructure, r as StructureOptions, s as remarkStructureDefaultOptions, t as Stringifier } from "../remark-structure-CnHwvNZr.js";
2
- export { Stringifier, StringifyOptions, StructureOptions, StructuredData, defaultStringifier, remarkStructure, remarkStructureDefaultOptions, structure };
1
+ import { a as remarkStructureDefaultOptions, i as remarkStructure, n as StructuredData, o as structure, r as StructuredDataContent, t as StructureOptions } from "../remark-structure-C4hp7I5L.js";
2
+ export { StructureOptions, StructuredData, StructuredDataContent, remarkStructure, remarkStructureDefaultOptions, structure };