[Super Editor] - Markdown: Preserve code fence language and serialize fence content literally (Resolves #3006) - #3081
Closed
donaldheppner wants to merge 3 commits into
Conversation
… re-parses to the same styled text
Rewrites AttributedTextMarkdownSerializer so its output re-parses to the
same styled text:
- Trim whitespace at the edges of bold/italic/strikethrough/code spans
outside the style markers ("**bold **" -> "**bold** "); whitespace-
bounded markers are not valid CommonMark emphasis, so the styling
silently vanished on the next parse (Flutter-Bounty-Hunters#2424, Flutter-Bounty-Hunters#2650).
- Preserve backslash escapes: parsing "3\*4" records a markdownEscape
attribution on the "*" and serialization re-emits the backslash.
- Serialize overlapping (non-nested) spans by closing and re-opening
styles so markers nest properly; open same-offset styles longest-span
first; merge adjacent same-style spans instead of emitting "**a****b**".
- Safety net: re-parse the output and compare; if styles don't survive,
escape markdown-significant characters (protects "3*4 and 5*6" from
gaining emphasis).
- Escape block-level triggers at plain-paragraph line starts ("# ", "> ",
"- ", "1. ", fences, thematic breaks) so paragraphs don't change block
type on the next parse.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…derline as "<u>" (parse legacy forms) - Strikethrough serializes as GFM "~~text~~" instead of the non-standard single "~". The parser still accepts the legacy single-tilde form, which heals to "~~" on the next serialization. - Underline serializes as "<u>text</u>" instead of the proprietary "¬text¬" marker; inline HTML tags are the only widely supported way to express underline in Markdown. The parser accepts both, so legacy "¬" content heals to "<u>" on the next save. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
… fence content literally (Resolves Flutter-Bounty-Hunters#3006) - Parse the fence info string ("```dart") into the code node's codeLanguage metadata and re-emit it on serialization. Previously the language was silently dropped on the first round trip. - Serialize fence content as literal plain text instead of routing it through the inline markdown serializer, which appended two-space hard-break markers to every line (compounding on every round trip) and backslash-escaped code content. - Strip the single trailing newline the parser stores for fenced code so the fence doesn't grow a blank line on every round trip. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Author
|
Closing — opened prematurely from our fork's staging branches. Apologies for the noise. |
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 this does
Fixes fenced code blocks corrupting on every serialize/parse round trip (Resolves #3006):
toPlainText()instead of routing through the inline Markdown serializer. The inline path appended two-space hard-break markers to every line — one more" "per line per round trip, compounding exactly as described in [BUG] - [Markdown] - Fenced code blocks accumulate trailing whitespace on every parse → serialize round-trip #3006 — and backslash-escaped code content.```on every round trip (the second symptom in [BUG] - [Markdown] - Fenced code blocks accumulate trailing whitespace on every parse → serialize round-trip #3006). This matches the fix proposed in the issue body.```dartstoresdartin the code node'scodeLanguagemetadata (from thelanguage-class the block parser produces), and serialization re-emits it. Previously the language was silently dropped on the first round trip.Tests
New serialization and deserialization cases in
super_editor_markdown_test.dart: language preservation both directions, literal (unescaped) fence content, andcodeLanguagemetadata absent for bare fences.PR 3 of the Markdown codec series — stacked on #3079 and #3080; review the last commit. Extracted from MemNote's super_editor fork.
🤖 Generated with Claude Code