Skip to content

parser: keep words and single spaces in one CommonMark text token - #373

Merged
kjk merged 1 commit into
gomarkdown:masterfrom
g4lb:commonmark-text-spaces
Nov 7, 2026
Merged

kjk merged 1 commit into
gomarkdown:masterfrom
g4lb:commonmark-text-spaces

Conversation

@g4lb

@g4lb g4lb commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

In CommonMark mode, commonMarkInline ends a text token at each space. A paragraph then becomes one text node for each word. This change keeps a single space between two words in the same token. A space run, or a space before a tab or a line break, still goes to the hard break code. The HTML output and the AST do not change.

CommonMark ToHTML Apple M5 Xeon 6975P Allocs
Plain paragraphs -67 to -68% -64 to -66% 21,040 → 3,640
README.md -38 to -41% -38% 9,801 → 3,786
Markdown Syntax doc -44 to -46% -42% 15,506 → 5,039
Table, 300 rows -31 to -36% -31% 16,604 → 10,579

I used 3 code layouts, 24 interleaved rounds and benchstat, with Go 1.26.5 on M5 and Go 1.27.3 on Xeon. On Xeon, 1,000 lines that end with one space are +0.5% to +0.9%, about 2 ns for each line. On M5, they show no change. The default parser does not use this code.

Checks:

  • go test -race ./... passes. go test ./... passes with Go 1.22.
  • FuzzCommonMark ran for 60 seconds with no failure.
  • Old and new output matched on 1,000,000 generated inputs in 6 parser and renderer settings.

@kjk
kjk merged commit 86e75bb into gomarkdown:master Nov 7, 2026
1 check passed
@kjk

kjk commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

Amazing change! Thanks!

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