Class

ViewStringify (engine/dev-utils)

@ckeditor/ckeditor5-engine/src/dev-utils/view

class private

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] } )

    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 to false, both are marked as [ and ].

    Defaults to false

    [ options.renderUIElements ] : Boolean

    When set to true, the inner content of each UIElement will be printed.

    Defaults to false

    [ options.renderRawElements ] : Boolean

    When set to true, the inner content of each

    Defaults 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

    Converts the view to a string.

    Returns

    String

    String representation of the view elements.

  • _stringifyElementAttributes( element ) → String

    private

    Converts the passed element attributes to their string representation. If an element has no attributes, an empty string is returned.

    Parameters

    element : Element

    Returns

    String
  • _stringifyElementClose( element ) → String

    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>).

    Parameters

    element : Element

    Returns

    String
  • _stringifyElementId( element ) → String

    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

    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

    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 )

    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

    private

    Converts the passed element's type to its string representation

    Returns:

    Parameters

    element : Element

    Returns

    String
  • _stringifyTextRanges( node )

    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 )

    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