Tiptap: getHTML does not preserve styling

Created on 28 May 2019  路  2Comments  路  Source: ueberdosis/tiptap

Describe the bug
When loading a JSON based document, if it is later retrieved via getHTML() then reset to the editor content, most styling will be lost. This is important because sometimes it is appropriate to convert to HTML to manipulate the HTML content before loading it back into the editor.

Steps to Reproduce / Codesandbox Example
Steps to reproduce the behavior:

  1. load editor with content
  2. get content via getHTML()
  3. Set content via setContent with the retrieved HTML
  4. Most styling will be lost

Expected behavior
Tiptap should support at least switching between JSON and HTML on its own marks and nodes, but it would certainly be preferable for all direct properties in the style tag to be preserved.

bug wontfix

Most helpful comment

@philippkuehn can you show us how to preserve custom styles???

All 2 comments

ProseMirror doesn't lose styling. All HTML will be normalized as defined in toDOM of each node/mark.

For example all of them will be converted to a basic <strong>:

<p><strong>This is strong</strong></p>
<p><b>And this</b></p>
<p style="font-weight: bold">This as well</p>
<p style="font-weight: bolder">Oh! and this</p>
<p style="font-weight: 500">Cool! Right!?</p>
<p style="font-weight: 999">Up to 999!!!</p>

It's a feature to keep your stored HTML clean. If you want to support more stylings/attributes you have to define it in your schema. You can extend all extension or create your own, but I don't want to change this in the core at the moment.

@philippkuehn can you show us how to preserve custom styles???

Was this page helpful?
0 / 5 - 0 ratings