Skip to content

fix(tostring): add footnote pattern to LPeg parser for correct table column widths#484

Merged
OXY2DEV merged 1 commit intoOXY2DEV:mainfrom
ImmanuelHaffner:fix/tostring-footnote-pattern
Mar 20, 2026
Merged

fix(tostring): add footnote pattern to LPeg parser for correct table column widths#484
OXY2DEV merged 1 commit intoOXY2DEV:mainfrom
ImmanuelHaffner:fix/tostring-footnote-pattern

Conversation

@ImmanuelHaffner
Copy link
Contributor

Problem

The tostring module (lua/markview/renderers/markdown/tostring.lua) is used to compute the visual (post-conceal) width of table cells for column alignment. It had no pattern for footnote references like [^1] or [^label].

These fell through to the hyperlink_no_src pattern, which strips [ and ] but keeps the ^ character, producing a visual string one character too wide.

Input tostring returned Actual renderer shows Width error
[^1] 󰌷 ^1 (width 4) 󰯓 1 (width 3) +1
[^long-descriptive-footnote-name] 󰌷 ^long-descriptive-footnote-name (width 37) 󰯓 long-descriptive-footnote-name (width 36) +1

This caused misaligned columns in any table row containing footnote references.

Fix

Add a dedicated footnote LPeg pattern and capture function that:

  • Matches [^label] syntax, placed before hyperlink in the token priority list
  • Strips [^ and ] delimiters, matching the actual renderer behavior (markdown_inline.lua conceals 2 bytes [^ and 1 byte ])
  • Looks up the footnote config for icon/corner/padding decorations
  • Returns the correct visual string for width measurement

Verification

✅ [^1]              → width=3  (was 4)
✅ [^abc]            → width=5  (was 6)
✅ [^long-label]     → width=49 (was 50)
✅ [link](url)       → unchanged
✅ [text]            → unchanged
✅ ![img](url)       → unchanged

…column widths

The tostring module (used for table column width calculation) had no
pattern for footnote references like [^1] or [^label].  These were
falling through to hyperlink_no_src, which strips [ and ] but keeps
the ^ character, producing a width 1 character too wide.

Add a dedicated footnote LPeg pattern that:
- Matches [^label] syntax (placed before hyperlink in token priority)
- Strips [^ and ] delimiters (matching actual renderer behavior)
- Looks up footnote config for icon/corner/padding decorations
- Returns the correct visual string for width measurement

This fixes misaligned table columns for rows containing footnote
references.
@OXY2DEV OXY2DEV merged commit 0509437 into OXY2DEV:main Mar 20, 2026
1 check passed
@ImmanuelHaffner ImmanuelHaffner deleted the fix/tostring-footnote-pattern branch March 20, 2026 14:51
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