fix(renderer): fix table column width miscalculation in markdown.output()#476
Closed
jujuyuzu wants to merge 1 commit intoOXY2DEV:mainfrom
Closed
fix(renderer): fix table column width miscalculation in markdown.output()#476jujuyuzu wants to merge 1 commit intoOXY2DEV:mainfrom
jujuyuzu wants to merge 1 commit intoOXY2DEV:mainfrom
Conversation
…ut() Bugs in markdown.output() caused incorrect table column width calculation, resulting in missing table borders: 1. corner_left used instead of corner_right (copy-paste typo) in inline code, highlights, email, and URI replacement and decoration width calculations. 2. Italic underscore pattern %_(.-)%_ too aggressive — matches mid-word underscores (e.g. json_serializable, mock_template_repository) which CommonMark/GFM does not treat as emphasis. This caused markdown.output() to strip underscores that treesitter correctly preserves, resulting in width mismatch. Added word-boundary check: skip when _ is preceded or followed by an alphanumeric character. 3. Removed redundant vim.pesc() calls inside concat() — the concat() helper already escapes all elements via vim.pesc(), so passing pre-escaped strings caused double-escaping and match failures.
Owner
|
@jujuyuzu thanks for the commit. The original pattern approach was error-prone, slow and had portability issues. I have re-written it to address all of these issues(including the bug mentioned in this commit). Give it a try. |
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
Table borders (
│) disappear on specific rows where cell content contains:json_serializable,mock_template_repositoryReproduction
Rows 2 and 3 lose their left/middle borders. Rows 1 and 4 render correctly.
Root Cause
Three bugs in
markdown.output()(used for table column width calculation):1. Overly aggressive italic
_matching (line 244)%_(.-)%_matches mid-word underscores in identifiers likejson_serializable. CommonMark/GFM spec says_emphasis requires wordboundaries. Treesitter correctly ignores mid-word
_, butmarkdown.output()strips them → width mismatch → broken borders.2.
corner_lefttypo (8 occurrences)corner_leftused wherecorner_rightwas intended — the last elementin
concat()calls afterpadding_right. Affects inline code, highlights,email, and URI handlers.
3. Redundant
vim.pesc()insideconcat()concat()(line 27-33) already callsvim.pesc()on every element.Three call sites additionally wrapped arguments with
vim.pesc()beforepassing to
concat(), causing double-escaping and potential match failures.Fix
_: skip when_is preceded orfollowed by
%w(alphanumeric), matching CommonMark rulescorner_left→corner_rightin all 8 affected locationsvim.pesc()calls in 3 locations