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. */