Socket
Socket
Sign inDemoInstall

lite-html-parser

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lite-html-parser

Parses HTML text and calls callbacks on found elements.


Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

HTML Parser

Parses HTML text and calls callbacks on found elements.

The given HTML doesn't have to be valid. It tries any string to be parsed.

Zero dependencies. Create an issue if you found any HTML code parsed in a wrong way.

See tests for examples.

Installation

npm i lite-html-parser

Usage

const { parse } = require('lite-html-parser')

parse('<p>Welcome <span>Mr</span> <strong>John</strong></p>', {
  opentag (name) { console.log({ opentag: name }) },
  closetag (name) { console.log({ closetag: name }) },
  attribute (name, value) { console.log({ attribute: [name, value] }) },
  text (text) { console.log({ text }) },
  comment (comment) { console.log({ comment }) },
  instruction (instruction) { console.log({ instruction }) }
})

API

Handlers

Handler functions are called in the parsing process.

All functions needs to be provided.

  • opentag (name)
  • closetag (name)
  • attribute (name, value)
  • text (text)
  • comment (comment)
  • instruction (instruction)

Options

A third argument can be an object with options.

  • noAttributeValue - value to used when an attribute doesn't have a value (e.g. <input enabled />); by default '' (empty string)

Keywords

FAQs

Package last updated on 26 Jun 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc