Skip to content

Commit

Permalink
Add raw nodes to hast node type registry
Browse files Browse the repository at this point in the history
When using this plugin, the raw type will automatically be added to
hast in the correct places.

See DefinitelyTyped/DefinitelyTyped#55187 for more information.
  • Loading branch information
wooorm committed Aug 26, 2021
1 parent df6a00c commit 1a6942e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* @typedef {import('hast').Root} Root
* @typedef {import('hast-util-raw').Options} Options
* @typedef {import('hast-util-raw')} DoNotTouchAsThisImportIncludesRawInTree
*/

import {raw} from 'hast-util-raw'
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
],
"dependencies": {
"@types/hast": "^2.0.0",
"hast-util-raw": "^7.0.0",
"hast-util-raw": "^7.2.0",
"unified": "^10.0.0"
},
"devDependencies": {
Expand All @@ -47,6 +47,7 @@
"tape": "^5.0.0",
"type-coverage": "^2.0.0",
"typescript": "^4.0.0",
"unist-util-visit": "^4.0.0",
"xo": "^0.44.0"
},
"scripts": {
Expand Down
17 changes: 15 additions & 2 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
/**
* @typedef {import('hast').Root} Root
*/

import test from 'tape'
import {unified} from 'unified'
import {visit} from 'unist-util-visit'
import remarkParse from 'remark-parse'
import remarkRehype from 'remark-rehype'
import rehypeStringify from 'rehype-stringify'
import rehypeRaw from './index.js'

test('rehypeRaw', (t) => {
t.plan(2)

unified()
.use(remarkParse)
.use(remarkRehype, {allowDangerousHtml: true})
.use(rehypeRaw)
.use(
/** @type {import('unified').Plugin<[], Root>} */
() => (root) => {
visit(root, 'raw', () => {
t.fail('should not include `raw` in tree after `rehype-raw`')
})
}
)
.use(rehypeStringify)
.process(
[
Expand All @@ -33,6 +48,4 @@ test('rehypeRaw', (t) => {
)
}
)

t.end()
})

0 comments on commit 1a6942e

Please sign in to comment.