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
 
x24
x24
 
x1
 
 
 
 
 
 
 
 
 
x24
x24
 
x24
x24
x50
x50
x77
x77
x50
x50























// 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
}