From 093dfe8e22f1b15dff3af4f859b40bc616f8e696 Mon Sep 17 00:00:00 2001 From: George Kovats Date: Mon, 20 Feb 2023 18:58:55 -0500 Subject: [PATCH] adding onPasteHTML config --- src/components/modules/paste.ts | 4 ++++ types/configs/editor-config.d.ts | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/src/components/modules/paste.ts b/src/components/modules/paste.ts index c626b789..081bf824 100644 --- a/src/components/modules/paste.ts +++ b/src/components/modules/paste.ts @@ -202,6 +202,10 @@ export default class Paste extends Module { htmlData = '

' + (htmlData.trim() ? htmlData : plainData) + '

'; } + if (_.isFunction(this.config.onPasteHTML)) { + htmlData = String(this.config.onPasteHTML(htmlData) || htmlData); + } + /** Add all tags that can be substituted to sanitizer configuration */ const toolsTags = Object.keys(this.toolsTags).reduce((result, tag) => { /** diff --git a/types/configs/editor-config.d.ts b/types/configs/editor-config.d.ts index cb5a93ed..a1efebd3 100644 --- a/types/configs/editor-config.d.ts +++ b/types/configs/editor-config.d.ts @@ -94,6 +94,13 @@ export interface EditorConfig { */ onChange?(api: API, event: CustomEvent): void; + /** + * On Paste hook for parsing HTML before sanitization + * @param {string} html Input pasted HTML + * @returns {string} cleaned / updated HTML + */ + onPasteHTML?(html: string): string; + /** * Defines default toolbar for all tools. */