From 26dec86b70c8988e09e3bb2a678498b2dbdca200 Mon Sep 17 00:00:00 2001 From: milvasic Date: Mon, 23 Mar 2026 19:47:39 +0100 Subject: [PATCH] fix(markdown-table): handle escaped backslashes before pipe separators; use @/ alias in test import - Rewrite parseRow to count consecutive backslashes before each pipe so that `\\|` (escaped backslash + unescaped pipe) is correctly treated as a column separator. The previous lookbehind regex (? { - // Strip leading/trailing pipes and split by unescaped pipe. + // Strip leading/trailing pipes and split by pipes preceded by an even number + // of backslashes (0, 2, 4, …). A pipe preceded by an odd number of + // backslashes is an escaped pipe and must not be treated as a column + // separator. The simpler regex (? cell.trim().replace(/\\\|/g, "|")); + + const cells: string[] = []; + let cellStart = 0; + for (let i = 0; i < trimmed.length; i++) { + if (trimmed[i] === "|") { + let backslashes = 0; + let j = i - 1; + while (j >= 0 && trimmed[j] === "\\") { + backslashes++; + j--; + } + if (backslashes % 2 === 0) { + cells.push(trimmed.slice(cellStart, i).trim().replace(/\\\|/g, "|")); + cellStart = i + 1; + } + } + } + cells.push(trimmed.slice(cellStart).trim().replace(/\\\|/g, "|")); + return cells; }; const headers = parseRow(lines[0]);