engine/dev-utils/model
Functions
_getModelData( model, options = { [options.convertMarkers], [options.rootName], [options.withoutSelection] } ) → stringmodule:engine/dev-utils/model~_getModelDataWrites the content of a model document to an HTML-like string.
getData( editor.model ); // -> '<paragraph>Foo![]</paragraph>'Copy codeNote: A text node that contains attributes will be represented as:
<$text attribute="value">Text data</$text>Copy codeNote: Using this tool in production-grade code is not recommended. It was designed for development, prototyping, debugging and testing.
Parameters
model : Modeloptions : object- Properties
[ options.convertMarkers ] : booleanWhether to include markers in the returned string.
[ options.rootName ] : stringThe name of the root from which the data should be stringified. If not provided, the default
mainname will be used.[ options.withoutSelection ] : booleanWhether to write the selection. When set to
true, the selection will not be included in the returned string.
Defaults to
{}
Returns
stringThe stringified data.
_parseModel( data, schema, options = { [options.context], [options.inlineObjectElements], [options.lastRangeBackward], [options.selectionAttributes] } ) → ModelNode | ModelDocumentFragment | objectmodule:engine/dev-utils/model~_parseModelParses 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>Copy codeNote: The default
options.contextvalue is'$root', which only matches the generic root. When the editor uses a custom rootmodelElement, pass the target root element (or its configured model element name) explicitly, otherwise the conversion result may be wrong. See the Custom root elements section of the Schema deep-dive guide for more details.Parameters
data : stringHTML-like string to be parsed.
schema : ModelSchemaA schema instance used by converters for element validation.
options : objectAdditional configuration.
Properties[ options.context ] : ModelSchemaContextDefinitionThe conversion context. If not provided, the default
'$root'will be used.[ options.inlineObjectElements ] : Array<string>[ options.lastRangeBackward ] : booleanIf set to
true, the last range will be added as backward.[ options.selectionAttributes ] : Record<string, unknown> | Iterable<[ string, unknown ]>A list of attributes which will be passed to the selection.
Defaults to
{}
Returns
ModelNode | ModelDocumentFragment | objectReturns the parsed model node or an object with two fields:
modelandselection, when selection ranges were included in the data to parse.
_setModelData( model, data, options = { [options.batchType], [options.inlineObjectElements], [options.lastRangeBackward], [options.rootName], [options.selectionAttributes] } ) → voidmodule:engine/dev-utils/model~_setModelDataSets the content of a model document provided as an HTML-like string.
setData( editor.model, '<paragraph>Foo![]</paragraph>' );Copy codeNote: 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>Copy codeNote: Using this tool in production-grade code is not recommended. It was designed for development, prototyping, debugging and testing.
Parameters
model : Modeldata : stringHTML-like string to write into the document.
options : object- Properties
[ options.batchType ] : BatchTypeBatch type used for inserting elements. See
constructor.[ options.inlineObjectElements ] : Array<string>[ options.lastRangeBackward ] : booleanIf set to
true, the last range will be added as backward.[ options.rootName ] : stringRoot name where parsed data will be stored. If not provided, the default
mainname will be used.[ options.selectionAttributes ] : Record<string, unknown>A list of attributes which will be passed to the selection.
Defaults to
{}
Returns
void
_stringifyModel( node, selectionOrPositionOrRange, markers ) → stringmodule:engine/dev-utils/model~_stringifyModelConverts model nodes to HTML-like string representation.
Note: A text node that contains attributes will be represented as:
<$text attribute="value">Text data</$text>Copy codeParameters
node : ModelNode | ModelDocumentFragmentA node to stringify.
selectionOrPositionOrRange : ModelPosition | ModelRange | ModelSelection | ModelDocumentSelection | nullA 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
nullmarkers : MarkerCollection | nullMarkers to include.
Defaults to
null
Returns
stringAn HTML-like string representing the model.