[lexical-markdown] Feature: add ability to control finding the end of a node matched by TextMatchTransformer #6681
+12
−1
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
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).