Skip to content

redexp/simple-html-dom-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

simple-html-dom-parser

Build Status

Install

npm install simple-html-dom-parser

API

/**
 * @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)