You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using the markdown shortcuts plugin with custom transformers, if a transformer's replace function returns false to cancel the transformation, the leading node of the matching node is still removed from the document. This happens because leadingNode.remove() is called before checking the return value of the replace function in this line
This seems unintended since it doesn't respect the documentation of the replace function: @return return false to cancel the transform, even though the regex matched. Lexical will then search for the next transformer.
Fixing this would enable writing transformers that do not replace the content even if they match, under certain conditions. For example preventing turning headers into numbered lists if you type 1. Header, like Notion and other popular editors do.
Lexical version: v0.31.2
Steps To Reproduce
Create a markdown transformer that returns false from its replace function
Type a markdown shortcut that would trigger the transformer
The document is modified despite the transformation being cancelled
The current behaviour
The leading node gets removed even if the replace is cancelled.
The expected behavior
Returning false from the replace function should cancel the transform and not remove the nodes.
Impact of fix
This issue prevents applying markdown transformers conditionally. For example, if you don't want to transform headings into numbered lists which is a common use case.
Let me know what you think. Happy to put up a PR.
The text was updated successfully, but these errors were encountered:
Made a PR with the simplest solution, all unit and e2e tests pass, but also I think most if not all transformers in the playground never return false, I think it could be improved (for example splitText still runs, I don't know if it's a potential issue or not) but didn't want to move things around too much
Uh oh!
There was an error while loading. Please reload this page.
When using the markdown shortcuts plugin with custom transformers, if a transformer's
replace
function returnsfalse
to cancel the transformation, the leading node of the matching node is still removed from the document. This happens becauseleadingNode.remove()
is called before checking the return value of thereplace
function in this linelexical/packages/lexical-markdown/src/MarkdownShortcuts.ts
Line 73 in b61a1ea
This seems unintended since it doesn't respect the documentation of the replace function:
@return return false to cancel the transform, even though the regex matched. Lexical will then search for the next transformer.
Fixing this would enable writing transformers that do not replace the content even if they match, under certain conditions. For example preventing turning headers into numbered lists if you type
1. Header
, like Notion and other popular editors do.Lexical version: v0.31.2
Steps To Reproduce
false
from itsreplace
functionThe current behaviour
The leading node gets removed even if the replace is cancelled.
The expected behavior
Returning
false
from the replace function should cancel the transform and not remove the nodes.Impact of fix
This issue prevents applying markdown transformers conditionally. For example, if you don't want to transform headings into numbered lists which is a common use case.
Let me know what you think. Happy to put up a PR.
The text was updated successfully, but these errors were encountered: