<p> tag was removed after pasteHTML()
See original GitHub issueSteps 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:
- Created 5 years ago
- Comments:5 (2 by maintainers)
Top 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 <p> ...
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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
You need to use getContents and setContents. You can read about Delta.
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