Markdown, YAML and XML: when whitespace becomes syntax

The same U+00A0 may be harmless in Markdown prose, break an expected separation in YAML and remain text inside an XML element. Position and grammar define its role; a universal replacement has neither context.
Markdown is position-sensitive
Indentation creates lists and code blocks, while trailing spaces can affect line breaks. CommonMark defines ASCII space and tab in syntactic positions. An NBSP copied before a list marker looks blank but need not count as indentation.
YAML forbids tabs for indentation
YAML structure uses space indentation. A tab cannot indent a node, although it can occur in some quoted content. Replacing every tab can change literal values; repair the parser-reported position only.
XML has a strict character repertoire
XML 1.0 accepts UTF-8 and UTF-16, normalizes line endings and excludes most C0 controls. Text and attributes also follow escaping rules. Deleting a character before parsing can hide corruption rather than explain it.
Parser first, editor second
Preserve a minimal sample and the exact line-and-column error. Reveal spaces, tabs, CR and LF. Change one character and run the same parser again. A visually tidy editor view is not proof of validity.
Do not clean code blocks as prose
A Markdown document may contain YAML front matter, an XML example and a fenced code block. The outer grammar must not rewrite embedded languages. Automated repair should use a syntax tree or a format-specific linter.
Measure a round trip
After repair, parse, serialize and parse again with the same meaning. Compare keys, values and ordering where relevant. Keep the source beside the formatted copy and review the diff.
One character in three contexts
Here key and value are separated by NBSP, not ASCII space. The cleaner exposes the code point; the YAML parser confirms whether the targeted replacement restores the intended grammar.
const source = "key:\u00A0value";
console.log([...source].map(c => "U+" + c.codePointAt(0).toString(16).toUpperCase()));
// Replace only after confirming parser position and expected grammar.Repair order
- Identify format and version.
- Capture the parser error.
- Reveal whitespace and code points.
- Change the smallest region.
- Repeat parse → serialize → parse and inspect the diff.
Sources and specifications
Related guides
- C0/C1 control characters: what lives between U+0000 and U+009F
- NBSP and narrow spaces
- Hidden characters in code and JSON
Author: Mykola. Highlighting locates a character; format-specific parsers determine Markdown, YAML and XML validity.