hast-util-from-parse5
Advanced tools
Comparing version 5.0.0 to 5.0.1
25
index.js
@@ -16,3 +16,3 @@ 'use strict' | ||
/* Handlers. */ | ||
// Handlers. | ||
var map = { | ||
@@ -26,3 +26,3 @@ '#document': root, | ||
/* Wrapper to normalise options. */ | ||
// Wrapper to normalise options. | ||
function wrapper(ast, options) { | ||
@@ -47,3 +47,3 @@ var settings = options || {} | ||
/* Transform a node. */ | ||
// Transform a node. | ||
function transform(ast, config) { | ||
@@ -80,3 +80,3 @@ var schema = config.schema | ||
/* Transform children. */ | ||
// Transform children. | ||
function nodes(children, config) { | ||
@@ -94,4 +94,4 @@ var length = children.length | ||
/* Transform a document. | ||
* Stores `ast.quirksMode` in `node.data.quirksMode`. */ | ||
// Transform a document. | ||
// Stores `ast.quirksMode` in `node.data.quirksMode`. | ||
function root(ast, children, config) { | ||
@@ -119,3 +119,3 @@ var node = {type: 'root', children: children, data: {}} | ||
/* Transform a doctype. */ | ||
// Transform a doctype. | ||
function doctype(ast) { | ||
@@ -130,3 +130,3 @@ return { | ||
/* Transform a text. */ | ||
// Transform a text. | ||
function text(ast) { | ||
@@ -136,3 +136,3 @@ return {type: 'text', value: ast.value} | ||
/* Transform a comment. */ | ||
// Transform a comment. | ||
function comment(ast) { | ||
@@ -142,3 +142,3 @@ return {type: 'comment', value: ast.data} | ||
/* Transform an element. */ | ||
// Transform an element. | ||
function element(ast, children, config) { | ||
@@ -181,3 +181,3 @@ var fn = config.schema.space === 'svg' ? s : h | ||
/* Create clean positional information. */ | ||
// Create clean positional information. | ||
function location(node, location, config) { | ||
@@ -196,3 +196,4 @@ var schema = config.schema | ||
/* Unclosed with children (upstream: https://github.com/inikulin/parse5/issues/109) */ | ||
// Bug for unclosed with children. | ||
// See: <https://github.com/inikulin/parse5/issues/109>. | ||
if ( | ||
@@ -199,0 +200,0 @@ !location.endTag && |
{ | ||
"name": "hast-util-from-parse5", | ||
"version": "5.0.0", | ||
"description": "Transform Parse5βs AST to HAST", | ||
"version": "5.0.1", | ||
"description": "Transform Parse5βs AST to hast", | ||
"license": "MIT", | ||
@@ -32,15 +32,15 @@ "keywords": [ | ||
"not": "^0.1.0", | ||
"nyc": "^13.0.0", | ||
"nyc": "^14.0.0", | ||
"parse5": "^5.0.0", | ||
"prettier": "^1.13.5", | ||
"prettier": "^1.0.0", | ||
"remark-cli": "^6.0.0", | ||
"remark-preset-wooorm": "^4.0.0", | ||
"remark-preset-wooorm": "^5.0.0", | ||
"tape": "^4.0.0", | ||
"tinyify": "^2.4.3", | ||
"tinyify": "^2.0.0", | ||
"to-vfile": "^5.0.0", | ||
"unist-util-visit": "^1.1.3", | ||
"xo": "^0.23.0" | ||
"unist-util-visit": "^1.0.0", | ||
"xo": "^0.24.0" | ||
}, | ||
"scripts": { | ||
"format": "remark . -qfo && prettier --write '**/*.js' && xo --fix", | ||
"format": "remark . -qfo && prettier --write \"**/*.js\" && xo --fix", | ||
"build-bundle": "browserify index.js -s hastUtilFromParse5 > hast-util-from-parse5.js", | ||
@@ -47,0 +47,0 @@ "build-mangle": "browserify index.js -p tinyify -s hastUtilFromParse5 > hast-util-from-parse5.min.js", |
@@ -1,10 +0,19 @@ | ||
# hast-util-from-parse5 [![Build][build-badge]][build] [![Coverage][coverage-badge]][coverage] [![Downloads][downloads-badge]][downloads] [![Chat][chat-badge]][chat] | ||
# hast-util-from-parse5 | ||
Transform [HAST][] to [Parse5βs AST][ast]. | ||
[![Build][build-badge]][build] | ||
[![Coverage][coverage-badge]][coverage] | ||
[![Downloads][downloads-badge]][downloads] | ||
[![Size][size-badge]][size] | ||
[![Sponsors][sponsors-badge]][collective] | ||
[![Backers][backers-badge]][collective] | ||
[![Chat][chat-badge]][chat] | ||
## Installation | ||
[**hast**][hast] utility to transform [Parse5βs AST][ast] to a hast | ||
[*tree*][tree]. | ||
## Install | ||
[npm][]: | ||
```bash | ||
```sh | ||
npm install hast-util-from-parse5 | ||
@@ -23,3 +32,3 @@ ``` | ||
```javascript | ||
```js | ||
var vfile = require('to-vfile') | ||
@@ -57,27 +66,29 @@ var parse5 = require('parse5') | ||
Transform an `ASTNode` to a [HAST Node][node]. | ||
Transform [Parse5βs AST][ast] to a [**hast**][hast] [*tree*][tree]. | ||
##### `options` | ||
If `options` is a [VFile][], itβs treated as `{file: options}`. | ||
If `options` is a [`VFile`][vfile], itβs treated as `{file: options}`. | ||
###### `options.space` | ||
Whether the root of the given tree is in the `'html'` or `'svg'` space (enum, | ||
`'svg'` or `'html'`, default: `'html'`). | ||
Whether the [*root*][root] of the [*tree*][tree] is in the `'html'` or `'svg'` | ||
space (enum, `'svg'` or `'html'`, default: `'html'`). | ||
If an element in with the SVG namespace is found in `ast`, `fromParse5` | ||
automatically switches to the SVG space when entering the element, and | ||
switches back when leaving. | ||
automatically switches to the SVG space when entering the element, and switches | ||
back when leaving. | ||
###### `options.file` | ||
[Virtual file][vfile], used to add positional information to HAST nodes. | ||
If given, the file should have the original HTML source as its contents. | ||
[`VFile`][vfile], used to add [positional information][positional-information] | ||
to [*nodes*][node]. | ||
If given, the [*file*][file] should have the original HTML source as its | ||
contents. | ||
###### `options.verbose` | ||
Whether to add positional information about starting tags, closing tags, | ||
and attributes to elements (`boolean`, default: `false`). Note: not used | ||
without `file`. | ||
Whether to add extra positional information about starting tags, closing tags, | ||
and attributes to elements (`boolean`, default: `false`). | ||
Note: not used without `file`. | ||
@@ -96,7 +107,3 @@ For the following HTML: | ||
tagName: 'img', | ||
properties: { | ||
src: 'http://example.com/fav.ico', | ||
alt: 'foo', | ||
title: 'bar' | ||
}, | ||
properties: {src: 'http://example.com/fav.ico', alt: 'foo', title: 'bar'}, | ||
children: [], | ||
@@ -135,7 +142,9 @@ data: { | ||
See [`contributing.md` in `syntax-tree/hast`][contributing] for ways to get | ||
See [`contributing.md` in `syntax-tree/.github`][contributing] for ways to get | ||
started. | ||
See [`support.md`][support] for ways to get help. | ||
This organisation has a [Code of Conduct][coc]. By interacting with this | ||
repository, organisation, or community you agree to abide by its terms. | ||
This project has a [Code of Conduct][coc]. | ||
By interacting with this repository, organisation, or community you agree to | ||
abide by its terms. | ||
@@ -160,5 +169,15 @@ ## License | ||
[size-badge]: https://img.shields.io/bundlephobia/minzip/hast-util-from-parse5.svg | ||
[size]: https://bundlephobia.com/result?p=hast-util-from-parse5 | ||
[sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg | ||
[backers-badge]: https://opencollective.com/unified/backers/badge.svg | ||
[collective]: https://opencollective.com/unified | ||
[chat-badge]: https://img.shields.io/badge/join%20the%20community-on%20spectrum-7b16ff.svg | ||
[chat]: https://spectrum.chat/unified/rehype | ||
[chat]: https://spectrum.chat/unified/syntax-tree | ||
@@ -171,12 +190,22 @@ [npm]: https://docs.npmjs.com/cli/install | ||
[hast]: https://github.com/syntax-tree/hast | ||
[contributing]: https://github.com/syntax-tree/.github/blob/master/contributing.md | ||
[ast]: https://github.com/inikulin/parse5/wiki/Documentation | ||
[support]: https://github.com/syntax-tree/.github/blob/master/support.md | ||
[node]: https://github.com/syntax-tree/hast#ast | ||
[coc]: https://github.com/syntax-tree/.github/blob/master/code-of-conduct.md | ||
[ast]: https://github.com/inikulin/parse5/blob/master/packages/parse5/docs/tree-adapter/default/interface-list.md | ||
[vfile]: https://github.com/vfile/vfile | ||
[contributing]: https://github.com/syntax-tree/hast/blob/master/contributing.md | ||
[tree]: https://github.com/syntax-tree/unist#tree | ||
[coc]: https://github.com/syntax-tree/hast/blob/master/code-of-conduct.md | ||
[root]: https://github.com/syntax-tree/unist#root | ||
[positional-information]: https://github.com/syntax-tree/unist#positional-information | ||
[file]: https://github.com/syntax-tree/unist#file | ||
[hast]: https://github.com/syntax-tree/hast | ||
[node]: https://github.com/syntax-tree/hast#nodes |
13788
193
206