77 * @module engine/dev-utils/view
88 */
99
10+ /* globals document */
11+
1012/**
1113 * Collection of methods for manipulating the {@link module:engine/view/view view} for testing purposes.
1214 */
@@ -49,6 +51,8 @@ const allowedTypes = {
4951 * (`<span view-priority="12">`, `<b view-priority="10">`).
5052 * @param {Boolean } [options.showAttributeElementId=false] When set to `true`, attribute element's id will be printed
5153 * (`<span id="marker:foo">`).
54+ * @param {Boolean } [options.renderUIElements=false] When set to `true`, the inner content of each
55+ * {@link module:engine/view/uielement~UIElement} will be printed.
5256 * @returns {String } The stringified data.
5357 */
5458export function getData ( view , options = { } ) {
@@ -63,6 +67,7 @@ export function getData( view, options = {} ) {
6367 const stringifyOptions = {
6468 showType : options . showType ,
6569 showPriority : options . showPriority ,
70+ renderUIElements : options . renderUIElements ,
6671 ignoreRoot : true
6772 } ;
6873
@@ -222,6 +227,8 @@ setData._parse = parse;
222227 * Mainly used by the `getData` function to ignore the {@link module:engine/view/document~Document document's} root element.
223228 * @param {Boolean } [options.sameSelectionCharacters=false] When set to `true`, the selection inside the text will be marked as
224229 * `{` and `}` and the selection outside the text as `[` and `]`. When set to `false`, both will be marked as `[` and `]` only.
230+ * @param {Boolean } [options.renderUIElements=false] When set to `true`, the inner content of each
231+ * {@link module:engine/view/uielement~UIElement} will be printed.
225232 * @returns {String } An HTML-like string representing the view.
226233 */
227234export function stringify ( node , selectionOrPositionOrRange = null , options = { } ) {
@@ -605,6 +612,8 @@ class ViewStringify {
605612 * be outputted.
606613 * @param {Boolean } [options.sameSelectionCharacters=false] When set to `true`, the selection inside the text is marked as
607614 * `{` and `}` and the selection outside the text as `[` and `]`. When set to `false`, both are marked as `[` and `]`.
615+ * @param {Boolean } [options.renderUIElements=false] When set to `true`, the inner content of each
616+ * {@link module:engine/view/uielement~UIElement} will be printed.
608617 */
609618 constructor ( root , selection , options ) {
610619 this . root = root ;
@@ -620,6 +629,7 @@ class ViewStringify {
620629 this . showAttributeElementId = ! ! options . showAttributeElementId ;
621630 this . ignoreRoot = ! ! options . ignoreRoot ;
622631 this . sameSelectionCharacters = ! ! options . sameSelectionCharacters ;
632+ this . renderUIElements = ! ! options . renderUIElements ;
623633 }
624634
625635 /**
@@ -652,13 +662,17 @@ class ViewStringify {
652662 callback ( this . _stringifyElementOpen ( root ) ) ;
653663 }
654664
655- let offset = 0 ;
656- callback ( this . _stringifyElementRanges ( root , offset ) ) ;
657-
658- for ( const child of root . getChildren ( ) ) {
659- this . _walkView ( child , callback ) ;
660- offset ++ ;
665+ if ( this . renderUIElements && root . is ( 'uiElement' ) ) {
666+ callback ( root . render ( document ) . innerHTML ) ;
667+ } else {
668+ let offset = 0 ;
661669 callback ( this . _stringifyElementRanges ( root , offset ) ) ;
670+
671+ for ( const child of root . getChildren ( ) ) {
672+ this . _walkView ( child , callback ) ;
673+ offset ++ ;
674+ callback ( this . _stringifyElementRanges ( root , offset ) ) ;
675+ }
662676 }
663677
664678 if ( root . is ( 'element' ) && ! ignore ) {
0 commit comments