romagny13-html-parser
TypeScript icon, indicating that this package has built-in type declarations

0.1.3 • Public • Published

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>

Readme

Keywords

none

Package Sidebar

Install

npm i romagny13-html-parser

Weekly Downloads

3

Version

0.1.3

License

ISC

Last publish

Collaborators

  • romagny13