-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes GH-10. Reviewed-by: Christian Murphy <christian.murphy.42@gmail.com> Reviewed-by: Titus Wormer <tituswormer@gmail.com>
- Loading branch information
1 parent
cdf4822
commit aa17c1a
Showing
7 changed files
with
103 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
coverage/ | ||
hast-util-from-parse5.js | ||
hast-util-from-parse5.min.js | ||
*.html | ||
*.json | ||
*.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// TypeScript Version: 3.5 | ||
import {Node} from 'unist' | ||
import {Document} from 'parse5' | ||
import {VFile} from 'vfile' | ||
|
||
declare namespace hastUtilFromParse5 { | ||
interface HastUtilFromParse5Options { | ||
/** | ||
* Whether the [*root*](https://github.com/syntax-tree/unist#root) of the | ||
* [*tree*](https://github.com/syntax-tree/unist#tree) is in the `'html'` or `'svg'` | ||
* space. | ||
* | ||
* 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. | ||
* | ||
* @default 'html' | ||
*/ | ||
space?: 'html' | 'svg' | ||
|
||
/** | ||
* [`VFile`](https://github.com/vfile/vfile), used to add | ||
* [positional information](https://github.com/syntax-tree/unist#positional-information) | ||
* to [*nodes*](https://github.com/syntax-tree/hast#nodes). | ||
* If given, the [*file*](https://github.com/syntax-tree/unist#file) should have the | ||
* original HTML source as its contents. | ||
*/ | ||
file?: VFile | ||
/** | ||
* | ||
* Whether to add extra positional information about starting tags, closing tags, | ||
* and attributes to elements. | ||
* | ||
* Note: not used without `file`. | ||
* | ||
* @default: false | ||
*/ | ||
verbose?: boolean | ||
} | ||
} | ||
|
||
/** | ||
* Transform [Parse5’s AST](https://github.com/inikulin/parse5/blob/master/packages/parse5/docs/tree-adapter/default/interface-list.md) | ||
* to a [**hast**](https://github.com/syntax-tree/hast) | ||
* [*tree*](https://github.com/syntax-tree/unist#tree). | ||
* | ||
* @param options If `options` is a [`VFile`](https://github.com/vfile/vfile), it’s treated | ||
* as `{file: options}`. | ||
*/ | ||
declare function hastUtilFromParse5( | ||
ast: Document, | ||
options?: hastUtilFromParse5.HastUtilFromParse5Options | VFile | ||
): Node | ||
|
||
export = hastUtilFromParse5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import vfile = require('vfile') | ||
import parse5 = require('parse5') | ||
import fromParse5 = require('hast-util-from-parse5') | ||
|
||
const file = vfile() | ||
const ast = parse5.parse('', {sourceCodeLocationInfo: true}) | ||
fromParse5(ast, file) | ||
fromParse5(ast, {file}) | ||
fromParse5(ast, {space: 'html'}) | ||
fromParse5(ast, {space: 'svg'}) | ||
fromParse5(ast, {verbose: true}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"compilerOptions": { | ||
"lib": ["es2015"], | ||
"strict": true, | ||
"baseUrl": ".", | ||
"paths": { | ||
"hast-util-from-parse5": ["index.d.ts"] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"extends": "dtslint/dtslint.json", | ||
"rules": { | ||
"no-redundant-jsdoc": false, | ||
"semicolon": false, | ||
"whitespace": false | ||
} | ||
} |