0.1.3 • Published 7 years ago

romagny13-html-parser v0.1.3

Weekly downloads
1
License
ISC
Repository
-
Last release
7 years ago

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>
0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago