Skip to content

Commit 900cbf6

Browse files
heavygeeHAPI
andcommitted
fix(web): handle double-backtick code spans and preserve tree root on re-parse
- countSourceCells: use /`+[^`]*?`+/g so double-backtick spans like `` `a | b` `` are also stripped before counting column boundaries - remarkRepairTables: Object.assign(tree, newTree) instead of only copying children, so position/data from the root node are preserved via [HAPI](https://hapi.run) Co-Authored-By: HAPI <noreply@hapi.run>
1 parent b04947a commit 900cbf6

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

web/src/lib/remark-repair-tables.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import type { VFile } from 'vfile'
2222
* Skips escaped pipes (\|) which are literal characters, not cell boundaries. */
2323
function countSourceCells(line: string): number {
2424
// Replace code spans with a placeholder so any | inside them is invisible
25-
const trimmed = line.trim().replace(/`[^`]*`/g, '\x00')
25+
const trimmed = line.trim().replace(/`+[^`]*?`+/g, '\x00')
2626
const inner = trimmed.startsWith('|') ? trimmed.slice(1) : trimmed
2727
const stripped = inner.endsWith('|') ? inner.slice(0, -1) : inner
2828
let cells = 1
@@ -142,6 +142,6 @@ export default function remarkRepairTables(this: Processor) {
142142
// Re-parse with the repaired source so remark-gfm produces table nodes
143143
// processor.parse() runs only the parse phase, not transformers
144144
const newTree = processor.parse(repaired) as Root
145-
tree.children = newTree.children
145+
Object.assign(tree, newTree)
146146
}
147147
}

0 commit comments

Comments
 (0)