Skip to content

Stop Markdown inserting a space where inline runs touch [patch] - #642

Merged
matt-edmondson merged 2 commits into
mainfrom
fix/markdown-glued-inline-runs
Oct 18, 2026
Merged

matt-edmondson merged 2 commits into
mainfrom
fix/markdown-glued-inline-runs

Conversation

@matt-edmondson

@matt-edmondson matt-edmondson commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #480

What

InlineLayout.Wrap added spaceWidth before every token except the first on a line. Emphasis, inline code and links each split the text into separate runs, so a gap appeared at every one of those boundaries:

Source Before After
**Note**: text Note : text Note: text
`a`b a b ab
[docs](u). docs . docs.
a**b**c a b c abc

Change

  • Tokenize walks all the runs and flags each token that had whitespace before it in the source: a space inside the run, at the end of the previous run, or at the start of this one. The soft-break " " run counts as whitespace. An empty run is skipped, so it doesn't look like a space. Images follow the same rule.
  • SplitGluedWords groups the flagged tokens into words.
  • Wrap places one word at a time. It measures the whole word, adds a space only between words, and breaks lines only between words, so a line can no longer break between docs and its .. Each token keeps its own role and link, so fonts and link hit-tests are unchanged.

This doesn't address hard line breaks (#481), which are tracked separately.

Tests

tests/ImGui.Markdown.Tests/InlineLayoutTests.cs gets seven new tests:

  • **x**:, `a`b, [l](u). and a**b**c each check the token x positions, which no longer contain a phantom space.
  • Whitespace at run boundaries ("ab ", "cd", " ef") still separates tokens. This guards against over-gluing.
  • An empty run between two touching runs keeps them glued.
  • At a width that fits aaa docs but not aaa docs., docs. moves to the next line together.

I restored the original InlineLayout.cs and ran the tests again: the boundary tests fail and the whitespace guard passes. With the fix, ImGui.Markdown.Tests passes 49/49. CI is green on all three OSes, including ImGuiMarkdownDemo.UITests. Those demo tests fail locally only because this container gets the image assets as Git LFS pointer stubs.

🤖 Generated with Claude Code

https://claude.ai/code/session_018Cibp2qAPg69KcG7TXtUeH

matt-edmondson and others added 2 commits October 17, 2026 13:40
InlineLayout.Wrap put a space before every token but the first on a
line, so the run boundaries an emphasis, inline code or link creates
drew as gaps: "**Note**:" became "Note :" and "[docs](u)." became
"docs .". Wrap now groups tokens with no source whitespace between
them, across runs, into one word that gets no inner spacing and wraps
as a unit, so a line can no longer break inside a glued sequence.

Fixes #480

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Cibp2qAPg69KcG7TXtUeH
SonarCloud flagged SplitGluedWords at cognitive complexity 19. The
whitespace tracking moves into Tokenize, which yields each token with a
space-before flag, and SplitGluedWords only groups. Tokenize also skips
an empty text run, which would otherwise have read as whitespace and
split the runs either side of it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018Cibp2qAPg69KcG7TXtUeH
@sonarqubecloud

Copy link
Copy Markdown

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.

Markdown inserts a space wherever bold, code or a link touches adjacent text: "**Note**:" draws as "Note :"

1 participant