rehype-parse
Advanced tools
Comparing version 7.0.1 to 8.0.0
91
index.js
@@ -1,90 +0,3 @@ | ||
'use strict' | ||
import rehypeParse from './lib/index.js' | ||
var fromParse5 = require('hast-util-from-parse5') | ||
var Parser5 = require('parse5/lib/parser') | ||
var errors = require('./errors.json') | ||
var base = 'https://html.spec.whatwg.org/multipage/parsing.html#parse-error-' | ||
var fatalities = {2: true, 1: false, 0: null} | ||
module.exports = parse | ||
function parse(options) { | ||
var settings = Object.assign({}, options, this.data('settings')) | ||
var position = settings.position | ||
position = typeof position === 'boolean' ? position : true | ||
this.Parser = parser | ||
function parser(doc, file) { | ||
var fn = settings.fragment ? 'parseFragment' : 'parse' | ||
var onParseError = settings.emitParseErrors ? onerror : null | ||
var parse5 = new Parser5({ | ||
sourceCodeLocationInfo: position, | ||
onParseError: onParseError, | ||
scriptingEnabled: false | ||
}) | ||
return fromParse5(parse5[fn](doc), { | ||
space: settings.space, | ||
file: file, | ||
verbose: settings.verbose | ||
}) | ||
function onerror(err) { | ||
var code = err.code | ||
var name = camelcase(code) | ||
var setting = settings[name] | ||
var config = setting === undefined || setting === null ? true : setting | ||
var level = typeof config === 'number' ? config : config ? 1 : 0 | ||
var start = { | ||
line: err.startLine, | ||
column: err.startCol, | ||
offset: err.startOffset | ||
} | ||
var end = {line: err.endLine, column: err.endCol, offset: err.endOffset} | ||
var info | ||
var message | ||
if (level) { | ||
info = errors[name] || /* istanbul ignore next */ { | ||
reason: '', | ||
description: '' | ||
} | ||
message = file.message(format(info.reason), {start: start, end: end}) | ||
message.source = 'parse-error' | ||
message.ruleId = code | ||
message.fatal = fatalities[level] | ||
message.note = format(info.description) | ||
message.url = info.url === false ? null : base + code | ||
} | ||
function format(value) { | ||
return value.replace(/%c(?:-(\d+))?/g, char).replace(/%x/g, encodedChar) | ||
} | ||
function char($0, $1) { | ||
var offset = $1 ? -parseInt($1, 10) : 0 | ||
var char = doc.charAt(err.startOffset + offset) | ||
return char === '`' ? '` ` `' : char | ||
} | ||
function encodedChar() { | ||
var char = doc.charCodeAt(err.startOffset).toString(16).toUpperCase() | ||
return '0x' + char | ||
} | ||
} | ||
} | ||
} | ||
function camelcase(value) { | ||
return value.replace(/-[a-z]/g, replacer) | ||
} | ||
function replacer($0) { | ||
return $0.charAt(1).toUpperCase() | ||
} | ||
export default rehypeParse |
{ | ||
"name": "rehype-parse", | ||
"version": "7.0.1", | ||
"version": "8.0.0", | ||
"description": "rehype plugin to parse HTML", | ||
@@ -29,13 +29,27 @@ "license": "MIT", | ||
], | ||
"sideEffects": false, | ||
"type": "module", | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"files": [ | ||
"index.js", | ||
"types/index.d.ts", | ||
"errors.json" | ||
"lib/", | ||
"index.d.ts", | ||
"index.js" | ||
], | ||
"types": "types/index.d.ts", | ||
"dependencies": { | ||
"hast-util-from-parse5": "^6.0.0", | ||
"parse5": "^6.0.0" | ||
"@types/hast": "^2.0.0", | ||
"hast-util-from-parse5": "^7.0.0", | ||
"parse5": "^6.0.0", | ||
"unified": "^10.0.0" | ||
}, | ||
"xo": false | ||
"scripts": { | ||
"build": "rimraf \"lib/**/*.d.ts\" && tsc && type-coverage" | ||
}, | ||
"xo": false, | ||
"typeCoverage": { | ||
"atLeast": 100, | ||
"detail": true, | ||
"strict": true, | ||
"ignoreCatch": true | ||
} | ||
} |
129
readme.md
@@ -22,43 +22,45 @@ # rehype-parse | ||
Support this effort and give back by sponsoring on [OpenCollective][collective]! | ||
<!--lint ignore no-html--> | ||
<table> | ||
<tr valign="top"> | ||
<td width="33.33%" align="center" colspan="2"> | ||
<a href="https://www.gatsbyjs.org">Gatsby</a><br>π₯<br><br> | ||
<a href="https://www.gatsbyjs.org"><img src="https://avatars1.githubusercontent.com/u/12551863?s=900&v=4"></a> | ||
</td> | ||
<td width="33.33%" align="center" colspan="2"> | ||
<a href="https://vercel.com">Vercel</a><br>π₯<br><br> | ||
<!--OC has a sharper image--> | ||
<a href="https://vercel.com"><img src="https://images.opencollective.com/vercel/d8a5bee/logo/512.png"></a> | ||
</td> | ||
<td width="33.33%" align="center" colspan="2"> | ||
<a href="https://www.netlify.com">Netlify</a><br><br><br> | ||
<!--OC has a sharper image--> | ||
<a href="https://www.netlify.com"><img src="https://images.opencollective.com/netlify/4087de2/logo/512.png"></a> | ||
</td> | ||
</tr> | ||
<tr valign="top"> | ||
<td width="16.67%" align="center"> | ||
<a href="https://www.holloway.com">Holloway</a><br><br><br> | ||
<a href="https://www.holloway.com"><img src="https://avatars1.githubusercontent.com/u/35904294?s=300&v=4"></a> | ||
</td> | ||
<td width="16.67%" align="center"> | ||
<a href="https://themeisle.com">ThemeIsle</a><br>π₯<br><br> | ||
<a href="https://themeisle.com"><img src="https://twitter-avatar.now.sh/themeisle"></a> | ||
</td> | ||
<td width="16.67%" align="center"> | ||
<a href="https://boostio.co">BoostIO</a><br>π₯<br><br> | ||
<a href="https://boostio.co"><img src="https://avatars1.githubusercontent.com/u/13612118?s=300&v=4"></a> | ||
</td> | ||
<td width="16.67%" align="center"> | ||
<a href="https://expo.io">Expo</a><br>π₯<br><br> | ||
<a href="https://expo.io"><img src="https://avatars1.githubusercontent.com/u/12504344?s=300&v=4"></a> | ||
</td> | ||
<td width="50%" align="center" colspan="2"> | ||
<br><br><br><br> | ||
<a href="https://opencollective.com/unified"><strong>You?</strong></a> | ||
</td> | ||
</tr> | ||
<tr valign="middle"> | ||
<td width="20%" align="center" colspan="2"> | ||
<a href="https://www.gatsbyjs.org">Gatsby</a> π₯<br><br> | ||
<a href="https://www.gatsbyjs.org"><img src="https://avatars1.githubusercontent.com/u/12551863?s=256&v=4" width="128"></a> | ||
</td> | ||
<td width="20%" align="center" colspan="2"> | ||
<a href="https://vercel.com">Vercel</a> π₯<br><br> | ||
<a href="https://vercel.com"><img src="https://avatars1.githubusercontent.com/u/14985020?s=256&v=4" width="128"></a> | ||
</td> | ||
<td width="20%" align="center" colspan="2"> | ||
<a href="https://www.netlify.com">Netlify</a><br><br> | ||
<!--OC has a sharper image--> | ||
<a href="https://www.netlify.com"><img src="https://images.opencollective.com/netlify/4087de2/logo/256.png" width="128"></a> | ||
</td> | ||
<td width="10%" align="center"> | ||
<a href="https://www.holloway.com">Holloway</a><br><br> | ||
<a href="https://www.holloway.com"><img src="https://avatars1.githubusercontent.com/u/35904294?s=128&v=4" width="64"></a> | ||
</td> | ||
<td width="10%" align="center"> | ||
<a href="https://themeisle.com">ThemeIsle</a><br><br> | ||
<a href="https://themeisle.com"><img src="https://avatars1.githubusercontent.com/u/58979018?s=128&v=4" width="64"></a> | ||
</td> | ||
<td width="10%" align="center"> | ||
<a href="https://boosthub.io">Boost Hub</a><br><br> | ||
<a href="https://boosthub.io"><img src="https://images.opencollective.com/boosthub/6318083/logo/128.png" width="64"></a> | ||
</td> | ||
<td width="10%" align="center"> | ||
<a href="https://expo.io">Expo</a><br><br> | ||
<a href="https://expo.io"><img src="https://avatars1.githubusercontent.com/u/12504344?s=128&v=4" width="64"></a> | ||
</td> | ||
</tr> | ||
<tr valign="middle"> | ||
<td width="100%" align="center" colspan="10"> | ||
<br> | ||
<a href="https://opencollective.com/unified"><strong>You?</strong></a> | ||
<br><br> | ||
</td> | ||
</tr> | ||
</table> | ||
@@ -68,2 +70,5 @@ | ||
This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c): | ||
Node 12+ is needed to use it and it must be `import`ed instead of `require`d. | ||
[npm][]: | ||
@@ -93,15 +98,18 @@ | ||
```js | ||
var vfile = require('to-vfile') | ||
var report = require('vfile-reporter') | ||
var unified = require('unified') | ||
var parse = require('rehype-parse') | ||
var rehype2remark = require('rehype-remark') | ||
var stringify = require('remark-stringify') | ||
import {readSync} from 'to-vfile' | ||
import {reporter} from 'vfile-reporter' | ||
import {unified} from 'unified' | ||
import rehypeParse from 'rehype-parse' | ||
import rehypeRemark from 'rehype-remark' | ||
import remarkStringify from 'remark-stringify' | ||
const file = readSync('example.html') | ||
unified() | ||
.use(parse, {emitParseErrors: true, duplicateAttribute: false}) | ||
.use(rehype2remark) | ||
.use(stringify) | ||
.process(vfile.readSync('example.html'), function(err, file) { | ||
console.error(report(err || file)) | ||
.use(rehypeParse, {emitParseErrors: true, duplicateAttribute: false}) | ||
.use(rehypeRemark) | ||
.use(remarkStringify) | ||
.process(file) | ||
.then((file) => { | ||
console.error(reporter(file)) | ||
console.log(String(file)) | ||
@@ -127,4 +135,7 @@ }) | ||
### `processor.use(parse[, options])` | ||
This package exports no identifiers. | ||
The default export is `rehypeParse`. | ||
### `unified().use(rehypeParse[, options])` | ||
Configure `processor` to parse HTML and create a [**hast**][hast] syntax tree. | ||
@@ -165,3 +176,3 @@ | ||
Setting this to true starts emitting [HTML parse errors][parse-errors]. | ||
Setting this to `true` starts emitting [HTML parse errors][parse-errors]. | ||
@@ -187,3 +198,3 @@ Specific rules can be turned off by setting them to `false` (or `0`). | ||
* [`controlCharacterReference`](https://html.spec.whatwg.org/multipage/parsing.html#parse-error-control-character-reference) β unexpected control character reference ([example](https://github.com/rehypejs/rehype/blob/main/test/parse-error/control-character-reference/index.html)) | ||
* `disallowedContentInNoscriptInHead` β disallowed content inside \`<noscript>\` in \`<head>\` ([example](https://github.com/rehypejs/rehype/blob/main/test/parse-error/disallowed-content-in-noscript-in-head/index.html)) | ||
* `disallowedContentInNoscriptInHead` β disallowed content inside `<noscript>` in `<head>` ([example](https://github.com/rehypejs/rehype/blob/main/test/parse-error/disallowed-content-in-noscript-in-head/index.html)) | ||
* [`duplicateAttribute`](https://html.spec.whatwg.org/multipage/parsing.html#parse-error-duplicate-attribute) β unexpected duplicate attribute ([example](https://github.com/rehypejs/rehype/blob/main/test/parse-error/duplicate-attribute/index.html)) | ||
@@ -205,3 +216,3 @@ * [`endTagWithAttributes`](https://html.spec.whatwg.org/multipage/parsing.html#parse-error-end-tag-with-attributes) β unexpected attribute on closing tag ([example](https://github.com/rehypejs/rehype/blob/main/test/parse-error/end-tag-with-attributes/index.html)) | ||
* `misplacedDoctype` β misplaced doctype ([example](https://github.com/rehypejs/rehype/blob/main/test/parse-error/misplaced-doctype/index.html)) | ||
* `misplacedStartTagForHeadElement` β misplaced \`<head>\` start tag ([example](https://github.com/rehypejs/rehype/blob/main/test/parse-error/misplaced-start-tag-for-head-element/index.html)) | ||
* `misplacedStartTagForHeadElement` β misplaced `<head>` start tag ([example](https://github.com/rehypejs/rehype/blob/main/test/parse-error/misplaced-start-tag-for-head-element/index.html)) | ||
* [`missingAttributeValue`](https://html.spec.whatwg.org/multipage/parsing.html#parse-error-missing-attribute-value) β missing attribute value ([example](https://github.com/rehypejs/rehype/blob/main/test/parse-error/missing-attribute-value/index.html)) | ||
@@ -222,3 +233,3 @@ * `missingDoctype` β missing doctype before other content ([example](https://github.com/rehypejs/rehype/blob/main/test/parse-error/missing-doctype/index.html)) | ||
* [`nestedComment`](https://html.spec.whatwg.org/multipage/parsing.html#parse-error-nested-comment) β unexpected nested comment ([example](https://github.com/rehypejs/rehype/blob/main/test/parse-error/nested-comment/index.html)) | ||
* `nestedNoscriptInHead` β unexpected nested \`<noscript>\` in \`<head>\` ([example](https://github.com/rehypejs/rehype/blob/main/test/parse-error/nested-noscript-in-head/index.html)) | ||
* `nestedNoscriptInHead` β unexpected nested `<noscript>` in `<head>` ([example](https://github.com/rehypejs/rehype/blob/main/test/parse-error/nested-noscript-in-head/index.html)) | ||
* `nonConformingDoctype` β unexpected non-conforming doctype declaration ([example](https://github.com/rehypejs/rehype/blob/main/test/parse-error/non-conforming-doctype/index.html)) | ||
@@ -235,3 +246,3 @@ * [`nonVoidHtmlElementStartTagWithTrailingSolidus`](https://html.spec.whatwg.org/multipage/parsing.html#parse-error-non-void-html-element-start-tag-with-trailing-solidus) β unexpected trailing slash on start tag of non-void element ([example](https://github.com/rehypejs/rehype/blob/main/test/parse-error/non-void-html-element-start-tag-with-trailing-solidus/index.html)) | ||
* [`unexpectedCharacterInUnquotedAttributeValue`](https://html.spec.whatwg.org/multipage/parsing.html#parse-error-unexpected-character-in-unquoted-attribute-value) β unexpected character in unquoted attribute value ([example](https://github.com/rehypejs/rehype/blob/main/test/parse-error/unexpected-character-in-unquoted-attribute-value/index.html)) | ||
* [`unexpectedEqualsSignBeforeAttributeName`](https://html.spec.whatwg.org/multipage/parsing.html#parse-error-unexpected-equals-sign-before-attribute-name) β unexpected equals sign before attribute name ([example](https://github.com/rehypejs/rehype/blob/main/test/parse-error/unexpected-equals-sign-before-attribute-name/index.html)) | ||
* [`unexpectedEqualsSignBeforeAttributeName`](https://html.spec.whatwg.org/multipage/parsing.html#parse-error-unexpected-equals-sign-before-attribute-name) β unexpected equals sign before attribute name ([example](https://github.com/rehypejs/rehype/blob/main/test/parse-error/unexpected-equals-sign-before-attribute-name/index.html)) | ||
* [`unexpectedNullCharacter`](https://html.spec.whatwg.org/multipage/parsing.html#parse-error-unexpected-null-character) β unexpected NULL character ([example](https://github.com/rehypejs/rehype/blob/main/test/parse-error/unexpected-null-character/index.html)) | ||
@@ -300,5 +311,5 @@ * [`unexpectedQuestionMarkInsteadOfTagName`](https://html.spec.whatwg.org/multipage/parsing.html#parse-error-unexpected-question-mark-instead-of-tag-name) β unexpected question mark instead of tag name ([example](https://github.com/rehypejs/rehype/blob/main/test/parse-error/unexpected-question-mark-instead-of-tag-name/index.html)) | ||
[build-badge]: https://img.shields.io/travis/rehypejs/rehype.svg | ||
[build-badge]: https://github.com/rehypejs/rehype/workflows/main/badge.svg | ||
[build]: https://travis-ci.org/rehypejs/rehype | ||
[build]: https://github.com/rehypejs/rehype/actions | ||
@@ -323,5 +334,5 @@ [coverage-badge]: https://img.shields.io/codecov/c/github/rehypejs/rehype.svg | ||
[chat-badge]: https://img.shields.io/badge/chat-spectrum-7b16ff.svg | ||
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg | ||
[chat]: https://spectrum.chat/unified/rehype | ||
[chat]: https://github.com/rehypejs/rehype/discussions | ||
@@ -328,0 +339,0 @@ [health]: https://github.com/rehypejs/.github |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
61429
8
1073
0
373
Yes
4
1
+ Added@types/hast@^2.0.0
+ Addedunified@^10.0.0
+ Addedbail@2.0.2(transitive)
+ Addedcomma-separated-tokens@2.0.3(transitive)
+ Addedextend@3.0.2(transitive)
+ Addedhast-util-from-parse5@7.1.2(transitive)
+ Addedhast-util-parse-selector@3.1.1(transitive)
+ Addedhastscript@7.2.0(transitive)
+ Addedis-plain-obj@4.1.0(transitive)
+ Addedproperty-information@6.5.0(transitive)
+ Addedspace-separated-tokens@2.0.2(transitive)
+ Addedtrough@2.2.0(transitive)
+ Addedunified@10.1.2(transitive)
+ Addedunist-util-stringify-position@3.0.3(transitive)
+ Addedvfile@5.3.7(transitive)
+ Addedvfile-location@4.1.0(transitive)
+ Addedvfile-message@3.1.4(transitive)
+ Addedweb-namespaces@2.0.1(transitive)
- Removed@types/parse5@5.0.3(transitive)
- Removedcomma-separated-tokens@1.0.8(transitive)
- Removedhast-util-from-parse5@6.0.1(transitive)
- Removedhast-util-parse-selector@2.2.5(transitive)
- Removedhastscript@6.0.0(transitive)
- Removedproperty-information@5.6.0(transitive)
- Removedspace-separated-tokens@1.1.5(transitive)
- Removedunist-util-stringify-position@2.0.3(transitive)
- Removedvfile@4.2.1(transitive)
- Removedvfile-location@3.2.0(transitive)
- Removedvfile-message@2.0.4(transitive)
- Removedweb-namespaces@1.1.4(transitive)
- Removedxtend@4.0.2(transitive)
Updatedhast-util-from-parse5@^7.0.0