How to retain the original HTML inline styles when inserting templates into Tiptap editor (React)? #5675
-
I’m using the Tiptap editor with some custom extensions configured like this: const extensions = [
// StarterKit
StarterKit.configure({
paragraph: {
HTMLAttributes: {
class: 'yp-paragraph',
},
},
}),
// Table extension
Table.configure({
resizable: false,
HTMLAttributes: {
style: 'display: block; width: 100%; box-sizing: border-box; border-collapse: collapse; margin: 0; overflow-x: auto; table-layout: fixed; padding: 0.25rem;',
},
}),
// Table-related extensions
TableRow,
TableHeader.configure({
HTMLAttributes: {
style: 'background-color: #d1d5db; font-weight: bold; text-align: left; box-sizing: border-box; position: relative; vertical-align: top; border-style: solid; border-width: 1px; border-color: #9ca3af; padding: 0.375rem 0.5rem; margin-bottom: 0;',
},
}),
TableCell.configure({
HTMLAttributes: {
style: 'box-sizing: border-box; vertical-align: top; min-width: 128px; border: 1px solid #9ca3af; padding: 0.375rem 0.5rem; margin-bottom: 0;',
},
}),
]; When I insert an HTML template with inline styles (like a tag and a ), the styles defined in my extensions get applied, but the original inline styles from the HTML template get removed.For example, if I insert this HTML:
Tiptap only applies the styles defined in my extensions (e.g., the yp-paragraph class), but the original inline styles (like font-size: 16px on the My Question: How can I preserve the original inline styles from the HTML template when inserting it into Tiptap? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
You need to handle every style that you want to preserve. Otherwise it will be discarded as content that does not match the schema. |
Beta Was this translation helpful? Give feedback.
-
@nperez0111 in the above example, a p tag can possibly have varied css style props and it could be very hard to whitelist all of them. is there a way to insert html content as it is without loosing any of the element's attributes? |
Beta Was this translation helpful? Give feedback.
You need to handle every style that you want to preserve. Otherwise it will be discarded as content that does not match the schema.