Skip to content

romagny13/html-parser

Repository files navigation

TypeScript/JavaScript HTML Parser

Build Status

HTML tree to Object tree.

Installation

npm i romagny13-html-parser -S 

Usage

TypeScript / es6

import { parse } from "romagny13-html-parser"; let html = `<!-- a comment -->  <section>  <h1>A title</h1>  <p>A <strong>content</strong> with a <a href="#">Link</a></p>  </section>  <p>Other content</p>`; let nodes = parse(html); console.log(nodes);

es5

<script src="/node_modules/romagny13-html-parser/html-parser.js"></script> <script> var html = '<!-- a comment --><section><h1>A title</h1><p>A <strong>content</strong> with a <a href="#">Link</a></p></section><p>Other content</p>'; var nodes = HTMLParser.parse(html); console.log(nodes); // link infos var infos = nodes[1].children[1].children[1].infos; console.log(html.substring(infos.index, infos.end)); // show "<a href="#">Link</a>" </script>

About

TypeScript/JavaScript HTML Parser

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published