All files / plugins / sanitize.ts

100.00% Branches 0/0
100.00% Lines 14/14
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
x1
 
x16
x16
 
x1
 
 
 
 
 
 
 
 
 
x16
x16
 
x16
x16
x34
x34
x53
x53
x34
x34























// Imports
import type { Plugin } from "../renderer.ts"
import rehypeSanitize, { defaultSchema as defaults } from "rehype-sanitize"
export { defaults as schema }

/**
 * Sanitize HTML.
 *
 * @example
 * ```md
 * <script>alert('foo')</script>
 * ```
 * ```html
 * <p></p>
 * ```
 */
export default create() as Plugin

/** Create a new HTML sanitization plugin. */
export function create(schema = defaults): Plugin {
  return {
    rehype(processor) {
      return processor.use(rehypeSanitize, schema)
    },
  } as Plugin
}