fix: handle escaped pipes (\|) in table cells#12
Open
maou-shonen wants to merge 1 commit intofranlol:mainfrom
Open
fix: handle escaped pipes (\|) in table cells#12maou-shonen wants to merge 1 commit intofranlol:mainfrom
maou-shonen wants to merge 1 commit intofranlol:mainfrom
Conversation
0e2c970 to
a91bca8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Tables with escaped pipes (
\|) in cell content don't get formatted. The formatter treats\|as a column separator, which inflates the column count for that row. Since the separator row (| --- | --- |) has fewer columns,isValidTable()sees a mismatch and rejects the whole table.For example, this 3-column table:
The data row gets parsed as 5 columns (splitting on every
|including the escaped ones), but the header and separator have 3 — so the formatter skips it and appends<!-- table not formatted: invalid structure -->.Cause
All 4 call sites use
.split("|")which doesn't distinguish between real delimiters and escaped pipes:isTableRow()— column count checkisSeparatorRow()— cell extractionisValidTable()— row parsingformatTable()— row parsingFix
Added a
splitByUnescapedPipe()helper that uses a negative lookbehind regex to split on|only when it's not preceded by\. Replaced all.split("|")calls with it.Test script
You can verify with the test below — run it against the repo before and after the fix:
Before fix: 1 passed, 5 failed. After fix: 6 passed, 0 failed.