# ViewDowncastWriter

class

View downcast writer.

It provides a set of methods used to manipulate view nodes.

Do not create an instance of this writer manually. To modify a view structure, use the [`View#change()`](module_engine_view_view-EditingView.md#function-change) block.

The `ViewDowncastWriter` is designed to work with semantic views which are the views that were/are being downcasted from the model. To work with ordinary views (e.g. parsed from a pasted content) use the [upcast writer](module_engine_view_upcastwriter-ViewUpcastWriter.md).

Read more about changing the view in the [Changing the view](../framework/architecture/editing-engine.md#changing-the-view) section of the [Editing engine architecture](../framework/architecture/editing-engine.md) guide.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/downcastwriter.ts#L55)

<a id="properties">

## Properties

<a id="member-document">

### `document: ViewDocument` _(readonly)_

The view document instance in which this writer operates.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/downcastwriter.ts#L59)

<a id="member-_cloneGroups">

### `_cloneGroups: Map<string | number, Set<ViewAttributeElement>>` _(private)_

Holds references to the attribute groups that share the same [id](module_engine_view_attributeelement-ViewAttributeElement.md#member-id). The keys are `id`s, the values are `Set`s holding [`ViewAttributeElement`](module_engine_view_attributeelement-ViewAttributeElement.md)s.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/downcastwriter.ts#L65)

<a id="member-_slotFactory">

### `_slotFactory: ( writer: ViewDowncastWriter, modeOrFilter: 'children' | DowncastSlotFilter ) => ViewElement | null` _(private)_

The slot factory used by the `elementToStructure` downcast helper.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/downcastwriter.ts#L70)

<a id="methods">

## Methods

<a id="function-constructor">

### `constructor( document )`

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/downcastwriter.ts#L75)

#### Parameters

* `document: ViewDocument`

  The view document instance.

<a id="function-addClass">

### `addClass( className, element ) → void`

Adds specified class to the element.

```typescript
writer.addClass( 'foo', linkElement );
writer.addClass( [ 'foo', 'bar' ], linkElement );
```

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/downcastwriter.ts#L604)

#### Parameters

* `className: string | Array<string>`
* `element: ViewElement`

#### Returns

* `void`

<a id="function-breakAttributes">

### `breakAttributes( positionOrRange ) → ViewPosition | ViewRange`

Breaks attribute elements at the provided position or at the boundaries of a provided range. It breaks attribute elements up to their first ancestor that is a container element.

In following examples `<p>` is a container, `<b>` and `<u>` are attribute elements:

```html
<p>foo<b><u>bar{}</u></b></p> -> <p>foo<b><u>bar</u></b>[]</p>
<p>foo<b><u>{}bar</u></b></p> -> <p>foo{}<b><u>bar</u></b></p>
<p>foo<b><u>b{}ar</u></b></p> -> <p>foo<b><u>b</u></b>[]<b><u>ar</u></b></p>
<p><b>fo{o</b><u>ba}r</u></p> -> <p><b>fo</b><b>o</b><u>ba</u><u>r</u></b></p>
```

**Note:** [DocumentFragment](module_engine_view_documentfragment-ViewDocumentFragment.md) is treated like a container.

**Note:** The difference between [breakAttributes()](#function-breakAttributes) and [breakContainer()](#function-breakContainer) is that `breakAttributes()` breaks all [attribute elements](module_engine_view_attributeelement-ViewAttributeElement.md) that are ancestors of a given `position`, up to the first encountered [container element](module_engine_view_containerelement-ViewContainerElement.md). `breakContainer()` assumes that a given `position` is directly in the container element and breaks that container element.

Throws the `view-writer-invalid-range-container` [CKEditorError](module_utils_ckeditorerror-CKEditorError.md) when the [start](module_engine_view_range-ViewRange.md#member-start) and [end](module_engine_view_range-ViewRange.md#member-end) positions of a passed range are not placed inside same parent container.

Throws the `view-writer-cannot-break-empty-element` [CKEditorError](module_utils_ckeditorerror-CKEditorError.md) when trying to break attributes inside an [ViewEmptyElement](module_engine_view_emptyelement-ViewEmptyElement.md).

Throws the `view-writer-cannot-break-ui-element` [CKEditorError](module_utils_ckeditorerror-CKEditorError.md) when trying to break attributes inside a [UIElement](module_engine_view_uielement-ViewUIElement.md).

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/downcastwriter.ts#L741)

#### Parameters

* `positionOrRange: ViewPosition | ViewRange`

  The position where to break attribute elements.

#### Returns

* `ViewPosition | ViewRange`

  The new position or range, after breaking the attribute elements.

#### Related:

* [ViewAttributeElement](module_engine_view_attributeelement-ViewAttributeElement.md)
* [ViewContainerElement](module_engine_view_containerelement-ViewContainerElement.md)
* [ViewDowncastWriter#breakContainer](#function-breakContainer)

<a id="function-breakContainer">

### `breakContainer( position ) → ViewPosition`

Breaks a [container view element](module_engine_view_containerelement-ViewContainerElement.md) into two, at the given position. The position has to be directly inside the container element and cannot be in the root. It does not break the conrainer view element if the position is at the beginning or at the end of its parent element.

```html
<p>foo^bar</p> -> <p>foo</p><p>bar</p>
<div><p>foo</p>^<p>bar</p></div> -> <div><p>foo</p></div><div><p>bar</p></div>
<p>^foobar</p> -> ^<p>foobar</p>
<p>foobar^</p> -> <p>foobar</p>^
```

**Note:** The difference between [breakAttributes()](#function-breakAttributes) and [breakContainer()](#function-breakContainer) is that `breakAttributes()` breaks all [attribute elements](module_engine_view_attributeelement-ViewAttributeElement.md) that are ancestors of a given `position`, up to the first encountered [container element](module_engine_view_containerelement-ViewContainerElement.md). `breakContainer()` assumes that the given `position` is directly in the container element and breaks that container element.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/downcastwriter.ts#L774)

#### Parameters

* `position: ViewPosition`

  The position where to break the element.

#### Returns

* `ViewPosition`

  The position between broken elements. If an element has not been broken, the returned position is placed either before or after it.

#### Related:

* [ViewAttributeElement](module_engine_view_attributeelement-ViewAttributeElement.md)
* [ViewContainerElement](module_engine_view_containerelement-ViewContainerElement.md)
* [ViewDowncastWriter#breakAttributes](#function-breakAttributes)

<a id="function-clear">

### `clear( range, element ) → void`

Removes matching elements from given range.

Throws [CKEditorError](module_utils_ckeditorerror-CKEditorError.md) `view-writer-invalid-range-container` when [start](module_engine_view_range-ViewRange.md#member-start) and [end](module_engine_view_range-ViewRange.md#member-end) positions are not placed inside same parent container.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/downcastwriter.ts#L1057)

#### Parameters

* `range: ViewRange`

  Range to clear.

* `element: ViewElement`

  Element to remove.

#### Returns

* `void`

<a id="function-clearClonedElementsGroup">

### `clearClonedElementsGroup( groupName ) → void`

Cleans up memory by removing obsolete cloned elements group from the writer.

Should be used whenever all [attribute elements](module_engine_view_attributeelement-ViewAttributeElement.md) with the same [id](module_engine_view_attributeelement-ViewAttributeElement.md#member-id) are going to be removed from the view and the group will no longer be needed.

Cloned elements group are not removed automatically in case if the group is still needed after all its elements were removed from the view.

Keep in mind that group names are equal to the `id` property of the attribute element.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/downcastwriter.ts#L1278)

#### Parameters

* `groupName: string`

  Name of the group to clear.

#### Returns

* `void`

<a id="function-createAttributeElement">

### `createAttributeElement( name, attributes?, options = { options.id?, options.priority?, options.renderUnsafeAttributes? } ) → ViewAttributeElement`

Creates a new [`ViewAttributeElement`](module_engine_view_attributeelement-ViewAttributeElement.md).

```typescript
writer.createAttributeElement( 'strong' );
writer.createAttributeElement( 'a', { href: 'foo.bar' } );

// Make `<a>` element contain other attributes element so the `<a>` element is not broken.
writer.createAttributeElement( 'a', { href: 'foo.bar' }, { priority: 5 } );

// Set `id` of a marker element so it is not joined or merged with "normal" elements.
writer.createAttributeElement( 'span', { class: 'my-marker' }, { id: 'marker:my' } );
```

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/downcastwriter.ts#L246)

#### Parameters

* `name: string`

  Name of the element.

* `attributes?: ViewElementAttributes`

  Element's attributes.

* `options: object`

  Element's options.

  Properties

  * `options.id?: string | number`

    Element's [id](module_engine_view_attributeelement-ViewAttributeElement.md#member-id).

  * `options.priority?: number`

    Element's [priority](module_engine_view_attributeelement-ViewAttributeElement.md#member-priority).

  * `options.renderUnsafeAttributes?: Array<string>`

    A list of attribute names that should be rendered in the editing pipeline even though they would normally be filtered out by unsafe attribute detection mechanisms.

  Defaults to `{}`

#### Returns

* `ViewAttributeElement`

  Created element.

<a id="function-createContainerElement:WITH_CHILDREN">

### `createContainerElement( name, attributes, children, options? = { options.renderUnsafeAttributes? } ) → ViewContainerElement`

Creates a new [`ViewContainerElement`](module_engine_view_containerelement-ViewContainerElement.md) with children.

```typescript
// Create element with children.
writer.createContainerElement( 'figure', { class: 'image' }, [
	writer.createEmptyElement( 'img' ),
	writer.createContainerElement( 'figcaption' )
] );

// Create element with specific options.
writer.createContainerElement( 'figure', { class: 'image' }, [
	writer.createEmptyElement( 'img' ),
	writer.createContainerElement( 'figcaption' )
], { renderUnsafeAttributes: [ 'foo' ] } );
```

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/downcastwriter.ts#L332)

#### Parameters

* `name: string`

  Name of the element.

* `attributes: ViewElementAttributes`

  Elements attributes.

* `children: ViewNode | Iterable<ViewNode>`

  A node or a list of nodes to be inserted into the created element. If no children were specified, element's `options` can be passed in this argument.

* `options?: object`

  Element's options.

  Properties

  * `options.renderUnsafeAttributes?: Array<string>`

    A list of attribute names that should be rendered in the editing pipeline even though they would normally be filtered out by unsafe attribute detection mechanisms.

#### Returns

* `ViewContainerElement`

  Created element.

<a id="function-createContainerElement:WITHOUT_CHILDREN">

### `createContainerElement( name, attributes?, options? = { options.renderUnsafeAttributes? } ) → ViewContainerElement`

Creates a new [`ViewContainerElement`](module_engine_view_containerelement-ViewContainerElement.md).

```typescript
writer.createContainerElement( 'p' );

// Create element with custom attributes.
writer.createContainerElement( 'div', { id: 'foo-bar', 'data-baz': '123' } );

// Create element with custom styles.
writer.createContainerElement( 'p', { style: 'font-weight: bold; padding-bottom: 10px' } );

// Create element with custom classes.
writer.createContainerElement( 'p', { class: 'foo bar baz' } );

// Create element with specific options.
writer.createContainerElement( 'span', { class: 'placeholder' }, { renderUnsafeAttributes: [ 'foo' ] } );
```

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/downcastwriter.ts#L299)

#### Parameters

* `name: string`

  Name of the element.

* `attributes?: ViewElementAttributes`

  Elements attributes.

* `options?: object`

  Element's options.

  Properties

  * `options.renderUnsafeAttributes?: Array<string>`

    A list of attribute names that should be rendered in the editing pipeline even though they would normally be filtered out by unsafe attribute detection mechanisms.

#### Returns

* `ViewContainerElement`

  Created element.

<a id="function-createDocumentFragment">

### `createDocumentFragment( children? ) → ViewDocumentFragment`

Creates a new [`ViewDocumentFragment`](module_engine_view_documentfragment-ViewDocumentFragment.md) instance.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/downcastwriter.ts#L205)

#### Parameters

* `children?: ViewNode | Iterable<ViewNode>`

  A list of nodes to be inserted into the created document fragment.

#### Returns

* `ViewDocumentFragment`

  The created document fragment.

<a id="function-createEditableElement">

### `createEditableElement( name, attributes?, options = { options.renderUnsafeAttributes? } ) → ViewEditableElement`

Creates a new [`ViewEditableElement`](module_engine_view_editableelement-ViewEditableElement.md).

```typescript
writer.createEditableElement( 'div' );
writer.createEditableElement( 'div', { id: 'foo-1234' } );
```

Note: The editable element is to be used in the editing pipeline. Usually, together with [`toWidgetEditable()`](module_widget_utils.md#function-toWidgetEditable).

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/downcastwriter.ts#L379)

#### Parameters

* `name: string`

  Name of the element.

* `attributes?: ViewElementAttributes`

  Elements attributes.

* `options: object`

  Element's options.

  Properties

  * `options.renderUnsafeAttributes?: Array<string>`

    A list of attribute names that should be rendered in the editing pipeline even though they would normally be filtered out by unsafe attribute detection mechanisms.

  Defaults to `{}`

#### Returns

* `ViewEditableElement`

  Created element.

<a id="function-createEmptyElement">

### `createEmptyElement( name, attributes?, options = { options.renderUnsafeAttributes? } ) → ViewEmptyElement`

Creates a new [`ViewEmptyElement`](module_engine_view_emptyelement-ViewEmptyElement.md).

```typescript
writer.createEmptyElement( 'img' );
writer.createEmptyElement( 'img', { id: 'foo-1234' } );
```

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/downcastwriter.ts#L410)

#### Parameters

* `name: string`

  Name of the element.

* `attributes?: ViewElementAttributes`

  Elements attributes.

* `options: object`

  Element's options.

  Properties

  * `options.renderUnsafeAttributes?: Array<string>`

    A list of attribute names that should be rendered in the editing pipeline even though they would normally be filtered out by unsafe attribute detection mechanisms.

  Defaults to `{}`

#### Returns

* `ViewEmptyElement`

  Created element.

<a id="function-createPositionAfter">

### `createPositionAfter( item ) → ViewPosition`

Creates a new position after given view item.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/downcastwriter.ts#L1306)

#### Parameters

* `item: ViewItem`

  View item after which the position should be located.

#### Returns

* `ViewPosition`

<a id="function-createPositionAt">

### `createPositionAt( itemOrPosition, offset? ) → ViewPosition`

Creates position at the given location. The location can be specified as:

* a [position](module_engine_view_position-ViewPosition.md),
* parent element and offset (offset defaults to `0`),
* parent element and `'end'` (sets position at the end of that element),
* [view item](module_engine_view_item-ViewItem.md) and `'before'` or `'after'` (sets position before or after given view item).

This method is a shortcut to other constructors such as:

* [`createPositionBefore`](#function-createPositionBefore),
* [`createPositionAfter`](#function-createPositionAfter),

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/downcastwriter.ts#L1297)

#### Parameters

* `itemOrPosition: ViewPosition | ViewItem`

* `offset?: ViewPositionOffset`

  Offset or one of the flags. Used only when the first parameter is a [view item](module_engine_view_item-ViewItem.md).

#### Returns

* `ViewPosition`

<a id="function-createPositionBefore">

### `createPositionBefore( item ) → ViewPosition`

Creates a new position before given view item.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/downcastwriter.ts#L1315)

#### Parameters

* `item: ViewItem`

  View item before which the position should be located.

#### Returns

* `ViewPosition`

<a id="function-createRange">

### `createRange( start, end? ) → ViewRange`

Creates a range spanning from `start` position to `end` position.

**Note:** This factory method creates its own [`ViewPosition`](module_engine_view_position-ViewPosition.md) instances basing on passed values.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/downcastwriter.ts#L1327)

#### Parameters

* `start: ViewPosition`

  Start position.

* `end?: ViewPosition | null`

  End position. If not set, range will be collapsed at `start` position.

#### Returns

* `ViewRange`

<a id="function-createRangeIn">

### `createRangeIn( element ) → ViewRange`

Creates a range inside an [element](module_engine_view_element-ViewElement.md) which starts before the first child of that element and ends after the last child of that element.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/downcastwriter.ts#L1344)

#### Parameters

* `element: ViewElement | ViewDocumentFragment`

  Element which is a parent for the range.

#### Returns

* `ViewRange`

<a id="function-createRangeOn">

### `createRangeOn( item ) → ViewRange`

Creates a range that starts before given [view item](module_engine_view_item-ViewItem.md) and ends after it.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/downcastwriter.ts#L1334)

#### Parameters

* `item: ViewItem`

#### Returns

* `ViewRange`

<a id="function-createRawElement">

### `createRawElement( name, attributes?, renderFunction?, options = { options.renderUnsafeAttributes? } ) → ViewRawElement`

Creates a new [`ViewRawElement`](module_engine_view_rawelement-ViewRawElement.md).

```typescript
writer.createRawElement( 'span', { id: 'foo-1234' }, function( domElement ) {
	domElement.innerHTML = '<b>This is the raw content of the raw element.</b>';
} );
```

Raw elements work as data containers ("wrappers", "sandboxes") but their children are not managed or even recognized by the editor. This encapsulation allows integrations to maintain custom DOM structures in the editor content without, for instance, worrying about compatibility with other editor features. Raw elements are a perfect tool for integration with external frameworks and data sources.

Unlike [UI elements](#function-createUIElement), raw elements act like "real" editor content (similar to [`ViewContainerElement`](module_engine_view_containerelement-ViewContainerElement.md) or [`ViewEmptyElement`](module_engine_view_emptyelement-ViewEmptyElement.md)), and they are considered by the editor selection.

You should not use raw elements to render the UI in the editor content. Check out [`#createUIElement()`](#function-createUIElement) instead.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/downcastwriter.ts#L498)

#### Parameters

* `name: string`

  The name of the element.

* `attributes?: ViewElementAttributes`

  Element attributes.

* `renderFunction?: ( domElement: HTMLElement, domConverter: ViewDomConverter ) => void`

  A custom render function.

* `options: object`

  Element's options.

  Properties

  * `options.renderUnsafeAttributes?: Array<string>`

    A list of attribute names that should be rendered in the editing pipeline even though they would normally be filtered out by unsafe attribute detection mechanisms.

  Defaults to `{}`

#### Returns

* `ViewRawElement`

  The created element.

<a id="function-createSelection:SELECTABLE">

### `createSelection( selectable?, option? ) → ViewSelection`

Creates new [`ViewSelection`](module_engine_view_selection-ViewSelection.md) instance.

```typescript
// Creates empty selection without ranges.
const selection = writer.createSelection();

// Creates selection at the given range.
const range = writer.createRange( start, end );
const selection = writer.createSelection( range );

// Creates selection at the given ranges
const ranges = [ writer.createRange( start1, end2 ), writer.createRange( star2, end2 ) ];
const selection = writer.createSelection( ranges );

// Creates selection from the other selection.
const otherSelection = writer.createSelection();
const selection = writer.createSelection( otherSelection );

// Creates selection from the document selection.
const selection = writer.createSelection( editor.editing.view.document.selection );

// Creates selection at the given position.
const position = writer.createPositionFromPath( root, path );
const selection = writer.createSelection( position );
```

`Selection`'s constructor allow passing additional options (`backward`, `fake` and `label`) as the last argument.

```typescript
// Creates backward selection.
const selection = writer.createSelection( range, { backward: true } );
```

Fake selection does not render as browser native selection over selected elements and is hidden to the user. This way, no native selection UI artifacts are displayed to the user and selection over elements can be represented in other way, for example by applying proper CSS class.

Additionally fake's selection label can be provided. It will be used to describe fake selection in DOM (and be properly handled by screen readers).

```typescript
// Creates fake selection with label.
const selection = writer.createSelection( range, { fake: true, label: 'foo' } );
```

See also: [`createSelection( node, placeOrOffset, options )`](#function-createSelection:NODE_OFFSET).

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/downcastwriter.ts#L1440)

#### Parameters

* `selectable?: ViewPosition | ViewRange | ViewSelection | ViewDocumentSelection | Iterable<ViewRange> | null`
* `option?: ViewSelectionOptions`

#### Returns

* `ViewSelection`

<a id="function-createSelection:NODE_OFFSET">

### `createSelection( selectable, placeOrOffset, options? ) → ViewSelection`

Creates new [`ViewSelection`](module_engine_view_selection-ViewSelection.md) instance.

```typescript
// Creates collapsed selection at the position of given item and offset.
const paragraph = writer.createContainerElement( 'p' );
const selection = writer.createSelection( paragraph, offset );

// Creates a range inside an element which starts before the
// first child of that element and ends after the last child of that element.
const selection = writer.createSelection( paragraph, 'in' );

// Creates a range on an item which starts before the item and ends
// just after the item.
const selection = writer.createSelection( paragraph, 'on' );
```

`Selection`'s constructor allow passing additional options (`backward`, `fake` and `label`) as the last argument.

```typescript
// Creates backward selection.
const selection = writer.createSelection( element, 'in', { backward: true } );
```

Fake selection does not render as browser native selection over selected elements and is hidden to the user. This way, no native selection UI artifacts are displayed to the user and selection over elements can be represented in other way, for example by applying proper CSS class.

Additionally fake's selection label can be provided. It will be used to describe fake selection in DOM (and be properly handled by screen readers).

```typescript
// Creates fake selection with label.
const selection = writer.createSelection( element, 'in', { fake: true, label: 'foo' } );
```

See also: [`createSelection( selectable, options )`](#function-createSelection:SELECTABLE).

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/downcastwriter.ts#L1388)

#### Parameters

* `selectable: ViewNode`
* `placeOrOffset: ViewPlaceOrOffset`
* `options?: ViewSelectionOptions`

#### Returns

* `ViewSelection`

<a id="function-createSlot">

### `createSlot( modeOrFilter ) → ViewElement`

Creates placeholders for child elements of the [`elementToStructure()`](module_engine_conversion_downcasthelpers-DowncastHelpers.md#function-elementToStructure) conversion helper.

```typescript
const viewSlot = conversionApi.writer.createSlot();
const viewPosition = conversionApi.writer.createPositionAt( viewElement, 0 );

conversionApi.writer.insert( viewPosition, viewSlot );
```

It could be filtered down to a specific subset of children (only `<foo>` model elements in this case):

```typescript
const viewSlot = conversionApi.writer.createSlot( node => node.is( 'element', 'foo' ) );
const viewPosition = conversionApi.writer.createPositionAt( viewElement, 0 );

conversionApi.writer.insert( viewPosition, viewSlot );
```

While providing a filtered slot, make sure to provide slots for all child nodes. A single node cannot be downcasted into multiple slots.

**Note**: You should not change the order of nodes. View elements should be in the same order as model nodes.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/downcastwriter.ts#L1475)

#### Parameters

* `modeOrFilter: 'children' | DowncastSlotFilter`

  The filter for child nodes.

  Defaults to `'children'`

#### Returns

* `ViewElement`

  The slot element to be placed in to the view structure while processing [`elementToStructure()`](module_engine_conversion_downcasthelpers-DowncastHelpers.md#function-elementToStructure).

<a id="function-createText">

### `createText( data ) → ViewText`

Creates a new [text node](module_engine_view_text-ViewText.md).

```typescript
writer.createText( 'foo' );
```

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/downcastwriter.ts#L219)

#### Parameters

* `data: string`

  The text's data.

#### Returns

* `ViewText`

  The created text node.

<a id="function-createUIElement">

### `createUIElement( name, attributes?, renderFunction? ) → ViewUIElement`

Creates a new [`ViewUIElement`](module_engine_view_uielement-ViewUIElement.md).

```typescript
writer.createUIElement( 'span' );
writer.createUIElement( 'span', { id: 'foo-1234' } );
```

A custom render function can be provided as the third parameter:

```typescript
writer.createUIElement( 'span', null, function( domDocument ) {
	const domElement = this.toDomElement( domDocument );
	domElement.innerHTML = '<b>this is ui element</b>';

	return domElement;
} );
```

Unlike [raw elements](#function-createRawElement), UI elements are by no means editor content, for instance, they are ignored by the editor selection system.

You should not use UI elements as data containers. Check out [`createRawElement`](#function-createRawElement) instead.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/downcastwriter.ts#L455)

#### Parameters

* `name: string`

  The name of the element.

* `attributes?: ViewElementAttributes`

  Element attributes.

* `renderFunction?: ( this: ViewUIElement, domDocument: Document, domConverter: ViewDomConverter ) => HTMLElement`

  A custom render function.

#### Returns

* `ViewUIElement`

  The created element.

<a id="function-insert">

### `insert( position, nodes ) → ViewRange`

Inserts a node or nodes at specified position. Takes care about breaking attributes before insertion and merging them afterwards.

Throws [CKEditorError](module_utils_ckeditorerror-CKEditorError.md) `view-writer-insert-invalid-node` when nodes to insert contains instances that are not [Texts](module_engine_view_text-ViewText.md), [ViewAttributeElements](module_engine_view_attributeelement-ViewAttributeElement.md), [ViewContainerElements](module_engine_view_containerelement-ViewContainerElement.md), [ViewEmptyElements](module_engine_view_emptyelement-ViewEmptyElement.md), [RawElements](module_engine_view_rawelement-ViewRawElement.md) or [UIElements](module_engine_view_uielement-ViewUIElement.md).

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/downcastwriter.ts#L953)

#### Parameters

* `position: ViewPosition`

  Insertion position.

* `nodes: ViewNode | Iterable<ViewNode>`

  Node or nodes to insert.

#### Returns

* `ViewRange`

  Range around inserted nodes.

<a id="function-mergeAttributes">

### `mergeAttributes( position ) → ViewPosition`

Merges [attribute elements](module_engine_view_attributeelement-ViewAttributeElement.md). It also merges text nodes if needed. Only [similar](module_engine_view_attributeelement-ViewAttributeElement.md#function-isSimilar) attribute elements can be merged.

In following examples `<p>` is a container and `<b>` is an attribute element:

```html
<p>foo[]bar</p> -> <p>foo{}bar</p>
<p><b>foo</b>[]<b>bar</b></p> -> <p><b>foo{}bar</b></p>
<p><b foo="bar">a</b>[]<b foo="baz">b</b></p> -> <p><b foo="bar">a</b>[]<b foo="baz">b</b></p>
```

It will also take care about empty attributes when merging:

```html
<p><b>[]</b></p> -> <p>[]</p>
<p><b>foo</b><i>[]</i><b>bar</b></p> -> <p><b>foo{}bar</b></p>
```

**Note:** Difference between [mergeAttributes](#function-mergeAttributes) and [mergeContainers](#function-mergeContainers) is that `mergeAttributes` merges two [attribute elements](module_engine_view_attributeelement-ViewAttributeElement.md) or [text nodes](module_engine_view_text-ViewText.md) while `mergeContainer` merges two [container elements](module_engine_view_containerelement-ViewContainerElement.md).

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/downcastwriter.ts#L842)

#### Parameters

* `position: ViewPosition`

  Merge position.

#### Returns

* `ViewPosition`

  Position after merge.

#### Related:

* [ViewAttributeElement](module_engine_view_attributeelement-ViewAttributeElement.md)
* [ViewContainerElement](module_engine_view_containerelement-ViewContainerElement.md)
* [ViewDowncastWriter#mergeContainers](#function-mergeContainers)

<a id="function-mergeContainers">

### `mergeContainers( position ) → ViewPosition`

Merges two [container elements](module_engine_view_containerelement-ViewContainerElement.md) that are before and after given position. Precisely, the element after the position is removed and it's contents are moved to element before the position.

```html
<p>foo</p>^<p>bar</p> -> <p>foo^bar</p>
<div>foo</div>^<p>bar</p> -> <div>foo^bar</div>
```

**Note:** Difference between [mergeAttributes](#function-mergeAttributes) and [mergeContainers](#function-mergeContainers) is that `mergeAttributes` merges two [attribute elements](module_engine_view_attributeelement-ViewAttributeElement.md) or [text nodes](module_engine_view_text-ViewText.md) while `mergeContainer` merges two [container elements](module_engine_view_containerelement-ViewContainerElement.md).

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/downcastwriter.ts#L913)

#### Parameters

* `position: ViewPosition`

  Merge position.

#### Returns

* `ViewPosition`

  Position after merge.

#### Related:

* [ViewAttributeElement](module_engine_view_attributeelement-ViewAttributeElement.md)
* [ViewContainerElement](module_engine_view_containerelement-ViewContainerElement.md)
* [ViewDowncastWriter#mergeAttributes](#function-mergeAttributes)

<a id="function-move">

### `move( sourceRange, targetPosition ) → ViewRange`

Moves nodes from provided range to target position.

Throws [CKEditorError](module_utils_ckeditorerror-CKEditorError.md) `view-writer-invalid-range-container` when [start](module_engine_view_range-ViewRange.md#member-start) and [end](module_engine_view_range-ViewRange.md#member-end) positions are not placed inside same parent container.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/downcastwriter.ts#L1118)

#### Parameters

* `sourceRange: ViewRange`

  Range containing nodes to move.

* `targetPosition: ViewPosition`

  Position to insert.

#### Returns

* `ViewRange`

  Range in target container. Inserted nodes are placed between [start](module_engine_view_range-ViewRange.md#member-start) and [end](module_engine_view_range-ViewRange.md#member-end) positions.

<a id="function-remove">

### `remove( rangeOrItem ) → ViewDocumentFragment`

Removes provided range from the container.

Throws [CKEditorError](module_utils_ckeditorerror-CKEditorError.md) `view-writer-invalid-range-container` when [start](module_engine_view_range-ViewRange.md#member-start) and [end](module_engine_view_range-ViewRange.md#member-end) positions are not placed inside same parent container.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/downcastwriter.ts#L1015)

#### Parameters

* `rangeOrItem: ViewRange | ViewItem`

  Range to remove from container or an [item](module_engine_view_item-ViewItem.md) to remove. If range is provided, after removing, it will be updated to a collapsed range showing the new position.

#### Returns

* `ViewDocumentFragment`

  Document fragment containing removed nodes.

<a id="function-removeAttribute">

### `removeAttribute( key, tokens, element ) → void`

Removes specified tokens from an attribute value (for example class names, style properties). If resulting attribute become empty, the whole attribute is removed.

```typescript
writer.removeAttribute( 'class', 'foo', linkElement );
```

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/downcastwriter.ts#L586)

#### Parameters

* `key: string`

  Attribute key.

* `tokens: ArrayOrItem<string>`

  Tokens to partly remove from attribute value. For example class names or style property names.

* `element: ViewElement`

  The element to remove an attribute of.

#### Returns

* `void`

<a id="function-removeAttribute">

### `removeAttribute( key, element ) → void`

Removes attribute from the element.

```typescript
writer.removeAttribute( 'href', linkElement );
```

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/downcastwriter.ts#L572)

#### Parameters

* `key: string`

  Attribute key.

* `element: ViewElement`

  The element to remove an attribute of.

#### Returns

* `void`

<a id="function-removeClass">

### `removeClass( className, element ) → void`

Removes specified class from the element.

```typescript
writer.removeClass( 'foo', linkElement );
writer.removeClass( [ 'foo', 'bar' ], linkElement );
```

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/downcastwriter.ts#L616)

#### Parameters

* `className: string | Array<string>`
* `element: ViewElement`

#### Returns

* `void`

<a id="function-removeCustomProperty">

### `removeCustomProperty( key, element ) → boolean`

Removes a custom property stored under the given key.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/downcastwriter.ts#L700)

#### Parameters

* `key: string | symbol`
* `element: ViewElement | ViewDocumentFragment`

#### Returns

* `boolean`

  Returns true if property was removed.

<a id="function-removeStyle">

### `removeStyle( property, element ) → void`

Removes specified style from the element.

```typescript
writer.removeStyle( 'color', element ); // Removes 'color' style.
writer.removeStyle( [ 'color', 'border-top' ], element ); // Removes both 'color' and 'border-top' styles.
```

**Note**: This method can work with normalized style names if [a particular style processor rule is enabled](module_engine_controller_datacontroller-DataController.md#function-addStyleProcessorRules). See [`StylesMap#remove()`](module_engine_view_stylesmap-StylesMap.md#function-remove) for details.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/downcastwriter.ts#L683)

#### Parameters

* `property: string | Array<string>`
* `element: ViewElement`

#### Returns

* `void`

<a id="function-rename">

### `rename( newName, viewElement ) → ViewContainerElement`

Renames element by creating a copy of renamed element but with changed name and then moving contents of the old element to the new one. Keep in mind that this will invalidate all [positions](module_engine_view_position-ViewPosition.md) which has renamed element as [a parent](module_engine_view_position-ViewPosition.md#member-parent).

New element has to be created because `Element#tagName` property in DOM is readonly.

Since this function creates a new element and removes the given one, the new element is returned to keep reference.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/downcastwriter.ts#L1254)

#### Parameters

* `newName: string`

  New name for element.

* `viewElement: ViewContainerElement`

  Element to be renamed.

#### Returns

* `ViewContainerElement`

  Element created due to rename.

<a id="function-setAttribute">

### `setAttribute( key, value, overwrite, element ) → void`

Adds or overwrites the element's attribute with a specified key and value. Note that for tokenized attributes it allows the `reset` parameter to specify if the previous attribute value should be overwritten or a new token (class name, style property) should be added.

```typescript
writer.setAttribute( 'href', 'http://ckeditor.com', linkElement );
writer.setAttribute( 'class', 'foo', false, element );
```

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/downcastwriter.ts#L547)

#### Parameters

* `key: string`

  The attribute key.

* `value: unknown`

  The attribute value.

* `overwrite: boolean`

  Whether tokenized attribute should overwrite the attribute value or just add a token.

* `element: ViewElement`

  The element to set an attribute on.

#### Returns

* `void`

<a id="function-setAttribute">

### `setAttribute( key, value, element ) → void`

Adds or overwrites the element's attribute with a specified key and value.

```typescript
writer.setAttribute( 'href', 'http://ckeditor.com', linkElement );
```

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/downcastwriter.ts#L530)

#### Parameters

* `key: string`

  The attribute key.

* `value: unknown`

  The attribute value.

* `element: ViewElement`

  The element to set an attribute on.

#### Returns

* `void`

<a id="function-setCustomProperty">

### `setCustomProperty( key, value, element ) → void`

Sets a custom property on element. Unlike attributes, custom properties are not rendered to the DOM, so they can be used to add special data to elements.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/downcastwriter.ts#L691)

#### Parameters

* `key: string | symbol`
* `value: unknown`
* `element: ViewElement | ViewDocumentFragment`

#### Returns

* `void`

<a id="function-setSelection:SELECTABLE">

### `setSelection( selectable, options? ) → void`

Sets [selection's](module_engine_view_documentselection-ViewDocumentSelection.md) ranges and direction to the specified location based on the given [selectable](module_engine_view_selection-ViewSelectable.md).

Usage:

```typescript
// Sets selection to the given range.
const range = writer.createRange( start, end );
writer.setSelection( range );

// Sets backward selection to the given range.
const range = writer.createRange( start, end );
writer.setSelection( range );

// Sets selection to given ranges.
const ranges = [ writer.createRange( start1, end2 ), writer.createRange( start2, end2 ) ];
writer.setSelection( range );

// Sets selection to the other selection.
const otherSelection = writer.createSelection();
writer.setSelection( otherSelection );

// Sets collapsed selection at the given position.
const position = writer.createPositionFromPath( root, path );
writer.setSelection( position );

// Removes all ranges.
writer.setSelection( null );
```

`ViewDowncastWriter#setSelection()` allow passing additional options (`backward`, `fake` and `label`) as the last argument.

```typescript
// Sets selection as backward.
writer.setSelection( range, { backward: true } );

// Sets selection as fake.
// Fake selection does not render as browser native selection over selected elements and is hidden to the user.
// This way, no native selection UI artifacts are displayed to the user and selection over elements can be
// represented in other way, for example by applying proper CSS class.
writer.setSelection( range, { fake: true } );

// Additionally fake's selection label can be provided. It will be used to describe fake selection in DOM
// (and be  properly handled by screen readers).
writer.setSelection( range, { fake: true, label: 'foo' } );
```

See also: [`setSelection( node, placeOrOffset, options )`](#function-setSelection:NODE_OFFSET).

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/downcastwriter.ts#L179)

#### Parameters

* `selectable: ViewPosition | ViewRange | ViewSelection | ViewDocumentSelection | Iterable<ViewRange> | null`
* `options?: ViewSelectionOptions`

#### Returns

* `void`

<a id="function-setSelection:NODE_OFFSET">

### `setSelection( selectable, placeOrOffset, options? ) → void`

Sets [selection's](module_engine_view_documentselection-ViewDocumentSelection.md) ranges and direction to the specified location based on the given [selectable](module_engine_view_selection-ViewSelectable.md).

Usage:

```typescript
// Sets collapsed selection at the position of given item and offset.
const paragraph = writer.createContainerElement( 'p' );
writer.setSelection( paragraph, offset );
```

Creates a range inside an [element](module_engine_view_element-ViewElement.md) which starts before the first child of that element and ends after the last child of that element.

```typescript
writer.setSelection( paragraph, 'in' );
```

Creates a range on the [item](module_engine_view_item-ViewItem.md) which starts before the item and ends just after the item.

```typescript
writer.setSelection( paragraph, 'on' );
```

`ViewDowncastWriter#setSelection()` allow passing additional options (`backward`, `fake` and `label`) as the last argument.

```typescript
// Sets selection as backward.
writer.setSelection( element, 'in', { backward: true } );

// Sets selection as fake.
// Fake selection does not render as browser native selection over selected elements and is hidden to the user.
// This way, no native selection UI artifacts are displayed to the user and selection over elements can be
// represented in other way, for example by applying proper CSS class.
writer.setSelection( element, 'in', { fake: true } );

// Additionally fake's selection label can be provided. It will be used to describe fake selection in DOM
// (and be  properly handled by screen readers).
writer.setSelection( element, 'in', { fake: true, label: 'foo' } );
```

See also: [`setSelection( selectable, options )`](#function-setSelection:SELECTABLE).

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/downcastwriter.ts#L125)

#### Parameters

* `selectable: ViewNode`
* `placeOrOffset: ViewPlaceOrOffset`
* `options?: ViewSelectionOptions`

#### Returns

* `void`

<a id="function-setSelectionFocus">

### `setSelectionFocus( itemOrPosition, offset? ) → void`

Moves [selection's focus](module_engine_view_documentselection-ViewDocumentSelection.md#member-focus) to the specified location.

The location can be specified in the same form as [view.createPositionAt()](module_engine_view_view-EditingView.md#function-createPositionAt) parameters.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/downcastwriter.ts#L195)

#### Parameters

* `itemOrPosition: ViewPosition | ViewItem`

* `offset?: ViewPositionOffset`

  Offset or one of the flags. Used only when the first parameter is a [view item](module_engine_view_item-ViewItem.md).

#### Returns

* `void`

<a id="function-setStyle:OBJECT">

### `setStyle( property, element ) → void`

Adds many styles to the element.

```typescript
writer.setStyle( {
	color: 'red',
	position: 'fixed'
}, element );
```

**Note**: The passed style can be normalized if [a particular style processor rule is enabled](module_engine_controller_datacontroller-DataController.md#function-addStyleProcessorRules). See [`StylesMap#set()`](module_engine_view_stylesmap-StylesMap.md#function-set:KEY_VALUE) for details.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/downcastwriter.ts#L656)

#### Parameters

* `property: Record<string, StyleValue>`

  Object with key - value pairs.

* `element: ViewElement`

  Element to set styles on.

#### Returns

* `void`

<a id="function-setStyle:KEY_VALUE">

### `setStyle( property, value, element ) → void`

Adds style to the element.

```typescript
writer.setStyle( 'color', 'red', element );
```

**Note**: The passed style can be normalized if [a particular style processor rule is enabled](module_engine_controller_datacontroller-DataController.md#function-addStyleProcessorRules). See [`StylesMap#set()`](module_engine_view_stylesmap-StylesMap.md#function-set:KEY_VALUE) for details.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/downcastwriter.ts#L636)

#### Parameters

* `property: string`

  Property name.

* `value: StyleValue`

  Value to set.

* `element: ViewElement`

  Element to set styles on.

#### Returns

* `void`

<a id="function-unwrap">

### `unwrap( range, attribute ) → ViewRange`

Unwraps nodes within provided range from attribute element.

Throws [CKEditorError](module_utils_ckeditorerror-CKEditorError.md) `view-writer-invalid-range-container` when [start](module_engine_view_range-ViewRange.md#member-start) and [end](module_engine_view_range-ViewRange.md#member-end) positions are not placed inside same parent container.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/downcastwriter.ts#L1200)

#### Parameters

* `range: ViewRange`
* `attribute: ViewAttributeElement`

#### Returns

* `ViewRange`

<a id="function-wrap">

### `wrap( range, attribute ) → ViewRange`

Wraps elements within range with provided [ViewAttributeElement](module_engine_view_attributeelement-ViewAttributeElement.md). If a collapsed range is provided, it will be wrapped only if it is equal to view selection.

If a collapsed range was passed and is same as selection, the selection will be moved to the inside of the wrapped attribute element.

Throws [`CKEditorError`](module_utils_ckeditorerror-CKEditorError.md) `view-writer-invalid-range-container` when [`start`](module_engine_view_range-ViewRange.md#member-start) and [`end`](module_engine_view_range-ViewRange.md#member-end) positions are not placed inside same parent container.

Throws [`CKEditorError`](module_utils_ckeditorerror-CKEditorError.md) `view-writer-wrap-invalid-attribute` when passed attribute element is not an instance of [ViewAttributeElement](module_engine_view_attributeelement-ViewAttributeElement.md).

Throws [`CKEditorError`](module_utils_ckeditorerror-CKEditorError.md) `view-writer-wrap-nonselection-collapsed-range` when passed range is collapsed and different than view selection.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/downcastwriter.ts#L1160)

#### Parameters

* `range: ViewRange`

  Range to wrap.

* `attribute: ViewAttributeElement`

  Attribute element to use as wrapper.

#### Returns

* `ViewRange`

  range Range after wrapping, spanning over wrapping attribute element.

<a id="function-_clearSlotFactory">

### `_clearSlotFactory() → void` _(internal)_

Clears the registered slot factory.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/downcastwriter.ts#L1505)

#### Returns

* `void`

<a id="function-_registerSlotFactory">

### `_registerSlotFactory( slotFactory ) → void` _(internal)_

Registers a slot factory.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/downcastwriter.ts#L1494)

#### Parameters

* `slotFactory: ( writer: ViewDowncastWriter, modeOrFilter: 'children' | DowncastSlotFilter ) => ViewElement`

  The slot factory.

#### Returns

* `void`

<a id="function-_addToClonedElementsGroup">

### `_addToClonedElementsGroup( element ) → void` _(private)_

Stores the information that an [attribute element](module_engine_view_attributeelement-ViewAttributeElement.md) was added to the tree. Saves the reference to the group in the given element and updates the group, so other elements from the group now keep a reference to the given attribute element.

The clones group can be obtained using [`getElementsWithSameId`](module_engine_view_attributeelement-ViewAttributeElement.md#function-getElementsWithSameId).

Does nothing if added element has no [id](module_engine_view_attributeelement-ViewAttributeElement.md#member-id).

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/downcastwriter.ts#L1993)

#### Parameters

* `element: ViewNode`

  Attribute element to save.

#### Returns

* `void`

<a id="function-_breakAttributes">

### `_breakAttributes( position, forceSplitText ) → ViewPosition` _(private)_

Helper function used by other `ViewDowncastWriter` methods. Breaks attribute elements at given position.

Throws [CKEditorError](module_utils_ckeditorerror-CKEditorError.md) `view-writer-cannot-break-empty-element` when break position is placed inside [ViewEmptyElement](module_engine_view_emptyelement-ViewEmptyElement.md).

Throws [CKEditorError](module_utils_ckeditorerror-CKEditorError.md) `view-writer-cannot-break-ui-element` when break position is placed inside [UIElement](module_engine_view_uielement-ViewUIElement.md).

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/downcastwriter.ts#L1874)

#### Parameters

* `position: ViewPosition`

  Position where to break attributes.

* `forceSplitText: boolean`

  If set to `true`, will break text nodes even if they are directly in container element. This behavior will result in incorrect view state, but is needed by other view writing methods which then fixes view state.

  Defaults to `false`

#### Returns

* `ViewPosition`

  New position after breaking the attributes.

<a id="function-_breakAttributesRange">

### `_breakAttributesRange( range, forceSplitText ) → ViewRange` _(private)_

Helper function used by other `ViewDowncastWriter` methods. Breaks attribute elements at the boundaries of given range.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/downcastwriter.ts#L1837)

#### Parameters

* `range: ViewRange`

  Range which `start` and `end` positions will be used to break attributes.

* `forceSplitText: boolean`

  If set to `true`, will break text nodes even if they are directly in container element. This behavior will result in incorrect view state, but is needed by other view writing methods which then fixes view state.

  Defaults to `false`

#### Returns

* `ViewRange`

  New range with located at break positions.

<a id="function-_insertNodes">

### `_insertNodes( position, nodes, breakAttributes ) → ViewRange` _(private)_

Inserts a node or nodes at the specified position. Takes care of breaking attributes before insertion and merging them afterwards if requested by the breakAttributes param.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/downcastwriter.ts#L1518)

#### Parameters

* `position: ViewPosition`

  Insertion position.

* `nodes: Iterable<ViewNode>`

  Node or nodes to insert.

* `breakAttributes: boolean`

  Whether attributes should be broken.

#### Returns

* `ViewRange`

  Range around inserted nodes.

<a id="function-_removeFromClonedElementsGroup">

### `_removeFromClonedElementsGroup( element ) → void` _(private)_

Removes all the information about the given [attribute element](module_engine_view_attributeelement-ViewAttributeElement.md) from its clones group.

Keep in mind, that the element will still keep a reference to the group (but the group will not keep a reference to it). This allows to reference the whole group even if the element was already removed from the tree.

Does nothing if the element has no [id](module_engine_view_attributeelement-ViewAttributeElement.md#member-id).

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/downcastwriter.ts#L2035)

#### Parameters

* `element: ViewNode`

  Attribute element to remove.

#### Returns

* `void`

<a id="function-_unwrapChildren">

### `_unwrapChildren( parent, startOffset, endOffset, unwrapElement ) → ViewRange` _(private)_

Unwraps children from provided `unwrapElement`. Only children contained in `parent` element between `startOffset` and `endOffset` will be unwrapped.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/downcastwriter.ts#L1651)

#### Parameters

* `parent: ViewElement`
* `startOffset: number`
* `endOffset: number`
* `unwrapElement: ViewAttributeElement`

#### Returns

* `ViewRange`

<a id="function-_wrapChildren">

### `_wrapChildren( parent, startOffset, endOffset, wrapElement ) → ViewRange` _(private)_

Wraps children with provided `wrapElement`. Only children contained in `parent` element between `startOffset` and `endOffset` will be wrapped.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/downcastwriter.ts#L1572)

#### Parameters

* `parent: ViewElement`
* `startOffset: number`
* `endOffset: number`
* `wrapElement: ViewAttributeElement`

#### Returns

* `ViewRange`

<a id="function-_wrapPosition">

### `_wrapPosition( position, attribute ) → ViewPosition` _(private)_

Helper function for [`wrap`](#function-wrap). Wraps position with provided attribute element. This method will also merge newly added attribute element with its siblings whenever possible.

Throws [`CKEditorError`](module_utils_ckeditorerror-CKEditorError.md) `view-writer-wrap-invalid-attribute` when passed attribute element is not an instance of [ViewAttributeElement](module_engine_view_attributeelement-ViewAttributeElement.md).

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/downcastwriter.ts#L1788)

#### Parameters

* `position: ViewPosition`
* `attribute: ViewAttributeElement`

#### Returns

* `ViewPosition`

  New position after wrapping.

<a id="function-_wrapRange">

### `_wrapRange( range, attribute ) → ViewRange` _(private)_

Helper function for `view.writer.wrap`. Wraps range with provided attribute element. This method will also merge newly added attribute element with its siblings whenever possible.

Throws [`CKEditorError`](module_utils_ckeditorerror-CKEditorError.md) `view-writer-wrap-invalid-attribute` when passed attribute element is not an instance of [ViewAttributeElement](module_engine_view_attributeelement-ViewAttributeElement.md).

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/view/downcastwriter.ts#L1759)

#### Parameters

* `range: ViewRange`
* `attribute: ViewAttributeElement`

#### Returns

* `ViewRange`

  New range after wrapping, spanning over wrapping attribute element.

---

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