double-encoding ampersands or angle brackets when repopulating editor #6817
Unanswered
RwwL
asked this question in
Questions & Help
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I want to store our editor content in a custom format to, among other reasons, allow rendering the content in other places without a Tiptap instance and having flexibility in the level being applied to heading elements. For top-level nodes other than headings, we're fine with storing the plain HTML. So, here's an example of what we're storing for a given document:
My approach to repopulating the editor with saved content has been to initialize the editor with
content: ''
, then loop over the server content, callinginsertContent
for each top-level object. If the object is oftype: "heading"
, then I use thegenerateHTML
util from@tiptap/core
to generate the full HTML for the heading node, and if it's not then I just useinsertContent(obj.value)
.So when we restore saved content to repopulate the editor, we loop over that saved-data array and here's what we do if the object type is
heading
:The only issue I'm having with this is when content in a header (but not paragraph/list/other nodes) contains
&
,<
, or>
: because I called thegenerateHTML
utility to store the header's content, and then I'm callinggenerateHTML
on it again, I'm winding up with double-escaped entity bugs that render as&
in the editor.I've tried not calling
generateHTML
here, just passing that object directly toinsertContent
, but that doesn't solve it.Anyone have thoughts on a better (or Tiptap-"correct") way to manage this than simply doing a
replace
on the stored HTML right before I restore it into the editor? Since the editor is clearly escaping incoming content, I don't think I'm exposing the editor to XSS attacks by doing that. I checked to see iftype: 'html'
is supported instead oftext
in the nested headercontent
in theinsertContent
arguments above, but it's not.I've looked the
parseOptions
option that can be passed toinsertContent
but don't see anything that I think might help here.Beta Was this translation helpful? Give feedback.
All reactions