# engine/dev-utils/model

module

<a id="constants">

## Constants

<a id="constant-_getModelData">

### `_getModelData: GetModelData`

Writes the content of a model [document](module_engine_model_document-ModelDocument.md) to an HTML-like string.

```typescript
getData( editor.model ); // -> '<paragraph>Foo![]</paragraph>'
```

**Note:** A [text](module_engine_model_text-ModelText.md) node that contains attributes will be represented as:

```xml
<$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.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/dev-utils/model.ts#L121)

<a id="constant-_setModelData">

### `_setModelData: SetModelData`

Sets the content of a model [document](module_engine_model_document-ModelDocument.md) provided as an HTML-like string.

```typescript
setData( editor.model, '<paragraph>Foo![]</paragraph>' );
```

**Note:** Remember to register elements in the [model's schema](module_engine_model_model-Model.md#member-schema) before trying to use them.

**Note:** To create a [text](module_engine_model_text-ModelText.md) node that contains attributes use:

```xml
<$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.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/dev-utils/model.ts#L172)

<a id="functions">

## Functions

<a id="function-_parseModel">

### `_parseModel( data, schema, options = { options.context?, options.inlineObjectElements?, options.lastRangeBackward?, options.selectionAttributes? } ) → ModelNode | ModelDocumentFragment | object`

Parses an HTML-like string and returns the model [rootElement](module_engine_model_rootelement-ModelRootElement.md).

**Note:** To create a [text](module_engine_model_text-ModelText.md) node that contains attributes use:

```xml
<$text attribute="value">Text data</$text>
```

**Note:** The default `options.context` value is `'$root'`, which only matches the generic root. When the editor uses a custom root [`modelElement`](module_core_editor_editorconfig-RootConfig.md#member-modelElement), pass the target [root element](module_engine_model_rootelement-ModelRootElement.md) (or its configured model element name) explicitly, otherwise the conversion result may be wrong. See the [Custom root elements](../framework/deep-dive/schema.md#custom-root-elements) section of the [Schema deep-dive](../framework/deep-dive/schema.md) guide for more details.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/dev-utils/model.ts#L397)

#### Parameters

* `data: string`

  HTML-like string to be parsed.

* `schema: ModelSchema`

  A schema instance used by converters for element validation.

* `options: object`

  Additional configuration.

  Properties

  * `options.context?: ModelSchemaContextDefinition`

    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<[ string, unknown ], any, any>`

    A list of attributes which will be passed to the selection.

  Defaults to `{}`

#### Returns

* `ModelNode | ModelDocumentFragment | object`

  Returns the parsed model node or an object with two fields: `model` and `selection`, when selection ranges were included in the data to parse.

<a id="function-_stringifyModel">

### `_stringifyModel( node, selectionOrPositionOrRange, markers ) → string`

Converts model nodes to HTML-like string representation.

**Note:** A [text](module_engine_model_text-ModelText.md) node that contains attributes will be represented as:

```xml
<$text attribute="value">Text data</$text>
```

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/dev-utils/model.ts#L259)

#### Parameters

* `node: ModelNode | ModelDocumentFragment`

  A node to stringify.

* `selectionOrPositionOrRange: ModelPosition | ModelRange | ModelSelection | ModelDocumentSelection | null`

  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: MarkerCollection | null`

  Markers to include.

  Defaults to `null`

#### Returns

* `string`

  An HTML-like string representing the model.

---

Full index of the CKEditor 5 API reference: [llms.txt](llms.txt)
