0.10.0 • Published 5 years ago

@starptech/rehype-webparser v0.10.0

Weekly downloads
3,556
License
MIT
Repository
-
Last release
5 years ago

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

0.10.0

5 years ago

0.9.0

5 years ago

0.8.17

5 years ago

0.8.10

5 years ago

0.8.7

5 years ago

0.8.6

5 years ago

0.8.5

5 years ago

0.8.3

5 years ago

0.8.1

5 years ago

0.8.0

5 years ago

0.7.0

5 years ago

0.6.0

5 years ago

0.5.3

5 years ago

0.5.2

5 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