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

Add code to html conversions #2187

Closed

Conversation

mmarkelov
Copy link

close #2049

@vercel
Copy link

vercel bot commented May 16, 2022

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

Name Status Preview Updated
lexical ✅ Ready (Inspect) Visit Preview May 16, 2022 at 7:01PM (UTC)
lexical-playground ✅ Ready (Inspect) Visit Preview May 16, 2022 at 7:01PM (UTC)

@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 May 16, 2022
@tylerjbainbridge
Copy link
Contributor

Won't this match every <code> tag with the TextNode and not the CodeNode?

@tylerjbainbridge
Copy link
Contributor

tylerjbainbridge commented May 16, 2022

In importDOM for code you should check if it's an inline code element and not a code block. If it's a code block you can return null, otherwise convert to text node.

...
code: (node: Node) => {
  if (node is code block) {
    return null;
  }

  return {
    conversion: convertTextFormatElement,
    priority: 0,
  }
},
...

cc @fantactuka, do you know if there's a good way to check if an incoming code node is inline?

@acywatson
Copy link
Contributor

acywatson commented May 16, 2022

Won't this match every <code> tag with the TextNode and not the CodeNode?

It will, but this still might be the right thing to do. CodeNode is not a core node, so this would allow us to handle pasted HTML code tags even if CodeNode is not registered.

I think the full solution involves also adding a higher priority conversion on CodeNode/CodeHighlightNode, but I think it could be done in two PRs.

Either way, we need some test coverage for this, which can be added here:

https://github.com/facebook/lexical/blob/main/packages/lexical-playground/__tests__/e2e/CopyAndPaste.spec.mjs

EDIT: @tylerjbainbridge saw your other comment, I'm on the same page.

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/code

It looks like <code> is inline by nature - maybe <pre> plus <code> is the formula for a code "block"?

@trueadm
Copy link
Collaborator

trueadm commented Jun 6, 2022

@tylerjbainbridge This adds tests, is this something we can get in for increased coverage?

@fantactuka
Copy link
Contributor

Addressed in #2607

@fantactuka fantactuka closed this Jul 7, 2022
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.

Bug: Formatting of Inline code elements is lost when content is copied from external web page
6 participants