Skip to content
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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

AlessioGr
Copy link
Contributor

@AlessioGr AlessioGr commented Sep 27, 2024

Description

Currently, for a TextMatchTransformer, the importRegExp 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 to TextMatchTransformer that allows us to do these kinds of things, by providing our custom algorithm to find the end of the node (Example).

Copy link

vercel bot commented Sep 27, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lexical ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 27, 2024 10:59pm
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 27, 2024 10:59pm

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 27, 2024
Copy link

github-actions bot commented Sep 27, 2024

size-limit report 📦

Path Size
lexical - cjs 29.83 KB (0%)
lexical - esm 29.65 KB (0%)
@lexical/rich-text - cjs 38.42 KB (0%)
@lexical/rich-text - esm 31.57 KB (0%)
@lexical/plain-text - cjs 37.01 KB (0%)
@lexical/plain-text - esm 28.86 KB (0%)
@lexical/react - cjs 40.23 KB (0%)
@lexical/react - esm 32.93 KB (0%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants