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

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

Summary

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 once it has finished parsing the document.

DomParser

addNodeFilter()

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

DomParser

parse()

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

DomParser

Methods

addAttributeFilter()

addAttributeFilter(name: String, 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 once it has finished parsing the document.

Examples

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

Parameters

  • name (String) - Comma separated list of nodes to collect.

  • callback (Function) - Callback function to execute once it has collected nodes.


addNodeFilter()

addNodeFilter(name: String, callback: Function)

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

Examples

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

Parameters

  • name (String) - Comma separated list of nodes to collect.

  • callback (Function) - Callback function to execute once it has collected nodes.


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

const rootNode = tinymce.html.DomParser({...}).parse('<b>text</b>');

Parameters

  • html (String) - Html string to sax parse.

  • args (Object) - Optional args object that gets passed to all filter functions.

Return value

  • Node - Root node containing the tree.