# code-block/converters

module

<a id="functions">

## Functions

<a id="function-dataViewToModelCodeBlockInsertion">

### `dataViewToModelCodeBlockInsertion( editingView, languageDefs ) → GetCallback<UpcastElementEvent>` _(internal)_

A view-to-model converter for `<pre>` with the `<code>` HTML.

Sample input:

```html
<pre><code class="language-javascript">foo();bar();</code></pre>
```

Sample output:

```html
<codeBlock language="javascript">foo();bar();</codeBlock>
```

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-code-block/src/converters.ts#L159)

#### Parameters

* `editingView: EditingView`

* `languageDefs: Array<CodeBlockLanguageDefinition>`

  The normalized language configuration passed to the feature.

#### Returns

* `GetCallback<UpcastElementEvent>`

  Returns a conversion callback.

<a id="function-dataViewToModelOrphanNodeConsumer">

### `dataViewToModelOrphanNodeConsumer() → GetCallback<UpcastElementEvent>` _(internal)_

A view-to-model converter that handles orphan text nodes (white spaces, new lines, etc.) that surround `<code>` inside `<pre>`.

Sample input:

```html
// White spaces
<pre> <code>foo()</code> </pre>

// White spaces
<pre>	  <code>foo()</code>	  </pre>

// White spaces
<pre>			<code>foo()</code>			</pre>

// New lines
<pre>
	<code>foo()</code>
</pre>

// Redundant text
<pre>ABC<code>foo()</code>DEF</pre>
```

Unified output for each case:

```html
<codeBlock language="plaintext">foo()</codeBlock>
```

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-code-block/src/converters.ts#L327)

#### Returns

* `GetCallback<UpcastElementEvent>`

  Returns a conversion callback.

<a id="function-dataViewToModelTextNewlinesInsertion">

### `dataViewToModelTextNewlinesInsertion() → GetCallback<UpcastTextEvent>` _(internal)_

A view-to-model converter for new line characters in `<pre>`.

Sample input:

```html
<pre><code class="language-javascript">foo();\nbar();</code></pre>
```

Sample output:

```html
<codeBlock language="javascript">foo();<softBreak></softBreak>bar();</codeBlock>
```

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-code-block/src/converters.ts#L253)

#### Returns

* `GetCallback<UpcastTextEvent>`

  Returns a conversion callback.

<a id="function-modelToDataViewSoftBreakInsertion">

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

A model-to-data view converter for the new line (`softBreak`) separator.

Sample input:

```html
<codeBlock ...>foo();<softBreak></softBreak>bar();</codeBlock>
```

Sample output:

```html
<pre><code ...>foo();\nbar();</code></pre>
```

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-code-block/src/converters.ts#L122)

#### Parameters

* `model: Model`

#### Returns

* `GetCallback<DowncastInsertEvent>`

  Returns a conversion callback.

<a id="function-modelToViewCodeBlockInsertion">

### `modelToViewCodeBlockInsertion( model, languageDefs, useLabels ) → GetCallback<DowncastInsertEvent>` _(internal)_

A model-to-view (both editing and data) converter for the `codeBlock` element.

Sample input:

```html
<codeBlock language="javascript">foo();<softBreak></softBreak>bar();</codeBlock>
```

Sample output (editing):

```html
<pre data-language="JavaScript"><code class="language-javascript">foo();<br />bar();</code></pre>
```

Sample output (data, see [`modelToDataViewSoftBreakInsertion`](#function-modelToDataViewSoftBreakInsertion)):

```html
<pre><code class="language-javascript">foo();\nbar();</code></pre>
```

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-code-block/src/converters.ts#L49)

#### Parameters

* `model: Model`

* `languageDefs: Array<CodeBlockLanguageDefinition>`

  The normalized language configuration passed to the feature.

* `useLabels: boolean`

  When `true`, the `<pre>` element will get a `data-language` attribute with a human–readable label of the language. Used only in the editing.

  Defaults to `false`

#### Returns

* `GetCallback<DowncastInsertEvent>`

  Returns a conversion callback.

---

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