Skip to content

YAML: recognize non-breaking spaces - #3209

Merged
birkenfeld merged 4 commits into
pygments:masterfrom
Sanjays2402:fix/yaml-non-breaking-spaces
Jul 16, 2026
Merged

YAML: recognize non-breaking spaces#3209
birkenfeld merged 4 commits into
pygments:masterfrom
Sanjays2402:fix/yaml-non-breaking-spaces

Conversation

@Sanjays2402

Copy link
Copy Markdown
Contributor

YAML permits U+00A0 in scalar content, but the lexer emitted an Error token for it. This recognizes non-breaking spaces in block, flow, and quoted scalars and adds a golden regression test.

Fixes #2827

YAML permits U+00A0 in scalar content, but the scalar rules treated it as
unmatched whitespace and emitted an Error token. Recognize it as scalar
content in block, flow, and quoted scalars, with a golden regression test.

Fixes pygments#2827
Comment thread pygments/lexers/data.py Outdated
# line breaks are ignored
(r'\n+', Whitespace),
# non-breaking spaces are a part of the value
(r'\xa0+', Name.Variable),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we combine this with the rule below?

Match regular and non-breaking spaces in one rule since both produce the same token.
@Sanjays2402

Copy link
Copy Markdown
Contributor Author

@birkenfeld Combined the adjacent quoted-scalar rules in c45b3c1f; regular and non-breaking spaces now share one [ \\xa0]+ expression with the same Name.Variable action.

Verification: the YAML regression passed, and the full suite is green: 5,296 passed, 16 skipped.

Refresh the changelog from current master and retain this PR's entry in alphabetical order.
Resolve the sorted changelog against current master while preserving this PR's YAML entry.
@birkenfeld
birkenfeld merged commit bc57a65 into pygments:master Jul 16, 2026
17 checks passed
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.

YAML lexer has trouble with non-breaking spaces

2 participants