engine/dev-utils/model
@ckeditor/ckeditor5-engine/src/dev-utils/model
Filtering
Functions
-
getData( model, [ options ] = { [options.withoutSelection], [options.rootName], [options.convertMarkers] } ) → 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.withoutSelection ] : Boolean
Whether to write the selection. When set to
true
, the selection will not be included in the returned string.Defaults to
false
[ 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.Defaults to
'main'
[ options.convertMarkers ] : Boolean
Whether to include markers in the returned string.
Defaults to
false
Returns
String
The stringified data.
-
parse( data, schema, [ options ] = { [options.selectionAttributes], [options.lastRangeBackward], [options.context] } ) → Element | Text | 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.selectionAttributes ] : Array.<Object>
A list of attributes which will be passed to the selection.
[ options.lastRangeBackward ] : Boolean
If set to
true
, the last range will be added as backward.Defaults to
false
[ options.context ] : SchemaContextDefinition
The conversion context. If not provided, the default
'$root'
will be used.Defaults to
'$root'
Defaults to
{}
Returns
Element | Text | 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.rootName], [options.selectionAttributes], [options.lastRangeBackward], [options.batchType] } )
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.rootName ] : String
Root name where parsed data will be stored. If not provided, the default
main
name will be used.Defaults to
'main'
[ options.selectionAttributes ] : Array.<Object>
A list of attributes which will be passed to the selection.
[ options.lastRangeBackward ] : Boolean
If set to
true
, the last range will be added as backward.Defaults to
false
[ options.batchType ] : Object
Batch type used for inserting elements. See
constructor
. Seetype
.
-
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 : RootElement | Element | Text | DocumentFragment
A node to stringify.
[ selectionOrPositionOrRange ] : Selection | Position | Range
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.
markers : Iterable.<Marker> | null
Markers to include.
Returns
String
An HTML-like string representing the model.
Every day, we work hard to keep our documentation complete. Have you spotted an outdated information? Is something missing? Please report it via our issue tracker.