fumadocs-core 16.17.0 → 16.17.1

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.
@@ -1,5 +1,5 @@
1
- import { s as walk } from "../utils-2pZeFRk8.js";
2
1
  import { replaceSource } from "./stringifier.js";
2
+ import { s as walk } from "../utils-2pZeFRk8.js";
3
3
  import * as path$1 from "node:path";
4
4
  import { fileURLToPath } from "node:url";
5
5
  //#region src/mdx-plugins/remark-image.ts
@@ -1,6 +1,6 @@
1
+ import { createStringifier } from "./stringifier.js";
1
2
  import { a as toMdxExport, i as isJsxElement } from "../utils-2pZeFRk8.js";
2
3
  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
5
  const componentNameRegex = /^[A-Z][\w$]*$/;
6
6
  /**
@@ -1,5 +1,5 @@
1
- import { s as walk } from "../utils-2pZeFRk8.js";
2
1
  import { replaceSource } from "./stringifier.js";
2
+ import { s as walk } from "../utils-2pZeFRk8.js";
3
3
  import path from "node:path";
4
4
  //#region src/mdx-plugins/remark-mdx-files.ts
5
5
  function parseFileTree(code) {
@@ -1,5 +1,5 @@
1
- import { s as walk } from "../utils-2pZeFRk8.js";
2
1
  import { replaceSource } from "./stringifier.js";
2
+ import { s as walk } from "../utils-2pZeFRk8.js";
3
3
  //#region src/mdx-plugins/remark-mdx-mermaid.ts
4
4
  function toMDX(code) {
5
5
  return {
@@ -1,6 +1,6 @@
1
+ import { replaceSource } from "./stringifier.js";
1
2
  import { s as walk } from "../utils-2pZeFRk8.js";
2
3
  import { generateCodeBlockTabs } from "./codeblock-utils.js";
3
- import { replaceSource } from "./stringifier.js";
4
4
  import convert from "npm-to-yarn";
5
5
  //#region src/mdx-plugins/remark-npm.ts
6
6
  function convertLines(cmd, to) {
@@ -1,5 +1,5 @@
1
- import { r as handleTag, s as walk } from "../utils-2pZeFRk8.js";
2
1
  import { replaceSource } from "./stringifier.js";
2
+ import { r as handleTag, s as walk } from "../utils-2pZeFRk8.js";
3
3
  //#region src/mdx-plugins/remark-steps.ts
4
4
  const StepRegex = /^(\d+)\.\s(.+)$/;
5
5
  const StepTag = "[step]";
@@ -1,7 +1,7 @@
1
+ import { createStringifier } from "./stringifier.js";
1
2
  import { a as toMdxExport, i as isJsxElement, s as walk } from "../utils-2pZeFRk8.js";
2
3
  import { t as headingIdRegex } from "../heading-id-CUA_RA6B.js";
3
4
  import { remarkHeading } from "./remark-heading.js";
4
- import { createStringifier } from "./stringifier.js";
5
5
  import { tableRowToStructuredData } from "../search/index.js";
6
6
  import { remark } from "remark";
7
7
  import { VFile } from "vfile";
@@ -47,4 +47,10 @@ export interface Stringifier {
47
47
  * @param namespace - also apply the edits of this namespace, like `search` for search records
48
48
  */
49
49
  export declare function createStringifier(file: VFile, namespace?: 'search' | (string & {})): Stringifier;
50
+ /**
51
+ * A Markdown table with aligned columns, its first row is the header.
52
+ *
53
+ * @param rows - the cells of each row, as inline Markdown
54
+ */
55
+ export declare function markdownTable(rows: string[][]): string;
50
56
  //#endregion
@@ -193,6 +193,26 @@ function createStringifier(file, namespace) {
193
193
  }
194
194
  return s;
195
195
  }
196
+ /**
197
+ * A Markdown table with aligned columns, its first row is the header.
198
+ *
199
+ * @param rows - the cells of each row, as inline Markdown
200
+ */
201
+ function markdownTable(rows) {
202
+ const widths = [];
203
+ const table = rows.map((row) => row.map((cell, i) => {
204
+ let text = cell.trim();
205
+ if (/[\n|]/.test(text)) text = text.replace(/\s*\n\s*|(?<!\\)\|/g, (s) => s === "|" ? "\\|" : " ");
206
+ widths[i] = Math.max(widths[i] ?? 3, text.length);
207
+ return text;
208
+ }));
209
+ const line = (row) => `| ${widths.map((w, i) => (row[i] ?? "").padEnd(w)).join(" | ")} |`;
210
+ return [
211
+ table[0],
212
+ widths.map((w) => "-".repeat(w)),
213
+ ...table.slice(1)
214
+ ].map(line).join("\n");
215
+ }
196
216
  const containerPrefixRegex = /^(?:[ \t]*(?:>|[-*+](?=[ \t])|\d{1,9}[.)](?=[ \t])))*[ \t]*/;
197
217
  /** the prefix of the containers (e.g. lists & blockquotes) at `start`, on the lines after the first */
198
218
  function containerPrefix(source, start) {
@@ -214,4 +234,4 @@ function dedent(source, start, text) {
214
234
  return text.replace(new RegExp(`\\n(?:${prefix}|${prefix.trimEnd()}(?=\\r?\\n|$))`, "g"), "\n");
215
235
  }
216
236
  //#endregion
217
- export { createStringifier, embedSource, replaceSource };
237
+ export { createStringifier, embedSource, markdownTable, replaceSource };
@@ -1,3 +1,4 @@
1
+ import { markdownTable } from "../mdx-plugins/stringifier.js";
1
2
  import { s as walk } from "../utils-2pZeFRk8.js";
2
3
  import { t as buildRegexFromQuery } from "../highlight-SXtD3BKk.js";
3
4
  import { remark } from "remark";
@@ -6,15 +7,9 @@ import { remark } from "remark";
6
7
  * A table row as structured data: a Markdown table of the row, after the header row of its table.
7
8
  */
8
9
  function tableRowToStructuredData({ table, heading, row, header }) {
9
- const formatRow = (cells) => {
10
- let out = "|";
11
- for (const cell of cells) out += ` ${cell.replace(/\s*\n\s*/g, " ").replace(/(?<!\\)\|/g, "\\|")} |`;
12
- return out;
13
- };
14
- const delimiter = `|${" --- |".repeat((header ?? row).length)}`;
15
10
  return {
16
11
  heading,
17
- content: header ? `${formatRow(header)}\n${delimiter}\n${formatRow(row)}` : `${formatRow(row)}\n${delimiter}`,
12
+ content: markdownTable(header ? [header, row] : [row]),
18
13
  table
19
14
  };
20
15
  }
package/dist/server.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { markdownTable } from "./mdx-plugins/stringifier.js";
1
2
  import { isValidElement } from "react";
2
3
  import { AsyncLocalStorage } from "node:async_hooks";
3
4
  //#region src/server.ts
@@ -214,6 +215,8 @@ function attribute(key, value) {
214
215
  return;
215
216
  }
216
217
  }
218
+ const ROW = "";
219
+ const CELL = "";
217
220
  const INLINE_TAGS = /* @__PURE__ */ new Set([
218
221
  "a",
219
222
  "abbr",
@@ -323,24 +326,18 @@ async function host(tag, props, state) {
323
326
  case "hr": return "\n---\n\n";
324
327
  case "br": return "\n";
325
328
  case "table": {
326
- const rows = (await children({ inline: false })).replace(/\n\s*\n/g, "\n").trim();
327
- if (rows.length === 0) return "";
328
- const end = rows.indexOf("\n");
329
- const first = end === -1 ? rows : rows.slice(0, end);
330
- return `\n${first}\n${separatorRow(first)}${end === -1 ? "" : rows.slice(end)}\n\n`;
329
+ const rows = [];
330
+ for (const row of (await children({ inline: false })).split(ROW).slice(1)) rows.push(row.split(CELL).slice(1));
331
+ return rows.length === 0 ? "" : `\n${markdownTable(rows)}\n\n`;
331
332
  }
332
- case "tr": return `|${await children({ inline: false })}\n`;
333
+ case "tr": return `${ROW}${await children({ inline: false })}`;
333
334
  case "th":
334
- case "td": return ` ${(await children({ inline: true })).trim().replace(/\s*\n\s*/g, " ").replaceAll("|", "\\|")} |`;
335
+ case "td": return `${CELL}${await children({ inline: true })}`;
335
336
  }
336
337
  if (INLINE_TAGS.has(tag)) return children({ inline: true });
337
338
  const c = (await children({ inline: false })).trim();
338
339
  return c.length === 0 ? "" : `\n${c}\n\n`;
339
340
  }
340
- function separatorRow(row) {
341
- const cells = Math.max(1, (row.match(/(?<!\\)\|/g)?.length ?? 2) - 1);
342
- return `|${" --- |".repeat(cells)}`;
343
- }
344
341
  function wrap(text, marker) {
345
342
  const [, lead, core, trail] = /^(\s*)([\s\S]*?)(\s*)$/.exec(text);
346
343
  return core ? `${lead}${marker}${core}${marker}${trail}` : text;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-core",
3
- "version": "16.17.0",
3
+ "version": "16.17.1",
4
4
  "description": "The React.js library for building a documentation website",
5
5
  "keywords": [
6
6
  "Docs",