Repository navigation
Conversation
… on export When a text node opens several formats, open first the format that continues furthest into the following siblings. A format that ends sooner is then closed on its own, instead of closing and reopening the others, which merged the delimiters into a run like `***a****: b*` and lost the italic on import. Fixes meta#9443 Co-authored-by: Ved Thakar <111605341+Vedthakar@users.noreply.github.com>
Owner
Author
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.
Description
This solves issue meta#9443: a bold and italic node followed by an italic node is exported as
***Disclaimer****: once accepted.*. CommonMark reads the four asterisks as closing both formats, so the italic on: once accepted.is lost and its asterisks show as text.Cause.
exportTextFormat()inMarkdownExport.tsopens a node's formats in transformer order (BOLD_STARbeforeITALIC_STAR), so bold is always outside italic. When bold ends first, the closing loop has to close italic too and the next node reopens it, which runs the delimiters together. Swapping the transformer order only moves the problem to bold.What this changes. Before the tags a node opens are added to
unclosedTags, they're sorted by how many following text siblings keep each format. The format that continues furthest is opened first (outermost), and the one that ends first is innermost, so it closes alone. The sort is stable, so formats that end together keep the transformer order and those exports don't change.The output for
**~~Hello *world*~~**~~!~~changes too. It used to close and reopen the strikethrough. It's now exported as~~**Hello *world***!~~, which imports to the same nodes, so two existingmdAfterExportfixtures inLexicalMarkdown.test.tsare updated.Relation to open PRs. meta#9420 changes the whitespace-only return at the end of
exportTextFormat(), and meta#9432 changescheckHasFormat(). Neither touches the opening loop changed here, and the patches don't conflict. meta#9435 is import-side (importTextFormatTransformer.ts).Closes meta#9443
Test plan
New
packages/lexical-markdown/src/__tests__/unit/NestedEmphasisExport.test.ts. It exports nodes built directly, checks the exact Markdown, and checks that importing it gives the same nodes back:***Disclaimer**: once accepted.*(the issue)~~***a** b* c~~~~**Hello *world***!~~***Disclaimer*: once accepted.**, and a single bold+italic node →***a b***Before
On
main(the new test file run againstmain'sMarkdownExport.ts):Tests 4 failed | 2 passed (6). The two controls pass. These fail:exports [["Disclaimer",["bold","italic"]],[": once accepted.",["italic"]]] as ***Disclaimer**: once accepted.* and imports it backexports [["a",["bold","italic","strikethrough"]],[" b",["italic","strikethrough"]],[" c",["strikethrough"]]] as ~~***a** b* c~~ and imports it backexports [["Hello ",["bold","strikethrough"]],["world",["bold","italic","strikethrough"]],["!",["strikethrough"]]] as ~~**Hello *world***!~~ and imports it backround-trips the markdown from the issueWith this change:
Tests 6 passed (6).After
vitest --project unit packages/lexical-markdown: 700 passedtest-unit: everything passes except the threelexical-devtoolsfiles, which also fail onmainin my environment (a transform error)tsc,eslint packages/lexical-markdownandprettier --checkare cleanAuthor: Ved Thakar (@Vedthakar)