@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.
Last updated 5 years ago by starptech .
MIT · Original npm · Tarball · package.json
$ gnpm install @starptech/rehype-webparser 
SYNC missed versions from official npm registry.

@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.

Current Tags

  • 0.10.0                                ...           latest (5 years ago)

32 Versions

  • 0.10.0                                ...           5 years ago
  • 0.9.0                                ...           6 years ago
  • 0.8.17                                ...           6 years ago
  • 0.8.10                                ...           6 years ago
  • 0.8.7                                ...           6 years ago
  • 0.8.6                                ...           6 years ago
  • 0.8.5                                ...           6 years ago
  • 0.8.3                                ...           6 years ago
  • 0.8.1                                ...           6 years ago
  • 0.8.0                                ...           6 years ago
  • 0.7.0                                ...           6 years ago
  • 0.6.0                                ...           6 years ago
  • 0.5.3                                ...           6 years ago
  • 0.5.2                                ...           6 years ago
  • 0.5.0                                ...           6 years ago
  • 0.4.2                                ...           6 years ago
  • 0.4.1                                ...           6 years ago
  • 0.4.0                                ...           6 years ago
  • 0.3.4                                ...           6 years ago
  • 0.3.3                                ...           6 years ago
  • 0.3.2                                ...           6 years ago
  • 0.3.1                                ...           6 years ago
  • 0.3.0                                ...           6 years ago
  • 0.2.4                                ...           6 years ago
  • 0.2.3                                ...           6 years ago
  • 0.2.2                                ...           6 years ago
  • 0.2.0                                ...           6 years ago
  • 0.1.9                                ...           6 years ago
  • 0.1.8                                ...           6 years ago
  • 0.1.7                                ...           6 years ago
  • 0.1.5                                ...           6 years ago
  • 0.1.4                                ...           6 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dev Dependencies (7)

Copyright 2013 - present © cnpmjs.org | Home |