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 hook into the import process for multiline element transformers #6682

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

Conversation

AlessioGr
Copy link
Contributor

@AlessioGr AlessioGr commented Sep 27, 2024

Description

This PR is similar to #6681 but for multiline element transformers.

This adds a new handleImportAfterStartMatch property to MultilineElementTransformer that allows you to replace whatever happens after the regExpStart has matched with your own, custom logic.

This is great for cases where the default logic for finding the end of a given match and running the replace function is not enough.

E.g. for JSX elements, we need custom logic to keep track of the amount of opened and closed tags matched in order to find the correct, ending tag. Simply looking for the next closing tag using regExpEnd would not work for nested JSX elements. (Example of this in action)

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 Oct 3, 2024 5:52am
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 3, 2024 5:52am

@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.86 KB (0%)
lexical - esm 29.75 KB (0%)
@lexical/rich-text - cjs 38.45 KB (0%)
@lexical/rich-text - esm 31.58 KB (0%)
@lexical/plain-text - cjs 37.09 KB (0%)
@lexical/plain-text - esm 28.95 KB (0%)
@lexical/react - cjs 40.22 KB (0%)
@lexical/react - esm 32.94 KB (0%)

*
* @returns a tuple or null. The first element of the returned tuple is a boolean indicating if a multiline element was imported. The second element is the index of the last line that was processed. If null is returned, the next multilineElementTransformer will be tried. If undefined is returned, the default behavior will be used.
*/
handleImportAfterStartMatch?: (args: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks safe since this is optional, wdyt about adding a test case to demo a simple usecase of this fn?

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. extended-tests Run extended e2e tests on a PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants