-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[lexical-markdown] Feature: add ability to control finding the end of a node matched by TextMatchTransformer #6681
[lexical-markdown] Feature: add ability to control finding the end of a node matched by TextMatchTransformer #6681
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
size-limit report 📦
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test coverage for this new functionality would be nice. It seems like you might also want to be able to let the transform fail if the end doesn't match correctly, maybe a more general solution (e.g. the option to use a function instead of regex for matching altogether) would be more appropriate? There's currently no "compilation" to merge regexes so there wouldn't be much of a disadvantage to having that sort of option.
Will add one after #6682 is merged!
Done! Can now return
I think adding a general option would be a good idea - however, I don't always wanna have to handle all that code related to text splitting myself (this: Maybe it's better to add that in a separate PR in addition to |
@AlessioGr were you planning to still add the test case here now that #6682 is merged? |
Yep, I am! Will be done this week |
Just following up here, looks like we are still waiting on test cases but otherwise this is ready to go |
@etrepum sorry for the delay - just added a test, so this should be ready now. Pretty tricky finding a good, simple use-case for a test here, as the actual function we use to match JSX is huge. For this test, I just added a very basic text match converter where getEndIndex is used just for simple JSX opening/closing tag counting. Similar to the other CODE_TAG_COUNTER_EXAMPLE example, but simpler and for text match transformers |
Description
Currently, for a
TextMatchTransformer
, theimportRegExp
is used to find a match in a given text. The end of the matched node is determined by the length of the match.However, in some scenarios, you want to use
importRegExp
to only match the start of the node. You might then want to determine the end manually, for example via a different regex, or some custom logic.Use-Case example
A good example is matching inline JSX, e.g.
"Hello <InlineBlock prop1="hey">some text</InlineBlock> there!"
.In this example, we use
importRegExp
solely to match<InlineBlock
. We use a custom algorithm to then find the proper end of this node (</InlineBlock>
). You might think this is possible solely with regex, but it's not.Example that showcases why:
"Hello <InlineBlock prop1="hey">some <InlineBlock>Sub Block</InlineBlock> text</InlineBlock> there!"
We need custom logic that keeps track of the opening and closing JSX tags in order to find the correct end of the node: the second
</InlineBlock>
.This PR adds a
getEndIndex
property toTextMatchTransformer
that allows us to do these kinds of things, by providing our custom algorithm to find the end of the node (Example).