npm install simple-html-dom-parser
/**
* @param {String} html
* @param {Object} options
* @returns {DomObject}
*/
parse(html, options)
options
- Optional object of options:
{
regex: {
name: /[a-zA-Z_][\w:\-\.]*/, //Regex for element name
attribute: /[a-zA-Z_][\w:\-\.]*/ //Regex for attribute name
}
}
{DomObject}
- object with next structure
{
type: 'document',
children: []
}
children:
is array of objects of next types
{
type: 'doctype' || 'comment' || 'text',
parent: {DomObject},
prev: {DomObject} || null,
next: {DomObject} || null,
data: {String}
}
{
type: 'tag',
name: {String},
attr: {
id: 'example'
},
unary: false, // shows is tag self-closing or not
parent: {DomObject},
prev: {DomObject} || null,
next: {DomObject} || null,
children: []
}
/**
* @param {DomObject} dom
* @returns {String}
*/
getOuterHTML(dom)
/**
* @param {DomObject} dom
* @returns {String}
*/
getInnerHTML(dom)