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

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 14, 2024 6:28pm
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 14, 2024 6:28pm

@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.94 KB (0%)
lexical - esm 29.81 KB (0%)
@lexical/rich-text - cjs 38.54 KB (0%)
@lexical/rich-text - esm 31.61 KB (0%)
@lexical/plain-text - cjs 37.15 KB (0%)
@lexical/plain-text - esm 28.99 KB (0%)
@lexical/react - cjs 40.34 KB (0%)
@lexical/react - esm 33.08 KB (0%)

potatowagon
potatowagon previously approved these changes Oct 3, 2024
@AlessioGr
Copy link
Contributor Author

Hi @potatowagon, just added a test for this feature. Not the simplest one, but an interesting use-case:

CleanShot 2024-10-14 at 10 46 04@2x

By default, this would create 2 code blocks. In the newly added test, we use handleImportAfterStartMatch to add open / end regex counting in order to find the correct end match. The result is just one code block that looks like this

CleanShot 2024-10-14 at 10 45 53@2x

@etrepum etrepum added this pull request to the merge queue Oct 16, 2024
Merged via the queue into facebook:main with commit a7e53e7 Oct 16, 2024
40 of 41 checks passed
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.

4 participants