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

fix(@lexical/markdown): preserve the order of markdown tags for markdown combinations, and close the tags when the outmost tag is closed #5758

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

Conversation

yhw5
Copy link

@yhw5 yhw5 commented Mar 23, 2024

Issue: #2303, #2632
Related PR: #2304

This PR aims to fix the following:
Closing tags were applied in a different order than opening tags.
Unclosed tags remain in the markdown for complex markdown combinations.

And this change should not add any unnecessary duplicate markdown tags

Examples:
Note: underline is a custom markdown here, the tag is "++". You can imagine it as strikethrough "~~"

  1. bold, italic and underline combination + italic
    image
    markdown:
    before: ++***BoldplusItalicplusUnderline**++Italic* (unclosed italic inside the first block)
    after: ***++BoldplusItalicplusUnderline++****Italic* (properly closed all the opening tags if the outmost one is closed)

  2. bold + underline and bold combination
    image
    markdown output:
    before: **bold++underline**++ (markdown tag order is wrong)
    after: **bold++underline++**

Copy link

vercel bot commented Mar 23, 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 Jul 16, 2024 6:30pm
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 16, 2024 6:30pm

@facebook-github-bot
Copy link
Contributor

Hi @yhw5!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

@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 Mar 23, 2024
@yhw5
Copy link
Author

yhw5 commented Mar 27, 2024

Hi @fantactuka I noticed that you have mainly been involved in the referenced issues and PRs above. Could you please take a look at this proposed change? If this could be merged, that would be really great! Thanks

@@ -141,7 +141,11 @@ describe('Markdown', () => {
},
{
html: '<p><span style="white-space: pre-wrap;">Hello </span><s><i><b><strong style="white-space: pre-wrap;">world</strong></b></i></s><span style="white-space: pre-wrap;">!</span></p>',
md: 'Hello ~~***world***~~!',
md: 'Hello ***~~world~~***!',
Copy link
Author

Choose a reason for hiding this comment

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

I changed the expected markdown here because I rearranged the order of tags in the markdownExport. The order change was to address edge cases, such as the one from L146-148, where the very first opening tag needs to be closed as the last one.

@yhw5
Copy link
Author

yhw5 commented Apr 3, 2024

The unit tests and integrity should be OK now. Please help review, thanks

@yhw5
Copy link
Author

yhw5 commented Apr 4, 2024

@ivailop7 @fantactuka @acywatson @zurfyx @Fetz May I get review for this one? Appreciate your time 🙏

@yhw5 yhw5 marked this pull request as draft April 8, 2024 19:07
@yhw5 yhw5 marked this pull request as ready for review April 8, 2024 19:07
@yhw5 yhw5 changed the title fix(@lexical/markdown): enhance exportMarkdown to support markdown combinations and edge cases fix(@lexical/markdown): preserve the order of markdown tags for markdown combinations, and close the tags when the outmost tag is closed Apr 12, 2024
@yhw5
Copy link
Author

yhw5 commented Apr 12, 2024

QVQ any concerns regarding the fix? Really like to get the issue fixed especially for the current broken markdown combinations

@SaintPepsi
Copy link

Does this also fix cases where multiple formats are being added/removed?
Github doesn't support it natively (first line is adding bold, then italic, and then removing bold from the word "that":

**Example _Text **that** is wrapped in_ bold**
**Example _Text _**that**_ is wrapped in_ bold**
**Example _Text_** _that_ **_is wrapped in_ bold**

Example Text that is wrapped in bold
Example Text that is wrapped in bold
Example Text that is wrapped in bold

@yhw5
Copy link
Author

yhw5 commented Jul 16, 2024

Does this also fix cases where multiple formats are being added/removed? Github doesn't support it natively (first line is adding bold, then italic, and then removing bold from the word "that":

**Example _Text **that** is wrapped in_ bold**
**Example _Text _**that**_ is wrapped in_ bold**
**Example _Text_** _that_ **_is wrapped in_ bold**

Example Text that is wrapped in bold Example Text that is wrapped in bold Example Text that is wrapped in bold

yes exactly!

Copy link

size-limit report 📦

Path Size
lexical - cjs 28.75 KB (0%)
lexical - esm 28.61 KB (0%)
@lexical/rich-text - cjs 37.2 KB (0%)
@lexical/rich-text - esm 28.13 KB (0%)
@lexical/plain-text - cjs 35.81 KB (0%)
@lexical/plain-text - esm 25.48 KB (0%)
@lexical/react - cjs 39.05 KB (0%)
@lexical/react - esm 29.48 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.

3 participants