Skip to content

fix(editor): render the first block of a file that starts with a BOM - #209

Merged
gnacho merged 1 commit into
masterfrom
fix/bom-analyze
Nov 21, 2026
Merged

gnacho merged 1 commit into
masterfrom
fix/bom-analyze

Conversation

@gnacho

@gnacho gnacho commented Nov 20, 2026

Copy link
Copy Markdown
Owner

What

A file that starts with a UTF-8 BOM did not render its first block. # Title behind a BOM stayed plain text, a first - item was not a list item and a table that opened the file was not a table. Closes #208, and documents the BOM behaviour asked about in #206.

Why

pulldown-cmark 0.12.2 does not skip a leading U+FEFF. analyze() handed it the document as it was, so the first line started with the BOM instead of the block marker.

Fix

  • analyze() strips a leading BOM before parsing and adds its byte length back to every byte offset it returns: spans, images, links, unclosed fences, table pads and break marks. Line-keyed ornaments are unchanged because the BOM adds no line.
  • close_unclosed_fences() gets the same offset correction, so an unclosed fence on the first line is still closed in place.
  • The split preview strips the BOM too, so editor and panel agree.
  • README (EN/ES): a leading UTF-8 BOM is kept as it is and Scribe never adds one.

The buffer and the file are untouched. The BOM was already preserved byte for byte by the covenant, only the analysis was wrong.

Tests

  • Property test: the analysis of a document with a BOM equals the analysis without it with every byte offset shifted by 3 (spans, inline element ranges, images, links, ornaments).
  • First heading with a BOM renders as h1 on (3, 12).
  • Table at the top with a BOM keeps its grid pads anchored on their |.
  • Unclosed fence behind a BOM closes in the right place (red without the shift).
  • Split preview: heading behind a BOM is a heading and the BOM does not leak into the painted text.
  • New fixture src/testdata/bom-ejemplo.md (BOM + heading + list), picked up automatically by tests/covenant.rs for the round trip.

make check green: fmt, clippy -D warnings, 217 unit tests, integration suites and the 3 version checks.

…208)

pulldown-cmark does not skip a leading U+FEFF, so a file that begins with a
BOM parsed its first line as a paragraph: no heading, no list item, no
table. The buffer and the file were never touched (the bytes covenant
already kept the BOM), only the analysis was wrong.

analyze() now drops a leading BOM before parsing and adds its length back to
every byte offset it returns: spans, images, links, unclosed fences, table
pads and break marks. Ornaments keyed by line do not change because the BOM
adds no line. close_unclosed_fences() and the split preview get the same
treatment.

Tests: property test (analysis with BOM equals analysis without it shifted
by 3), heading with BOM, table pads with BOM, fence closing with BOM (red
without the shift), preview heading with BOM, and a src/testdata fixture so
the byte covenant exercises the round trip. READMEs note that a BOM is kept
and never added.

Closes #208
Closes #206
@gnacho
gnacho merged commit 439622d into master Nov 21, 2026
3 checks passed
@gnacho
gnacho deleted the fix/bom-analyze branch November 21, 2026 10:00
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.

A leading UTF-8 BOM stops the first block from rendering

1 participant