1. simple-html-tokenizer
Simple HTML Tokenizer is a lightweight JavaScript library that can be used to tokenize the kind of HTML normally found in templates.
simple-html-tokenizer
Package: simple-html-tokenizer
Created by: tildeio
Last modified: Sun, 26 Jun 2022 19:40:17 GMT
Version: 0.5.11
License: MIT
Downloads: 2,071,062
Repository: https://github.com/tildeio/simple-html-tokenizer

Install

npm install simple-html-tokenizer
yarn add simple-html-tokenizer

Simple HTML Tokenizer Build Status

Simple HTML Tokenizer is a lightweight JavaScript library that can be
used to tokenize the kind of HTML normally found in templates. It can be
used to preprocess templates to change the behavior of some template
element depending upon whether the template element was found in an
attribute or text.

It is not a full HTML5 tokenizer. It focuses on the kind of HTML that is
used in templates: content designed to be inserted into the <body>
and without <script> tags.

In particular, Simple HTML Tokenizer does not handle many states from
the HTML5 Tokenizer Specification:

  • Any states involving CDATA or RCDATA
  • Any states involving <script>
  • Any states involving <DOCTYPE>
  • The bogus comment state

It also passes through character references, instead of trying to
tokenize and process them, because the preprocessed templates will
ultimately be parsed by a real browser context.

At the moment, there are some error states specified by the tokenizer
spec that are not handled by Simple HTML Tokenizer. Ultimately, I plan
to support all error states, as well as provide information about
tokenizer errors in debug mode.

Usage

You can tokenize HTML:

 var tokens = HTML5Tokenizer.tokenize("<div id='foo' href=bar class=\"bat\">");

var token = tokens[0];
token.tagName     //=> "div"
token.attributes  //=> [["id", "foo"], ["href", "bar"], ["class", "bat"]]
token.selfClosing //=> false

Building and running the tests

 npm install
npm test

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code