mirror of
https://github.com/morluto/rea.git
synced 2026-11-12 17:59:08 +00:00
fix(cli): preserve Markdown validation error cells (#7978)
fix(cli): preserve markdown validation error cells
This commit is contained in:
1 parent
61bb02d3df
commit
e416ce1983
5 files changed
+339
-9
No files matched your search
@@ -357,20 +357,22 @@ const escapeMarkdownText = (value: string): string =>
|
||||
const markdownHeading = (path: readonly string[]): string =>
|
||||
`## ${escapeMarkdownText(path.join("."))}\n\n`;
|
||||
|
||||
/** Encode literal text for a Markdown table cell, including edge whitespace. */
|
||||
export const encodeMarkdownTableCell = (value: string): string =>
|
||||
escapeTableCell(value).replace(/^[ \t]+|[ \t]+$/g, (whitespace) =>
|
||||
encodeMarkdownWhitespace(whitespace),
|
||||
);
|
||||
|
||||
const renderTable = (
|
||||
headers: readonly string[],
|
||||
rows: readonly string[][],
|
||||
): string => {
|
||||
if (headers.length === 0) return "";
|
||||
const encodeTableCell = (value: string): string =>
|
||||
escapeTableCell(value).replace(/^[ \t]+|[ \t]+$/g, (spaces) =>
|
||||
encodeMarkdownWhitespace(spaces),
|
||||
);
|
||||
const escapedHeaders = headers.map(encodeTableCell);
|
||||
const escapedHeaders = headers.map(encodeMarkdownTableCell);
|
||||
const widths = escapedHeaders.map((header) => header.length);
|
||||
for (const row of rows) {
|
||||
for (let index = 0; index < escapedHeaders.length; index += 1) {
|
||||
const width = encodeTableCell(row[index] ?? "").length;
|
||||
const width = encodeMarkdownTableCell(row[index] ?? "").length;
|
||||
if (width > widths[index]!) widths[index] = width;
|
||||
}
|
||||
}
|
||||
@@ -384,7 +386,9 @@ const renderTable = (
|
||||
for (const row of rows) {
|
||||
lines.push(
|
||||
`| ${escapedHeaders
|
||||
.map((_, index) => pad(encodeTableCell(row[index] ?? ""), index))
|
||||
.map((_, index) =>
|
||||
pad(encodeMarkdownTableCell(row[index] ?? ""), index),
|
||||
)
|
||||
.join(" | ")} |`,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user