ViewStringify (engine/dev-utils)
@ckeditor/ckeditor5-engine/src/dev-utils/view
Private helper class used for converting the view tree to a string.
Filtering
Methods
-
constructor( root, selection, options = { [options.showType], [options.showPriority], [options.ignoreRoot], [options.sameSelectionCharacters], [options.renderUIElements], [options.renderRawElements], [options.domConverter] } )
module:engine/dev-utils/view~ViewStringify#constructor
Creates a view stringify instance.
Parameters
root
selection : DocumentSelection
A selection whose ranges should also be converted to a string.
options : Object
An options object.
Properties[ options.showType ] : Boolean
When set to
true
, the type of elements will be printed (<container:p>
instead of<p>
,<attribute:b>
instead of<b>
and<empty:img>
instead of<img>
).Defaults to
false
[ options.showPriority ] : Boolean
When set to
true
, the attribute element's priority will be printed.Defaults to
false
[ options.ignoreRoot ] : Boolean
When set to
true
, the root's element opening and closing tag will not be outputted.Defaults to
false
[ options.sameSelectionCharacters ] : Boolean
When set to
true
, the selection inside the text is marked as{
and}
and the selection outside the text as[
and]
. When set tofalse
, both are marked as[
and]
.Defaults to
false
[ options.renderUIElements ] : Boolean
When set to
true
, the inner content of eachUIElement
will be printed.Defaults to
false
[ options.renderRawElements ] : Boolean
When set to
true
, the inner content of eachDefaults to
false
[ options.domConverter ] : Object
When set to an actual DomConverter instance, it lets the conversion go through exactly the same flow the editing view is going through, i.e. with view data filtering. Otherwise the simple stub is used.
RawElement
will be printed.Defaults to
{}
-
stringify() → String
module:engine/dev-utils/view~ViewStringify#stringify
Converts the view to a string.
Returns
String
String representation of the view elements.
-
_stringifyElementAttributes( element ) → String
module:engine/dev-utils/view~ViewStringify#_stringifyElementAttributes
private
Converts the passed element attributes to their string representation. If an element has no attributes, an empty string is returned.
-
_stringifyElementClose( element ) → String
module:engine/dev-utils/view~ViewStringify#_stringifyElementClose
private
Converts the passed element to a closing tag. Depending on the current configuration, the closing tag can be simple (
</a>
) or contain a type prefix (</container:p>
,</attribute:a>
or</empty:img>
). -
_stringifyElementId( element ) → String
module:engine/dev-utils/view~ViewStringify#_stringifyElementId
private
Converts the passed element to its id representation.
The id string representation will be returned when the passed element is an instance of attribute element, the element has an id and the current configuration allows to show the id. Otherwise returns an empty string.
Parameters
element : Element
Returns
String
-
_stringifyElementOpen( element ) → String
module:engine/dev-utils/view~ViewStringify#_stringifyElementOpen
private
Converts the passed element to an opening tag.
Depending on the current configuration, the opening tag can be simple (
<a>
), contain a type prefix (<container:p>
,<attribute:a>
or<empty:img>
), contain priority information (<attribute:a view-priority="20">
), or contain element id (<attribute:span view-id="foo">
). Element attributes will also be included (<a href="https://ckeditor.com" name="foobar">
).Parameters
element : Element
Returns
String
-
_stringifyElementPriority( element ) → String
module:engine/dev-utils/view~ViewStringify#_stringifyElementPriority
private
Converts the passed element to its priority representation.
The priority string representation will be returned when the passed element is an instance of attribute element and the current configuration allows to show the priority. Otherwise returns an empty string.
Parameters
element : Element
Returns
String
-
_stringifyElementRanges( element, offset )
module:engine/dev-utils/view~ViewStringify#_stringifyElementRanges
private
Checks if a given element has a range start or a range end placed at a given offset and returns its string representation.
Parameters
element : Element
offset : Number
-
_stringifyElementType( element ) → String
module:engine/dev-utils/view~ViewStringify#_stringifyElementType
private
Converts the passed element's type to its string representation
Returns:
- 'attribute' for attribute elements,
- 'container' for container elements,
- 'empty' for empty elements,
- 'ui' for UI elements,
- 'raw' for raw elements,
- an empty string when the current configuration is preventing showing elements' types.
Parameters
element : Element
Returns
String
-
_stringifyTextRanges( node )
module:engine/dev-utils/view~ViewStringify#_stringifyTextRanges
private
Checks if a given Text node has a range start or a range end placed somewhere inside. Returns a string representation of text with range delimiters placed inside.
Parameters
node : Text
-
_walkView( root, callback )
module:engine/dev-utils/view~ViewStringify#_walkView
private
Executes a simple walker that iterates over all elements in the view tree starting from the root element. Calls the
callback
with parsed chunks of string data.Parameters
root : DocumentFragment | Element | Text
callback : function
Every day, we work hard to keep our documentation complete. Have you spotted an outdated information? Is something missing? Please report it via our issue tracker.