Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@starptech/rehype-webparser

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@starptech/rehype-webparser

Parses HTML via [**Webparser**](https://github.com/Prettyhtml/prettyhtml/tree/master/packages/webparser) to a [**HAST**](https://github.com/syntax-tree/hast) syntax tree.

  • 0.10.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
2.3K
decreased by-3.81%
Maintainers
1
Weekly downloads
 
Created
Source

@starptech/rehype-webparser

Parses HTML via Webparser to a HAST syntax tree.

Installation

npm install --save @starptech/rehype-webparser

Usage

This example shows how we parse HTML with Webparser transform it into HAST compatible structure and finally compile that data back to HTML with hast-util-to-html.

Say we have the following file, example.html:

<!DOCTYPE html>
<title>Hello!</title>
<h1 id="world">World!</h1>

And our script, example.js, looks as follows:

const vfile = require('to-vfile')
const report = require('vfile-reporter')
const unified = require('unified')
const parse = require('@starptech/rehype-webparser')
const toHTML = require('hast-util-to-html')

// A compiler is needed to inform unified how to transform it back to HTML
function stringify() {
  this.Compiler = compiler

  function compiler(tree) {
    return toHTML(tree)
  }
}

unified()
  .use(parse)
  //.use(yourPlugin)
  .use(stringify)
  .process(vfile.readSync('example.html'), function(err, file) {
    console.error(report(err || file))
    console.log(String(file))
  })

Now, running node example yields:

<!doctype html>
<title>Hello!</title>
<h1 id="world">World!</h1>

API

processor.use(webparser[, options])

Configure the processor to read HTML as input and process a HAST syntax tree.

options.*

Webparser options.

Keywords

FAQs

Package last updated on 21 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