Skip to content

fix(tostring): account for tag decoration in table column width#517

Merged
OXY2DEV merged 1 commit into
OXY2DEV:mainfrom
ImmanuelHaffner:fix-tostring-tag-width
Jul 3, 2026
Merged

fix(tostring): account for tag decoration in table column width#517
OXY2DEV merged 1 commit into
OXY2DEV:mainfrom
ImmanuelHaffner:fix-tostring-tag-width

Conversation

@ImmanuelHaffner

@ImmanuelHaffner ImmanuelHaffner commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

A #-prefixed token in a table cell (#foo, #bug, #51) is parsed as an Obsidian-style tag. The tag renderer conceals the leading # and injects padding_left/padding_right (and, if configured, corner/icon) as inline virtual text, so the rendered cell is wider than its raw text. The table column-width calculation, however, runs through renderers/markdown/tostring.lua, which had no tag handler: it measured the raw text (#foo = 4 columns) and was blind to the conceal + padding. The mismatch drifted the cell's right border (about +1 per tag cell with the default padding).

This is not limited to numeric refs -- #foo drifts exactly like #51. The cause is the missing tag-width accounting in tostring, not whether the tag body is numeric (the separate question of whether purely-numeric #123 should be a tag at all, per Obsidian, is orthogonal and left unchanged).

Fix: give tostring a tag handler that mirrors the renderer -- strip the #, resolve the tag config via utils.match, and emit corner_left + padding_left + icon + label + padding_right + corner_right -- plus an lpeg tag pattern guarded like the parser (start/after-whitespace, not an internal-link #^section). The computed width now matches what is drawn.

A `#`-prefixed token in a table cell (`#foo`, `#bug`, `OXY2DEV#51`) is parsed as an Obsidian-style tag. The tag renderer conceals the leading `#` and injects padding_left/padding_right (and, if configured, corner/icon) as inline virtual text, so the rendered cell is wider than its raw text. The table column-width calculation, however, runs through renderers/markdown/tostring.lua, which had no tag handler: it measured the raw text (`#foo` = 4 columns) and was blind to the conceal + padding. The mismatch drifted the cell's right border (about +1 per tag cell with the default padding).

This is not limited to numeric refs -- `#foo` drifts exactly like `OXY2DEV#51`. The cause is the missing tag-width accounting in tostring, not whether the tag body is numeric (the separate question of whether purely-numeric `OXY2DEV#123` should be a tag at all, per Obsidian, is orthogonal and left unchanged).

Fix: give tostring a tag handler that mirrors the renderer -- strip the `#`, resolve the tag config via utils.match, and emit corner_left + padding_left + icon + label + padding_right + corner_right -- plus an lpeg tag pattern guarded like the parser (start/after-whitespace, not an internal-link `#^section`). The computed width now matches what is drawn.

Renames the fixture to test/table_ref_tag_drift.md and generalizes it: non-numeric tags drift too, and the repro documents the tostring root cause.
@ImmanuelHaffner ImmanuelHaffner force-pushed the fix-tostring-tag-width branch from fcb71a1 to 62de491 Compare July 3, 2026 16:28
@OXY2DEV OXY2DEV merged commit a2a0715 into OXY2DEV:main Jul 3, 2026
1 check passed
@ImmanuelHaffner ImmanuelHaffner deleted the fix-tostring-tag-width branch July 3, 2026 18:43
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