Skip to content

Commit

Permalink
Update styles
Browse files Browse the repository at this point in the history
  • Loading branch information
swissspidy committed Nov 25, 2024
1 parent 64ea38f commit 8284807
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion packages/rich-text/src/htmlManipulation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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: [],
Expand Down

0 comments on commit 8284807

Please sign in to comment.