Content Parser

Serializes editor blocks to JSON and deserializes JSON back into block instances, DOM nodes, or fragments.

Access:

app.getService('contentParser')

App code:

const contentParser = app.getService('contentParser');

Plugin:

const contentParser = this.app.getService('contentParser');

toJSON#

Serializes all top-level blocks in the editable editor root to a JSON array of { type, data } objects.

Returns: object[]

contentParser.toJSON();

fromJSON#

Deserializes a JSON block list into a DocumentFragment (default), Block[], Node[], or HTML string depending on the as option.

Parameters:

  • json (object | string) — JSON
  • as (any) — as

Returns: DocumentFragment|Block[]|Node[]|string

contentParser.fromJSON(blocks, { as: 'html' });