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

HTML P tags are not handled correctly #285

Open
pawelmidur opened this issue Jan 8, 2024 · 6 comments
Open

HTML P tags are not handled correctly #285

pawelmidur opened this issue Jan 8, 2024 · 6 comments

Comments

@pawelmidur
Copy link
Contributor

After pasting HTML as the default value, an error appears when trying to edit:

TypeError
Cannot read properties of null (reading 'append')

https://codesandbox.io/p/sandbox/mdx-editor-paste-html-ld5366?file=%2Fsrc%2FApp.tsx%3A20%2C21-20%2C29

something is with the parsing, because the <p> tag without attributes wraps the whole content or every tag <p> is wraped by other <p> without attributes

image

@petyosi
Copy link
Contributor

petyosi commented Jan 8, 2024

Nesting paragraphs is certainly not correct, but I want to get the obvious question out first - what's the purpose of P tags in a markdown file? White you can (quite inconveniently) edit HTML with the editor, there are much better tools for that purpose. And if you want to convert an exsiting HTML content to markdown, you will be much better off pre-processing it firstbefore passing it into the editor.

Apart from that, I can't reproduce a problem, but likely I'm missing something - what do you mean by "pasting"?

@pawelmidur
Copy link
Contributor Author

The example is in the sandbox, the link does not work?
https://codesandbox.io/p/sandbox/mdx-editor-paste-html-ld5366?file=%2Fsrc%2FApp.tsx%3A20%2C21-20%2C29

"pasting" wrong word, sorry, I meant to simply add the initial value as HTML

Preparing data from HTML to Markdown is probably the only solution in that case

@pawelmidur
Copy link
Contributor Author

import "@mdxeditor/editor/style.css";
import { MDXEditor, headingsPlugin } from "@mdxeditor/editor";

const fromDB = `<p>Lorem Ipsum is simply dummy text of the printing and</p>
  \n<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s</p>
  \n<p>desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum</p>
  \n<p>'Content here, content here', making it look like readable English.</p>
  \n<p>Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).</p>
  \n<p><strong>lorem bold impsum!</strong>.</p>
  \n`;

const otherFromDB = `<p>Lorem Ipsum is simply dummy text of the printing and</p>
  <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s</p>
  <p>desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum</p>
  <p>'Content here, content here', making it look like readable English.</p>
  <p>Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).</p>
  <p><strong>lorem bold impsum!</strong>.</p>`;

function App() {
  return <MDXEditor markdown={otherFromDB} plugins={[headingsPlugin()]} />;
}

export default App;

@petyosi
Copy link
Contributor

petyosi commented Jan 8, 2024

I opened the link, but then I'm not sure what I'm supposed to do there to trigger the error. I see no errors in the console, and I can type in the editor just fine.

@pawelmidur
Copy link
Contributor Author

Try pressing "Enter" e.g. after "Lorem Ipsum"

@petyosi
Copy link
Contributor

petyosi commented Jan 8, 2024

Got it. I will fix that at some point, probably a matter of handling the P paragraphs explicitly. But in general, you are still better off converting the HTML explicitly, given the whitespace specifics of the markdown.

@petyosi petyosi changed the title Can not edit when paste HTML as the default value HTML P tags are not handled correctly Jan 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants