Repository navigation
fix(editor): render the first block of a file that starts with a BOM - #209
Merged
Merged
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
A file that starts with a UTF-8 BOM did not render its first block.
# Titlebehind a BOM stayed plain text, a first- itemwas 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 buffer and the file are untouched. The BOM was already preserved byte for byte by the covenant, only the analysis was wrong.
Tests
h1on (3, 12).|.src/testdata/bom-ejemplo.md(BOM + heading + list), picked up automatically bytests/covenant.rsfor the round trip.make checkgreen: fmt, clippy-D warnings, 217 unit tests, integration suites and the 3 version checks.