unified

Project: micromark/micromark-extension-gfm-tagfilter

Package: micromark-extension-gfm-tagfilter@1.0.0

  1. Dependents: 1
  2. micromark extension to support GFM tagfilter
  1. unified 174
  2. markdown 131
  3. html 121
  4. micromark 32
  5. gfm 18
  6. micromark-extension 15
  7. filter 5
  8. tagfilter 3
  9. tag 2

micromark-extension-gfm-tagfilter

Build Coverage Downloads Size Sponsors Backers Chat

micromark extension to support GitHub flavored markdown tag filter. This extension matches the GFM spec and github.com. The tag filter is a rather naïve attempt at XSS protection. It’s much better to use a proper HTML sanitizing algorithm.

When to use this

You should probably use micromark-extension-gfm, which combines this package with other GFM features, instead. If for some weird reason you have to match GHs tagfilter, but not all the other GFM parts, use this package.

Install

This package is ESM only: Node 12+ is needed to use it and it must be imported instead of required.

npm:

npm install micromark-extension-gfm-tagfilter

Use

import {micromark} from 'micromark'
import {gfmTagfilterHtml} from 'micromark-extension-gfm-tagfilter'

const output = micromark('XSS! <script>alert(1)</script>', {
  allowDangerousHtml: true,
  htmlExtensions: [gfmTagfilterHtml]
})

console.log(output)

Yields:

<p>XSS! &lt;script>alert(1)&lt;/script></p>

API

This package exports the following identifiers: gfmTagfilterHtml. There is no default export.

gfmTagfilterHtml

Support a tag filter (protection against script, plaintext, etc). The export is an extension for the micromark compiler to escape certain tag names (can be passed in htmlExtensions).

Contribute

See contributing.md in micromark/.github for ways to get started. See support.md for ways to get help.

This project has a code of conduct. By interacting with this repository, organization, or community you agree to abide by its terms.

License

MIT © Titus Wormer