Nest inline markers instead of crossing them - #98
Merged
Conversation
A style applied across part of an existing emphasis run serialized as crossing delimiters, `*hello ~~there*~~`, which no markdown parser reads back. The markers landed in the reloaded document as literal characters and the styling was lost. toMarkdown now builds typed runs, splits any partially overlapping pair at the crossing point, and emits through a stack so every close mirrors its open. Links are never split, since that would emit the destination twice.
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 27 |
| Duplication | 0 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
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.
The bug
Markdown delimiters can only nest.
AnnotatedString.toMarkdownsorted style boundaries by run length and emitted them blind, so a style applied across part of an existing emphasis run came out as crossing delimiters:No parser reads that back as emphasis. On the next import the markers landed in the document as literal characters and the styling was gone:
It reproduced for a style inside an emphasis run, over the head or tail of one, and crossing a link. Strikethrough is where it shows up in practice, because striking part of a line of italic dialogue is a natural edit, but nothing about it is strikethrough-specific.
The fix
toMarkdownnow:MarkerRuns rather than loose boundaries,Where markdown genuinely cannot express a crossing, the run is split and both styles survive over exactly the text they covered:
Testing
New
CrossingSpanSerializationTestcovers the six shapes, asserting the reloaded text is byte-identical and the markers balance.Full
:ComposeTextEditor:desktopTestsuite: 1052 tests, 0 failures.