I am using Rich Text (Trix editor) with Rails and I want to be able to convert everything that user pastes to sanitized plain text instead of having formatted elements. Based on Trix documentation I am using this code to convert pasted elements to string.
const element = document.querySelector("trix-editor")
element.addEventListener("trix-paste", function(e) {
element.editor.getDocument().toString()
console.log(element.editor.getDocument().toString())
})
In console, it shows correct plain text, but in the editor, all the elements are still formatted.
How can I replace text in the editor to this sanitized text?