Commit 5cf4c4d
authored
Tables: tolerate trailing whitespace on rows; reject empty delimiter cells (#247)
Two table delimiter-row divergences (carve-js and carve-rs agreed; the PHP
impl was the outlier), ported from carve-php commit 28d4c10:
1. Trailing whitespace after a row's closing pipe broke recognition. A line
like `| a |` followed by spaces, or a separator `|---|` followed by spaces,
was not treated as a table row, so a table with a trailing-whitespace
separator split into separate blocks and the separator rendered as a
paragraph. Trailing spaces/tabs after the closing pipe are now stripped
before the structural checks (isTableRow, isSeparatorRow, the cell parsers,
and the BlockParser row loop).
2. A delimiter row with an empty cell (`|---||`) was accepted as a header
separator. isSeparatorRow used a character class that put `|` inside it and
so never validated per cell. It now splits the row into cells and requires
each to be a delimiter cell (optional whitespace, optional leading `:`, one
or more `-`, optional trailing `:`); an empty cell or any other content
disqualifies the row, which then stays an ordinary data row.
Behavior now matches the JS and Rust implementations on these delimiter-row
edge cases.1 parent 39c56cc commit 5cf4c4d
3 files changed
Lines changed: 92 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
37 | 41 | | |
38 | 42 | | |
39 | 43 | | |
| |||
88 | 92 | | |
89 | 93 | | |
90 | 94 | | |
91 | | - | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
92 | 118 | | |
93 | 119 | | |
94 | 120 | | |
| |||
152 | 178 | | |
153 | 179 | | |
154 | 180 | | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
155 | 184 | | |
156 | 185 | | |
157 | 186 | | |
| |||
357 | 386 | | |
358 | 387 | | |
359 | 388 | | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
360 | 392 | | |
361 | 393 | | |
362 | 394 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2758 | 2758 | | |
2759 | 2759 | | |
2760 | 2760 | | |
2761 | | - | |
| 2761 | + | |
| 2762 | + | |
| 2763 | + | |
2762 | 2764 | | |
2763 | 2765 | | |
2764 | 2766 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
0 commit comments