code-block/converters
@ckeditor/ckeditor5-code-block/src/converters
Filtering
Functions
-
dataViewToModelCodeBlockInsertion( editingView, languageDefs ) → GetCallback<UpcastElementEvent>
module:code-block/converters~dataViewToModelCodeBlockInsertion
A view-to-model converter for
<pre>
with the<code>
HTML.Sample input:
<pre><code class="language-javascript">foo();bar();</code></pre>
Sample output:
<codeBlock language="javascript">foo();bar();</codeBlock>
Parameters
editingView : View
languageDefs : Array<CodeBlockLanguageDefinition>
The normalized language configuration passed to the feature.
Returns
GetCallback<UpcastElementEvent>
Returns a conversion callback.
-
dataViewToModelOrphanNodeConsumer() → GetCallback<UpcastElementEvent>
module:code-block/converters~dataViewToModelOrphanNodeConsumer
A view-to-model converter that handles orphan text nodes (white spaces, new lines, etc.) that surround
<code>
inside<pre>
.Sample input:
// 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:
<codeBlock language="plaintext">foo()</codeBlock>
Returns
GetCallback<UpcastElementEvent>
Returns a conversion callback.
-
dataViewToModelTextNewlinesInsertion() → GetCallback<UpcastTextEvent>
module:code-block/converters~dataViewToModelTextNewlinesInsertion
A view-to-model converter for new line characters in
<pre>
.Sample input:
<pre><code class="language-javascript">foo();\nbar();</code></pre>
Sample output:
<codeBlock language="javascript">foo();<softBreak></softBreak>bar();</codeBlock>
Returns
GetCallback<UpcastTextEvent>
Returns a conversion callback.
-
modelToDataViewSoftBreakInsertion( model ) → GetCallback<DowncastInsertEvent>
module:code-block/converters~modelToDataViewSoftBreakInsertion
A model-to-data view converter for the new line (
softBreak
) separator.Sample input:
<codeBlock ...>foo();<softBreak></softBreak>bar();</codeBlock>
Sample output:
<pre><code ...>foo();\nbar();</code></pre>
Parameters
model : Model
Returns
GetCallback<DowncastInsertEvent>
Returns a conversion callback.
-
modelToViewCodeBlockInsertion( model, languageDefs, useLabels ) → GetCallback<DowncastInsertEvent>
module:code-block/converters~modelToViewCodeBlockInsertion
A model-to-view (both editing and data) converter for the
codeBlock
element.Sample input:
<codeBlock language="javascript">foo();<softBreak></softBreak>bar();</codeBlock>
Sample output (editing):
<pre data-language="JavaScript"><code class="language-javascript">foo();<br />bar();</code></pre>
Sample output (data, see
modelToDataViewSoftBreakInsertion
):<pre><code class="language-javascript">foo();\nbar();</code></pre>
Parameters
model : Model
languageDefs : Array<CodeBlockLanguageDefinition>
The normalized language configuration passed to the feature.
useLabels : boolean
When
true
, the<pre>
element will get adata-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.
Every day, we work hard to keep our documentation complete. Have you spotted outdated information? Is something missing? Please report it via our issue tracker.
With the release of version 42.0.0, we have rewritten much of our documentation to reflect the new import paths and features. We appreciate your feedback to help us ensure its accuracy and completeness.