pinkagable / yzhanHTMLParser

A streaming HTML parser based on HTML Standard. 基于 HTML 标准的流式 HTML 解析器

Home Page:https://mantoufan.github.io/yzhanHTMLParser/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

yzhanHTMLParser

npm npm GitHub license coverage
A streaming HTML parser based on HTML Standard
一款基于 HTML 标准的流式 HTML 解析器

Demo

You could change HTML Code and view the result in realtime.
Online Demo
DEMO PNG

Setup

Node.js

npm i yzhanhtmlparser
import yzhanHTMLParser from 'yzhanhtmlparser'

Browser

<script src="https://cdn.jsdelivr.net/npm/yzhanhtmlparser@latest/docs/yzhanhtmlparser.min.js"></script>

Usage

Declaration Code

const code = `<html lang="en">
<head>
<title>Page Name</title>
<meta charset="UTF-8">
</head>
<body>
<h1 class="text" id=a>Hello World</h1>
<input type="button" disabled/>
</body>`

Parser · Prase

const parseResult = yzhanHTMLParser.parse(code)

Streaming Usage

const fs = require('node:fs')
const htmlParser = new yzhanHTMLParser.HtmlParser()
/* data.txt: abcde */
fs.createReadStream('./data.txt').pipe(htmlParser)
htmlParser.on('data', char => {
  console.log(char) // a . b . c . d . e
})

Development

Unit Testing

npm test

Unit Testing Coverage

npm run test:coverage

Build

npm run build

Preview

npm run dev

About

A streaming HTML parser based on HTML Standard. 基于 HTML 标准的流式 HTML 解析器

https://mantoufan.github.io/yzhanHTMLParser/

License:MIT License


Languages

Language:HTML 55.2%Language:JavaScript 38.2%Language:CSS 6.6%