HTML Parser
This is a simple HTML to Virtual Tree parser that can be used both in the CLI and the browser.
Usage
CLI Usage
To parse an HTML file using the command line interface (CLI), run the following command:
node main.js <html-file-path>
Node Js Installation
node main.js <html-file-path>
Browser Usage
To use the parser in the browser, follow these steps:
Include the html-to-vtree.js script in your HTML file:
<script src="html-to-vtree.js"></script>
Create a textarea element where users can input HTML:
<script src="html-to-vtree.js"></script>
const htmlString = '<div class="container">Hello, <b>world</b></div>';
const parser = new HtmlParser(htmlString);
const rootNode = parser.parseHtml();
{
tag: 'div',
text: 'Hello, ',
class: 'container',
children: [
{tag: 'b', text: 'world'}
]
}