-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
43 additions
and
30 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,22 +1,28 @@ | ||
/** | ||
* @typedef {import('hast').Root} Root | ||
* | ||
* @typedef {import('hast-util-sanitize').Schema} Options | ||
* The sanitation schema defines how and if nodes and properties should be cleaned. | ||
* See `hast-util-sanitize`. | ||
* The default schema is exported as `defaultSchema`. | ||
* @typedef {import('hast-util-sanitize').Schema} Schema | ||
*/ | ||
|
||
import {sanitize as hastUtilSanitize, defaultSchema} from 'hast-util-sanitize' | ||
import {sanitize} from 'hast-util-sanitize' | ||
|
||
/** | ||
* Plugin to sanitize HTML. | ||
* | ||
* @type {import('unified').Plugin<[Options?] | Array<void>, Root, Root>} | ||
* @param {Schema | null | undefined} [options] | ||
* Configuration (optional). | ||
* @returns | ||
* Transform. | ||
*/ | ||
export default function rehypeSanitize(options = defaultSchema) { | ||
// @ts-expect-error: assume input `root` matches output root. | ||
return (tree) => hastUtilSanitize(tree, options) | ||
export default function rehypeSanitize(options) { | ||
/** | ||
* @param {Root} tree | ||
* Tree. | ||
* @returns {Root} | ||
* New tree. | ||
*/ | ||
return function (tree) { | ||
// Assume root in -> root out. | ||
const result = /** @type {Root} */ (sanitize(tree, options)) | ||
return result | ||
} | ||
} | ||
|
||
export {defaultSchema} from 'hast-util-sanitize' |
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