Skip to content

Commit 142f8f0

Browse files
fix(prd): escape a backslash in a PRD title so the index row keeps its columns (#155)
cell() escaped `|` but not `\`, so a title holding `a\|b` was written as `a\\|b` — an escaped backslash followed by a live pipe, which splits the cell and shifts every column after it. That is the exact break the comment above cell() says it is preventing. A newline in a title was not handled at all and ended the table row outright. Escape the backslash before the pipe, and flatten newlines to a space. Co-authored-by: clawedassistant26 <307253840+clawedassistant26@users.noreply.github.com>
1 parent d659f1e commit 142f8f0

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

src/prd.mjs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,14 @@ export function regenerateIndex(root = process.cwd()) {
249249
try { body = fs.readFileSync(readme, "utf8"); } catch { return false; }
250250
const prds = listPrds(root);
251251
// A `|` in a title would close its table cell early and shift every column
252-
// after it, so escape it for the markdown table.
253-
const cell = (text) => String(text).replace(/\|/g, "\\|");
252+
// after it, so escape it for the markdown table. Escape `\` first: escaping
253+
// the pipe alone turns `a\|b` into `a\\|b`, which markdown reads as an escaped
254+
// backslash followed by a *live* pipe — the very break this is preventing.
255+
// A newline would end the row outright, so flatten it to a space.
256+
const cell = (text) => String(text)
257+
.replace(/\\/g, "\\\\")
258+
.replace(/\|/g, "\\|")
259+
.replace(/\r\n?|\n/g, " ");
254260
const rows = prds.length
255261
? ["| # | Title | Status |", "|---|---|---|",
256262
...prds.map((p) => `| [${p.id}](${p.file}) | ${cell(p.title)} | ${cell(p.status)} |`)].join("\n")

test/prd-index-cell.test.mjs

7.35 KB
Binary file not shown.

0 commit comments

Comments
 (0)