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] Add test to keep code language #6259

Merged
merged 3 commits into from
Jun 11, 2024
Merged

Conversation

Minhir
Copy link
Contributor

@Minhir Minhir commented Jun 5, 2024

[lexical-markdown] Bug Fix: preserve language tag for Markdown code

Right now, PR contains only one commit with tests to highlight the problem.

If the markdown file contains a code block with an unsupported language (a language for which the project doesn't have syntax highlighter) the lexical will remove any information about that language.

Let's say we have markdown with the following content:

```rust
fn main() {
    println!("Hello World!");
}
```

If we don't have prism-rust in the project, lexical will strip all the info about the language and saved file will look like:

```
fn main() {
    println!("Hello World!");
}
```

That behavior seems to me like a bug.

Possible solution

I think CodeNode should always keep __language field, no matter what the mapToPrismLanguage() returns. And we can create another field called __isSyntaxHighlightSupported for highlighting check.

What do you think? I'll be happy to create another commit with a fix if provided solution works for the lexical team.

@facebook-github-bot
Copy link
Contributor

Hi @Minhir!

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 cla@meta.com. Thanks!

Copy link

vercel bot commented Jun 5, 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 Jun 9, 2024 4:59pm
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 9, 2024 4:59pm

Copy link

github-actions bot commented Jun 5, 2024

size-limit report 📦

Path Size
lexical - cjs 28.31 KB (0%)
lexical - esm 28.13 KB (0%)
@lexical/rich-text - cjs 36.77 KB (0%)
@lexical/rich-text - esm 28.09 KB (0%)
@lexical/plain-text - cjs 35.36 KB (0%)
@lexical/plain-text - esm 25.33 KB (0%)
@lexical/react - cjs 38.51 KB (0%)
@lexical/react - esm 29.14 KB (0%)

@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 Jun 5, 2024
@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@StyleT
Copy link
Contributor

StyleT commented Jun 7, 2024

Makes sense! Commit with the fix would really help here :P

return language != null && window.Prism.languages.hasOwnProperty(language)
? language
: undefined;
return language ? window.Prism.languages.hasOwnProperty(language) : false;
Copy link

Choose a reason for hiding this comment

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

try {
    return language ? window.Prism.languages.hasOwnProperty(language) : false;
} catch (error) {
    return false
}

this may help the headless editor work in a Web Worker

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point!

@StyleT StyleT added the extended-tests Run extended e2e tests on a PR label Jun 10, 2024
@StyleT StyleT added this pull request to the merge queue Jun 11, 2024
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