0.2.5 • Published 6 years ago

html-utils v0.2.5

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

html-utils

Tools for parsing, traversing, building, etc, html strings

Usage

HTML.parse(string html, object options);

Read and parse an HTML/XML document and return a light AST.

var HTML = require('html-utils');
var doc = '<html><head><title>Hello</title><body><h1 class="heading">World</h1></body>';

console.log(HTML.parse(doc));
->
[
  {
    tagName: 'html',
    children: [
      {
        tagName: 'head',
        children: [
          {
            tagName: 'title',
            children: [
              'Hello'
            ]
          },
          {
            tagName: 'body',
            children: [
              {
                tagName: 'h1',
                attributes: {
                  class: "heading"
                },
                children: [
                  'World'
                ]
              }
            ]
          }
        ]
      }
    ]
  }
]

Options

xml (bool) make sure to require all closing tags. Defaults to false

HTML.stringify(object ast, object options, number space = 2)

Pretty print indented (with space spaces) HTML.

With the previous example ast:

console.log(HTML.stringify(ast));
->
<html>
  <head>
    <title>
      Hello
    </title>
    <body>
      <h1 class="heading">
        World
      </h1>
    </body>
  </head>
</html>

Options

xml (bool) print void tags with a close slash (ie <img />). Defaults to false xhtml alias of xml

0.2.5

6 years ago

0.2.4

6 years ago

0.2.3

6 years ago

0.2.2

6 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago