HTML cleaning for paste and output.
Access:
app.getService('cleaner')
App code:
const cleaner = app.getService('cleaner');
Plugin:
const cleaner = this.app.getService('cleaner');
cleanForInsert#
Sanitizes HTML through htmlSanitizer before insertion into the editor.
Parameters:
- html (
string) — HTML string - options (
object) — reserved for future use; currently not read by this method
Returns: string
cleaner.cleanForInsert(html);
cleanForOutput#
Prepares HTML for export by stripping highlights, sanitizing, decoding/encoding entities, restoring template syntax, adding nofollow, and formatting or compacting via tidy.
Parameters:
- html (
string) — HTML string - options (
object) — object with the keys below- tidy (
boolean) — set tofalseto compact/minify the output instead of pretty-formatting it (defaulttrue)
- tidy (
Returns: string
cleaner.cleanForOutput(html, { tidy: false });
cleanForInput#
Normalizes initial editor input by storing embeds/svg/pictures, stripping denied tags, converting elements, paragraphizing, and restoring stored fragments.
Parameters:
- html (
string) — HTML string - options (
object) — forwarded as-is to thecleaner:before:input/cleaner:after:inputhook payloads for plugins to inspect or mutate
Returns: string
cleaner.cleanForInput(html);
cleanForEditorPaste#
Cleans internal editor clipboard fragments by storing embeds, removing denied tags, normalizing todo items, and optionally stripping empty paragraphs.
Parameters:
- html (
string) — HTML string - options (
object) — reserved for future use; currently not read by this method
Returns: string
cleaner.cleanForEditorPaste(html);
cleanForPaste#
Cleans external clipboard HTML with source-specific rules (Word, Pages, Google Docs), tag allowlists, attribute stripping, and stored fragment restoration.
Parameters:
- html (
string) — HTML string - options (
object) — forwarded as-is to thecleaner:before:paste/cleaner:after:pastehook payloads for plugins to inspect or mutate
Returns: string
cleaner.cleanForPaste(html);
isEditorFragment#
Detects Redactor editor clipboard HTML by checking for a meta tag with type rx-editor.
Parameters:
- html (
string) — HTML string
Returns: boolean
cleaner.isEditorFragment(clipboardHtml);
isWordFragment#
Detects Microsoft Word or Office clipboard HTML by checking Generator meta tags, Mso classes, and Office XML markers.
Parameters:
- html (
string) — HTML string
Returns: boolean
cleaner.isWordFragment(clipboardHtml);
isPagesFragment#
Detects Apple Pages clipboard HTML by checking Generator meta tags and Apple-specific CSS classes.
Parameters:
- html (
string) — HTML string
Returns: boolean
cleaner.isPagesFragment(clipboardHtml);
isGDocsFragment#
Detects Google Docs clipboard HTML by checking docs-internal-guid ids and Google-specific data attributes.
Parameters:
- html (
string) — HTML string
Returns: boolean
cleaner.isGDocsFragment(clipboardHtml);