question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

<p> tag was removed after pasteHTML()

See original GitHub issue

Steps for Reproduction

Write 3 lines in the editor, and save the html content using innerHTML:

<p>line 1</p><p>line 2</p><p>line 3</p>

Then paste the content in the editor :

    this.editor.pasteHTML('<p>line 1</p><p>line 2</p><p>line 3</p>');
    // or
    this.editor.clipboard.dangerouslyPasteHTML('<p>line 1</p><p>line 2</p><p>line 3</p>');

I don’t want to use getContent method as it does not preserve extra html code (in a more complex example, you may want to insert an iframe or some pre-formated html code)

Expected behavior:

HTML content is preserved including

tags

Actual behavior:

tags have been stripped out

(tricky) workaround for my use case:

To paste:

const quillHtmlContent = '<p>line 1</p><p>line 2</p><p>line 3</p>'.replace(new RegExp('<p><br></p>', 'g'), '<br/>').replace(new RegExp('<p>', 'g'), '<p><br/>').replace('<p><br/>', '<p>');

this.editor.pasteHTML(quillHtmlContent);

To copy:

    let htmlContent = this.editorContentHtmlElement.innerHTML;

    if (htmlContent === '<p><br/></p>') {
      htmlContent = null;
    } else {
      htmlContent = htmlContent.replace(new RegExp('<p><br/>', 'g'), '<p>')
    }
  }

Platforms:

firefox, chrome, and probably others

Version:

1.3.6

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
benbrocommented, Aug 3, 2018

You need to use getContents and setContents. You can read about Delta.

0reactions
Toubcommented, Aug 7, 2018

Thanks, nice read!

Also discovered the following usefully repository mentioned in the blog post (should be linked from main repository): https://github.com/quilljs/awesome-quill

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to remove <p><br></p> tags in summernote value?
Use the following: ... Just remove the empty element ... The editing area needs <p><br></p> for focus, even if the editor content is...
Read more >
Rich Text editor removing <p> tags from text - ExpressionEngine
In my case, I think the problem was that I had originally created the channel field as a normal textarea then changed it...
Read more >
pasteHTML · WebPlatform Docs
String that specifies the HTML text to paste. The string can contain text and any combination of the HTML tags described in HTML...
Read more >
How to Stop WordPress from Removing Paragraph &lt;p&gt ...
How do I stop WordPress from removing paragraph tags (<p> and </p>) from the post/page ... Paste HTML code in the "Text" tab...
Read more >
<p>: The Paragraph element - HTML - MDN Web Docs - Mozilla
See "Tag omission" below. Try it. HTML Demo: <p>. Reset. HTML CSS
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found