Cleaning

cleaner:after:input#

Emitted after input HTML has been cleaned. The cleaner re-reads html from this object before continuing.

Type: signal.

Payload:

  • html — cleaned HTML string
  • options — options passed to cleanForInput() (usually {})

Example:

app.on('cleaner:after:input', ({ html }) => {
  auditLoadedHtml(html.length);
});

cleaner:after:output#

Emitted after output HTML has been cleaned. The cleaner re-reads html from this object before continuing.

Type: signal.

Payload:

  • html — cleaned HTML string
  • options — options passed to cleanForOutput() (e.g. { tidy: false })

Example:

app.on('cleaner:after:output', ({ html, options }) => {
  if (!options.tidy) console.log('compact output', html.length);
});

cleaner:after:paste#

Emitted after pasted HTML has been cleaned. The cleaner re-reads html from this object before continuing.

Type: signal.

Payload:

  • html — cleaned paste HTML string
  • options — options passed to cleanForPaste() (usually {})

Example:

app.on('cleaner:after:paste', ({ html }) => {
  trackPasteSize(html.length);
});

cleaner:before:input#

Hook emitted before input HTML is cleaned.

Type: hook (handler may return a value).

Payload:

  • html — HTML string about to be cleaned
  • options — options passed to cleanForInput()

Example:

app.on('cleaner:before:input', ({ html, options }) => {
  return { html: html.replace(/data-draft="[^"]*"/g, ''), options };
});

cleaner:before:output#

Hook emitted before output HTML is cleaned.

Type: hook (handler may return a value).

Payload:

  • html — HTML string about to be cleaned
  • options — options passed to cleanForOutput() (e.g. { tidy: false })

Example:

app.on('cleaner:before:output', ({ html, options }) => {
  return { html: stripInternalMarkers(html), options };
});

cleaner:before:paste#

Hook emitted before pasted HTML is cleaned.

Type: hook (handler may return a value).

Payload:

  • html — paste HTML string about to be cleaned
  • options — options passed to cleanForPaste()

Example:

app.on('cleaner:before:paste', ({ html, options }) => {
  return { html: unwrapVendorSpans(html), options };
});