Last active
March 20, 2024 16:27
-
-
Save fxmontigny/58ffb86108aba8e80c606adcc3341036 to your computer and use it in GitHub Desktop.
Insert and get html content with quilljs editor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const editor = $('.editor'); | |
const quill = new Quill(editor); | |
// set html content | |
quill.setHTML = (html) => { | |
editor.root.innerHTML = html; | |
}; | |
// get html content | |
quill.getHTML = () => { | |
return editor.root.innerHTML; | |
}; | |
// usages | |
quill.setHTML('<b>Hello my friend</b>'); | |
quill.on('text-change', () => { | |
console.log('get html', quill.getHTML()); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you aren't getting the desired output. It could be because your html content is encoded.
Use this to convert it.
This code will output
After this you can use this command to set the html content in quill editor
or even this:
Its proper your html is in the real html format before setting the value on quill. Else the html tags would be displayed verbally.