# list/legacylist/legacyconverters

module

<a id="constants">

## Constants

<a id="constant-cleanList">

### `cleanList: GetCallback<UpcastElementEvent>`

A view-to-model converter for the `<ul>` and `<ol>` view elements that cleans the input view of garbage. This is mostly to clean whitespaces from between the `<li>` view elements inside the view list element, however, also incorrect data can be cleared if the view was incorrect.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-list/src/legacylist/legacyconverters.ts#L439)

<a id="constant-cleanListItem">

### `cleanListItem: GetCallback<UpcastElementEvent>`

A view-to-model converter for the `<li>` elements that cleans whitespace formatting from the input view.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-list/src/legacylist/legacyconverters.ts#L460)

<a id="constant-modelIndentPasteFixer">

### `modelIndentPasteFixer: GetCallback<ModelInsertContentEvent>`

A fixer for pasted content that includes list items.

It fixes indentation of pasted list items so the pasted items match correctly to the context they are pasted into.

Example:

```xml
<listItem listType="bulleted" listIndent=0>A</listItem>
<listItem listType="bulleted" listIndent=1>B^</listItem>
// At ^ paste:  <listItem listType="bulleted" listIndent=4>X</listItem>
//			  <listItem listType="bulleted" listIndent=5>Y</listItem>
<listItem listType="bulleted" listIndent=2>C</listItem>
```

Should become:

```xml
<listItem listType="bulleted" listIndent=0>A</listItem>
<listItem listType="bulleted" listIndent=1>BX</listItem>
<listItem listType="bulleted" listIndent=2>Y/listItem>
<listItem listType="bulleted" listIndent=2>C</listItem>
```

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-list/src/legacylist/legacyconverters.ts#L804)

<a id="constant-modelViewChangeType">

### `modelViewChangeType: GetCallback<DowncastAttributeEvent<ModelElement>>`

A model-to-view converter for the `type` attribute change on the `listItem` model element.

This change means that the `<li>` element parent changes from `<ul>` to `<ol>` (or vice versa). This is accomplished by breaking view elements and changing their name. The next [`modelViewMergeAfterChangeType`](#constant-modelViewMergeAfterChangeType) converter will attempt to merge split nodes.

Splitting this conversion into 2 steps makes it possible to add an additional conversion in the middle. Check [`modelViewChangeType`](module_list_legacytodolist_legacytodolistconverters.md#function-modelViewChangeType) to see an example of it.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-list/src/legacylist/legacyconverters.ts#L141)

<a id="constant-modelViewMergeAfter">

### `modelViewMergeAfter: GetCallback<DowncastRemoveEvent>`

A special model-to-view converter introduced by the [list feature](module_list_legacylist-LegacyList.md). This converter takes care of merging view lists after something is removed or moved from near them.

Example:

```xml
// Model:						// View:
<listItem>foo</listItem>		 <ul><li>foo</li></ul>
<paragraph>xxx</paragraph>	   <p>xxx</p>
<listItem>bar</listItem>		 <ul><li>bar</li></ul>

// After change:				 // Correct view guaranteed by this converter:
<listItem>foo</listItem>		 <ul>
<listItem>bar</listItem>			 <li>foo</li>
									 <li>bar</li>
								 </ul>
```

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-list/src/legacylist/legacyconverters.ts#L381)

<a id="constant-modelViewMergeAfterChangeType">

### `modelViewMergeAfterChangeType: GetCallback<DowncastAttributeEvent<ModelElement>>`

A model-to-view converter that attempts to merge nodes split by [`modelViewChangeType`](#constant-modelViewChangeType).

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-list/src/legacylist/legacyconverters.ts#L168)

<a id="constant-modelViewSplitOnInsert">

### `modelViewSplitOnInsert: GetCallback<DowncastInsertEvent<ModelElement>>`

A special model-to-view converter introduced by the [list feature](module_list_legacylist-LegacyList.md). This converter is fired for insert change of every model item, and should be fired before the actual converter. The converter checks whether the inserted model item is a non-`listItem` element. If it is, and it is inserted inside a view list, the converter breaks the list so the model element is inserted to the view parent element corresponding to its model parent element.

The converter prevents such situations:

```xml
// Model:						// View:
<listItem>foo</listItem>		 <ul>
<listItem>bar</listItem>			 <li>foo</li>
									 <li>bar</li>
								 </ul>

// After change:				 // Correct view guaranteed by this converter:
<listItem>foo</listItem>		 <ul><li>foo</li></ul><p>xxx</p><ul><li>bar</li></ul>
<paragraph>xxx</paragraph>	   // Instead of this wrong view state:
<listItem>bar</listItem>		 <ul><li>foo</li><p>xxx</p><li>bar</li></ul>
```

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-list/src/legacylist/legacyconverters.ts#L256)

<a id="constant-viewModelConverter">

### `viewModelConverter: GetCallback<UpcastElementEvent>`

A view-to-model converter that converts the `<li>` view elements into the `listItem` model elements.

To set correct values of the `listType` and `listIndent` attributes the converter:

* checks `<li>`'s parent,
* stores and increases the `conversionApi.store.indent` value when `<li>`'s sub-items are converted.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-list/src/legacylist/legacyconverters.ts#L402)

<a id="functions">

## Functions

<a id="function-modelChangePostFixer">

### `modelChangePostFixer( model, writer ) → boolean` _(internal)_

Post-fixer that reacts to changes on document and fixes incorrect model states.

In the example below, there is a correct list structure. Then the middle element is removed so the list structure will become incorrect:

```xml
<listItem listType="bulleted" listIndent=0>Item 1</listItem>
<listItem listType="bulleted" listIndent=1>Item 2</listItem>   <--- this is removed.
<listItem listType="bulleted" listIndent=2>Item 3</listItem>
```

The list structure after the middle element is removed:

```xml
<listItem listType="bulleted" listIndent=0>Item 1</listItem>
<listItem listType="bulleted" listIndent=2>Item 3</listItem>
```

Should become:

```xml
<listItem listType="bulleted" listIndent=0>Item 1</listItem>
<listItem listType="bulleted" listIndent=1>Item 3</listItem>   <--- note that indent got post-fixed.
```

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-list/src/legacylist/legacyconverters.ts#L613)

#### Parameters

* `model: Model`

  The data model.

* `writer: ModelWriter`

  The writer to do changes with.

#### Returns

* `boolean`

  `true` if any change has been applied, `false` otherwise.

<a id="function-modelToViewPosition">

### `modelToViewPosition( view ) → GetCallback<MapperModelToViewPositionEvent>` _(internal)_

Returns a callback for model position to view position mapping for [`Mapper`](module_engine_conversion_mapper-Mapper.md). The callback fixes positions between the `listItem` elements that would be incorrectly mapped because of how list items are represented in the model and in the view.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-list/src/legacylist/legacyconverters.ts#L490)

#### Parameters

* `view: EditingView`

#### Returns

* `GetCallback<MapperModelToViewPositionEvent>`

<a id="function-modelViewChangeIndent">

### `modelViewChangeIndent( model ) → GetCallback<DowncastAttributeEvent<ModelElement>>` _(internal)_

A model-to-view converter for the `listIndent` attribute change on the `listItem` model element.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-list/src/legacylist/legacyconverters.ts#L188)

#### Parameters

* `model: Model`

  Model instance.

#### Returns

* `GetCallback<DowncastAttributeEvent<ModelElement>>`

  Returns a conversion callback.

#### Related:

* [DowncastDispatcher#event:attribute](module_engine_conversion_downcastdispatcher-DowncastDispatcher.md#event-attribute)

<a id="function-modelViewInsertion">

### `modelViewInsertion( model ) → GetCallback<DowncastInsertEvent<ModelElement>>` _(internal)_

A model-to-view converter for the `listItem` model element insertion.

It creates a `<ul><li></li><ul>` (or `<ol>`) view structure out of a `listItem` model element, inserts it at the correct position, and merges the list with surrounding lists (if available).

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-list/src/legacylist/legacyconverters.ts#L54)

#### Parameters

* `model: Model`

  Model instance.

#### Returns

* `GetCallback<DowncastInsertEvent<ModelElement>>`

#### Related:

* [DowncastDispatcher#event:insert](module_engine_conversion_downcastdispatcher-DowncastDispatcher.md#event-insert)

<a id="function-modelViewRemove">

### `modelViewRemove( model ) → GetCallback<DowncastRemoveEvent>` _(internal)_

A model-to-view converter for the `listItem` model element removal.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-list/src/legacylist/legacyconverters.ts#L84)

#### Parameters

* `model: Model`

  Model instance.

#### Returns

* `GetCallback<DowncastRemoveEvent>`

  Returns a conversion callback.

#### Related:

* [DowncastDispatcher#event:remove](module_engine_conversion_downcastdispatcher-DowncastDispatcher.md#event-remove)

<a id="function-viewToModelPosition">

### `viewToModelPosition( model ) → GetCallback<MapperViewToModelPositionEvent>` _(internal)_

The callback for view position to model position mapping for [`Mapper`](module_engine_conversion_mapper-Mapper.md). The callback fixes positions between the `<li>` elements that would be incorrectly mapped because of how list items are represented in the model and in the view.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-list/src/legacylist/legacyconverters.ts#L528)

#### Parameters

* `model: Model`

  Model instance.

#### Returns

* `GetCallback<MapperViewToModelPositionEvent>`

  Returns a conversion callback.

#### Related:

* [Mapper#event:viewToModelPosition](module_engine_conversion_mapper-Mapper.md#event-viewToModelPosition)

---

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