From 82848075d4507da2e2f0ae63122a4af179d6fbfd Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Mon, 25 Nov 2024 17:28:58 +0100 Subject: [PATCH] Update styles --- packages/rich-text/src/htmlManipulation.ts | 23 +++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/packages/rich-text/src/htmlManipulation.ts b/packages/rich-text/src/htmlManipulation.ts index bc19959de5a0..cc3b16f1442d 100644 --- a/packages/rich-text/src/htmlManipulation.ts +++ b/packages/rich-text/src/htmlManipulation.ts @@ -29,6 +29,16 @@ import customImport from './customImport'; import customExport from './customExport'; import { getSelectionForAll } from './util'; import type { StyleSetter, AllowedSetterArgs } from './types'; +import { + ITALIC, + UNDERLINE, + WEIGHT, + COLOR, + LETTERSPACING, + UPPERCASE, + GRADIENT_COLOR, +} from './customConstants'; +import { getPrefixStylesInSelection } from './styleManipulation'; /** * Return an editor state object with content set to parsed HTML @@ -93,12 +103,23 @@ export function getHTMLInfo(html: string) { export function sanitizeEditorHtml(html: string) { const editorState = getSelectAllStateFromHTML(html); + + const styles: string[] = [ + ...getPrefixStylesInSelection(editorState, ITALIC), + ...getPrefixStylesInSelection(editorState, UNDERLINE), + ...getPrefixStylesInSelection(editorState, WEIGHT), + ...getPrefixStylesInSelection(editorState, COLOR), + ...getPrefixStylesInSelection(editorState, LETTERSPACING), + ...getPrefixStylesInSelection(editorState, UPPERCASE), + ...getPrefixStylesInSelection(editorState, GRADIENT_COLOR), + ]; + return ( customExport( filterEditorState( { blocks: [], - styles: ['BOLD', 'ITALIC', 'UNDERLINE'], + styles, entities: [], maxNesting: 1, whitespacedCharacters: [],