Skip to content

fix(renderer): fix table column width miscalculation in markdown.output()#476

Closed
jujuyuzu wants to merge 1 commit intoOXY2DEV:mainfrom
jujuyuzu:fix/table-width-calculation
Closed

fix(renderer): fix table column width miscalculation in markdown.output()#476
jujuyuzu wants to merge 1 commit intoOXY2DEV:mainfrom
jujuyuzu:fix/table-width-calculation

Conversation

@jujuyuzu
Copy link
Copy Markdown

Problem

Table borders () disappear on specific rows where cell content contains:

  • Mid-word underscores: json_serializable, mock_template_repository
  • Inline code with Lua pattern special chars (related cleanup)

Reproduction

| Item                                                                     | Difficulty |
| ------------------------------------------------------------------------ | ---------- |
| Extract AccordionCard from workout detail + template detail              | Medium     |
| `catch (_)``firstWhereOrNull` in mock_template_repository                 | Easy       |
| Remove unused pubspec deps (json_serializable, riverpod_generator, etc.) | Easy       |
| SetHeaderRow: add `readOnly` param to hide dropdown                        | Easy       |
image

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 like
json_serializable. CommonMark/GFM spec says _ emphasis requires word
boundaries. Treesitter correctly ignores mid-word _, but
markdown.output() strips them → width mismatch → broken borders.

2. corner_left typo (8 occurrences)

corner_left used where corner_right was intended — the last element
in concat() calls after padding_right. Affects inline code, highlights,
email, and URI handlers.

3. Redundant vim.pesc() inside concat()

concat() (line 27-33) already calls vim.pesc() on every element.
Three call sites additionally wrapped arguments with vim.pesc() before
passing to concat(), causing double-escaping and potential match failures.

Fix

  • Add word-boundary check for italic _: skip when _ is preceded or
    followed by %w (alphanumeric), matching CommonMark rules
  • Fix corner_leftcorner_right in all 8 affected locations
  • Remove redundant vim.pesc() calls in 3 locations

…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.
@OXY2DEV
Copy link
Copy Markdown
Owner

OXY2DEV commented Mar 11, 2026

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants