[lexical-markdown] Bug Fix: support link and inline code text formats#7004
Merged
potatowagon merged 25 commits intofacebook:mainfrom Feb 6, 2025
Merged
[lexical-markdown] Bug Fix: support link and inline code text formats#7004potatowagon merged 25 commits intofacebook:mainfrom
potatowagon merged 25 commits intofacebook:mainfrom
Conversation
…most matching applies to both text format and text match transformers, instead of just text format transformers
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
size-limit report 📦
|
…pdate call if node can not contain transformable markdown
etrepum
approved these changes
Jan 29, 2025
Collaborator
etrepum
left a comment
There was a problem hiding this comment.
I didn't do a very careful read of all the logic but this seems like a reasonable approach, has new tests, and passes existing tests. @potatowagon what do you think?
Contributor
lgtm! a very useful feature, thankyou |
kendelljoseph
pushed a commit
to payloadcms/payload
that referenced
this pull request
Feb 21, 2025
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.
Fixes #5148. Additionally, it fixes an issue where formatted code blocks (e.g.
are not exported to markdown correctly after they have been imported.
This PR refactors the logic for applying text match and text format transformers to enable support for nested text formats within text match transformers, such as link nodes.
Unlike the previous attempt to fix it, this change does not include any node-specific logic. It fixes the root cause of the issue by ensuring that nested combinations of textmatch and textformat transformers are applied in optimal order.
Before
CleanShot.2024-12-30.at.11.56.42.mp4
After
CleanShot.2024-12-30.at.11.56.03.mp4
The Problem
Previously, the import process for text transformers roughly followed this sequence:
ElementTransformers ($importBlocks)
=>TextFormatTransformers=if not found>TextMatchTransformersFor link nodes containing formatted text, the process failed as follows:
Initially, I attempted to solve this issue by adjusting the sequence to prioritize text match transformers:
ElementTransformers ($importBlocks)
=>TextMatchTransformers=>TextFormatTransformersWhile this resolved the issue with nested formats, it introduced a new problem in scenarios where links were wrapped by text format markdown, like this:
Now, the link is created first and we get
normal text, link, normal text. However, the bold text transformer could no longer identify and apply formatting to the entire outer bold range.The Solution
Text format transformers already include logic to identify the outermost match, allowing them to handle scenarios like:
In this case, the bold transformer runs first, followed by the italic transformer, ensuring proper formatting.
However, text match transformers currently lack similar logic. Consider this example:
The existing sequence processes it as:
However, to achieve correct results, the sequence should be:
To address this, the PR introduces logic for identifying the outermost match across both text match and text format transformers.
With this change, text match and text format transformers are treated as equals in priority, allowing their results to be compared directly. This ensures that the outermost match—whether from a text match or a text format transformer—is correctly identified and then applied, enabling seamless handling of nested text transformations.
Implementation details