fix(tostring): recurse into nested inline elements inside bold/italic#485
Merged
OXY2DEV merged 1 commit intoOXY2DEV:mainfrom Mar 20, 2026
Merged
Conversation
md_str.bold(), md_str.italic(), and md_str.bold_italic() stripped their delimiter characters but returned the raw inner text without further processing. This meant nested inline constructs like links, images, or code spans inside emphasis were never resolved. For example, **[bold link](https://example.com)** produced the visual string "[bold link](https://example.com)" (width 32) instead of the correct " bold link" (width 11), causing massive column width miscalculations in rendered tables. Pass the stripped inner text through md_str.tostring() so that nested inline elements (hyperlinks, images, code spans, etc.) are properly reduced to their visual representation. This mirrors the established pattern already used in the sibling module visual_text.lua, where md_delims_star() calls visual.markdown(inner).
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
md_str.bold(),md_str.italic(), andmd_str.bold_italic()in thetostringmodule strip their delimiter characters but return the raw inner text without further processing. Nested inline constructs (links, images, code spans, etc.) inside emphasis are never resolved to their visual representation.tostringreturned**[bold link](https://example.com)**[bold link](https://example.com)(width 32) bold link(width 11)**[bold link with long URL](https://…long…)** bold link with long URL(width 25)*[italic link](url)*[italic link](url) italic linkThis causes massive column width miscalculations in rendered tables.
Fix
Pass the stripped inner text through
md_str.tostring()so that nested inline elements are properly reduced. Three one-line changes:This mirrors the established pattern in the sibling module
visual_text.lua, wheremd_delims_star()callsvisual.markdown(inner).Performance
The recursive
lpeg.matchonly fires on cells where bold/italic actually wraps another inline element — a small subset in practice. Benchmarked overhead on representative table cells:Verification