|
|
@@ -67,4 +67,32 @@
|
|
|
return count;
|
|
|
}
|
|
|
};
|
|
|
+
|
|
|
+ bender.tools.treemodel = {
|
|
|
+ /**
|
|
|
+ * Returns tree structure as a simplified string. Elements are uppercase and characters are lowercase.
|
|
|
+ * Start and end of an element is marked the same way, by the element's name (in uppercase).
|
|
|
+ *
|
|
|
+ * let element = new Element( 'div', [], [ 'abc', new Element( 'p', [], 'foo' ), 'xyz' ] );
|
|
|
+ * bender.tools.treemodel.getNodesAndText( element ); // abcPfooPxyz
|
|
|
+ *
|
|
|
+ * @param {treeModel.Range} range Range to stringify.
|
|
|
+ * @returns {String} String representing element inner structure.
|
|
|
+ */
|
|
|
+ getNodesAndText: ( range ) => {
|
|
|
+ let txt = '';
|
|
|
+
|
|
|
+ for ( let step of range ) {
|
|
|
+ let node = step.node;
|
|
|
+
|
|
|
+ if ( node.character ) {
|
|
|
+ txt += node.character.toLowerCase();
|
|
|
+ } else if ( node.name ) {
|
|
|
+ txt += node.name.toUpperCase();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return txt;
|
|
|
+ }
|
|
|
+ };
|
|
|
} )();
|