engine/dev-utils/model
@ckeditor/ckeditor5-engine/src/dev-utils/model
Filtering
Functions
-
getData( model, options = { [options.convertMarkers], [options.rootName], [options.withoutSelection] } ) → string
module:engine/dev-utils/model~getData
Writes the content of a model document to an HTML-like string.
getData( editor.model ); // -> '<paragraph>Foo![]</paragraph>'
Note: A text node that contains attributes will be represented as:
<$text attribute="value">Text data</$text>
Note: Using this tool in production-grade code is not recommended. It was designed for development, prototyping, debugging and testing.
Parameters
model : Model
options : object
-
Properties
[ options.convertMarkers ] : boolean
Whether to include markers in the returned string.
[ options.rootName ] : string
The name of the root from which the data should be stringified. If not provided, the default
main
name will be used.[ options.withoutSelection ] : boolean
Whether to write the selection. When set to
true
, the selection will not be included in the returned string.
Defaults to
{}
Returns
string
The stringified data.
-
parse( data, schema, options = { [options.context], [options.inlineObjectElements], [options.lastRangeBackward], [options.selectionAttributes] } ) → Node | DocumentFragment | object
module:engine/dev-utils/model~parse
Parses an HTML-like string and returns the model rootElement.
Note: To create a text node that contains attributes use:
<$text attribute="value">Text data</$text>
Parameters
data : string
HTML-like string to be parsed.
schema : Schema
A schema instance used by converters for element validation.
options : object
Additional configuration.
Properties[ options.context ] : SchemaContextDefinition
The conversion context. If not provided, the default
'$root'
will be used.[ options.inlineObjectElements ] : Array<string>
[ options.lastRangeBackward ] : boolean
If set to
true
, the last range will be added as backward.[ options.selectionAttributes ] : Record<string, unknown> | Iterable<tuple>
A list of attributes which will be passed to the selection.
Defaults to
{}
Returns
Node | DocumentFragment | object
Returns the parsed model node or an object with two fields:
model
andselection
, when selection ranges were included in the data to parse.
-
setData( model, data, options = { [options.batchType], [options.inlineObjectElements], [options.lastRangeBackward], [options.rootName], [options.selectionAttributes] } ) → void
module:engine/dev-utils/model~setData
Sets the content of a model document provided as an HTML-like string.
setData( editor.model, '<paragraph>Foo![]</paragraph>' );
Note: Remember to register elements in the model's schema before trying to use them.
Note: To create a text node that contains attributes use:
<$text attribute="value">Text data</$text>
Note: Using this tool in production-grade code is not recommended. It was designed for development, prototyping, debugging and testing.
Parameters
model : Model
data : string
HTML-like string to write into the document.
options : object
-
Properties
[ options.batchType ] : BatchType
Batch type used for inserting elements. See
constructor
. Seetype
.[ options.inlineObjectElements ] : Array<string>
[ options.lastRangeBackward ] : boolean
If set to
true
, the last range will be added as backward.[ options.rootName ] : string
Root name where parsed data will be stored. If not provided, the default
main
name will be used.[ options.selectionAttributes ] : Record<string, unknown>
A list of attributes which will be passed to the selection.
Defaults to
{}
Returns
void
-
stringify( node, selectionOrPositionOrRange, markers ) → string
module:engine/dev-utils/model~stringify
Converts model nodes to HTML-like string representation.
Note: A text node that contains attributes will be represented as:
<$text attribute="value">Text data</$text>
Parameters
node : Node | DocumentFragment
A node to stringify.
selectionOrPositionOrRange : null | Position | Range | Selection | DocumentSelection
A selection instance whose ranges will be included in the returned string data. If a range instance is provided, it will be converted to a selection containing this range. If a position instance is provided, it will be converted to a selection containing one range collapsed at this position.
Defaults to
null
markers : null | MarkerCollection
Markers to include.
Defaults to
null
Returns
string
An HTML-like string representing the model.
Every day, we work hard to keep our documentation complete. Have you spotted outdated information? Is something missing? Please report it via our issue tracker.
With the release of version 42.0.0, we have rewritten much of our documentation to reflect the new import paths and features. We appreciate your feedback to help us ensure its accuracy and completeness.