1.0.0 • Published 2 years ago

@rustle/html-parse v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

NPM version

Simple html parser compatible with single tags without /.

Usage

import { parse, evaluate } from '@rustle/html-parse';

const built = parse(`
  <div>
    <br>
    <a href="xxx"/>
  </div>
`)

const ast = evaluate(built, (tag, props, ...children) => {
  return { tag, props, children };
})

console.log(ast); // [{ tag: 'div', props: null, children: [...] }]
// Get all `a` tags.
const a = [];

evaluate(built, (tag, props, ...children) => {
  if (tag === 'a') {
    a.push({ tag, props, children });
  }
})

CDN

<!DOCTYPE html>
<html lang='en'>
<body>
  <script src='https://unpkg.com/@rustle/html-parse/dist/htmlParse.umd.js'></script>
  <script>
    const { parse, evaluate } = FetchNpmPackage;
    // ...
  </script>
</body>
</html>

Caveats

  1. The special tag is marked with uppercase, because the html tags are all in lowercase, to avoid conflicts, the special tag is marked with uppercase.

    • comment node: COMMENT.
  2. For the wrong html syntax, it is impossible to achieve the same behavior as the browser. To be precise, this is more similar to an xml parser, so write standard html syntax as much as possible.

1.0.0

2 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago