Skip to content

ckeditor5-elements / createVerbatimElement

Function: createVerbatimElement() ​

ts
function createVerbatimElement(
   writer, 
   tag, 
   __namedParameters?
): ViewContainerElement;

Creates the view of a verbatim block in the editor, e.g. a pre: with the VERBATIM_CLASS, and a <br> after its text, which is not content (a UI element).

A browser shows no line after a new line at the end of a pre, and does not type there: the cursor and the text go back to the end of the line before. The <br> makes that last line a line, as in CKEditor's code blocks. It gives an empty block its height too, so the block has no block filler.

ts
conversion.for('editingDowncast').elementToElement({
  model: 'code',
  view: (element, { writer }) => createVerbatimElement(writer, 'pre')
});

The converters of the element schema (elementSchemaConverters) do it already.

Parameters ​

ParameterType
writerViewDowncastWriter
tagstring
__namedParameters?Record<string, string>

Returns ​

ViewContainerElement