tinymce.html.DomParser

This class parses HTML code into a DOM like structure of nodes it will remove redundant whitespace and make sure that the node tree is valid according to the specified schema. So for example: <p>a<p>b</p>c</p> will become <p>a</p><p>b</p><p>c</p>

Examples

var parser = new tinymce.html.DomParser({validate: true}, schema);
var rootNode = parser.parse('<h1>content</h1>');

Constructors

name summary defined by
DomParser() Constructs a new DomParser instance. tinymce.html.DomParser

Methods

name summary defined by
addAttributeFilter() Adds a attribute filter function to the parser, the parser will collect nodes that has the specified attributes and then execute the callback ones it has finished parsing the document. tinymce.html.DomParser
addNodeFilter() Adds a node filter function to the parser, the parser will collect the specified nodes by name and then execute the callback ones it has finished parsing the document. tinymce.html.DomParser
filterNode() Runs the specified node though the element and attributes filters. tinymce.html.DomParser
parse() Parses the specified HTML string into a DOM like node tree and returns the result. tinymce.html.DomParser

Constructors

DomParser

public constructor function DomParser(settings:Object, schema:tinymce.html.Schema)

Constructs a new DomParser instance.

Parameters

Methods

addAttributeFilter

addAttributeFilter(callback:function)

Adds a attribute filter function to the parser, the parser will collect nodes that has the specified attributes and then execute the callback ones it has finished parsing the document.

Examples
parser.addAttributeFilter('src,href', function(nodes, name) {
 for (var i = 0; i < nodes.length; i++) {
  console.log(nodes[i].name);
 }
});
Parameters

addNodeFilter

addNodeFilter(callback:function)

Adds a node filter function to the parser, the parser will collect the specified nodes by name and then execute the callback ones it has finished parsing the document.

Examples
parser.addNodeFilter('p,h1', function(nodes, name) {
 for (var i = 0; i < nodes.length; i++) {
  console.log(nodes[i].name);
 }
});
Parameters

filterNode

filterNode(Node:tinymce.html.Node):tinymce.html.Node

Runs the specified node though the element and attributes filters.

Parameters
Return value

parse

parse(html:String, args:Object):tinymce.html.Node

Parses the specified HTML string into a DOM like node tree and returns the result.

Examples
var rootNode = new DomParser({...}).parse('<b>text</b>');
Parameters
Return value

Can't find what you're looking for? Let us know.

Except as otherwise noted, the content of this page is licensed under the Creative Commons BY-NC-SA 3.0 License, and code samples are licensed under the Apache 2.0 License.