# markdown-it-sanitizer

> sanitizer for markdown-it.

Latest version **0.4.3** (published 2016-09-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install markdown-it-sanitizer
pnpm add markdown-it-sanitizer
yarn add markdown-it-sanitizer
bun add markdown-it-sanitizer
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.3 |
| Published | 2016-09-28 |
| First published | 2015-01-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 16 |
| Maintainers | svbergerem |
| Keywords | markdown-it-plugin, markdown-it, markdown, sanitizer |

## Links

- npm: https://www.npmjs.com/package/markdown-it-sanitizer
- Repository: https://github.com/svbergerem/markdown-it-sanitizer
- Issues: https://github.com/svbergerem/markdown-it-sanitizer/issues
- npm.io page: https://npm.io/package/markdown-it-sanitizer

## Alternatives

- [@mdxeditor/editor](https://npm.io/package/@mdxeditor/editor.md) — 962.4K weekly downloads
- [mmdb-lib](https://npm.io/package/mmdb-lib.md) — 680.9K weekly downloads
- [playcanvas](https://npm.io/package/playcanvas.md) — 36.2K weekly downloads
- [@glw907/cairn-cms](https://npm.io/package/@glw907/cairn-cms.md) — 967 weekly downloads
- [markdown-to-confluence](https://npm.io/package/markdown-to-confluence.md) — 103 weekly downloads

## Recent versions

- 0.4.3 (latest) — 2016-09-28
- 0.4.2 — 2016-08-10
- 0.4.1 — 2015-10-30
- 0.4.0 — 2015-10-06
- 0.3.2 — 2015-06-11
- 0.3.1 — 2015-05-17
- 0.3.0 — 2015-03-25
- 0.2.2 — 2015-02-28
- 0.2.1 — 2015-02-13
- 0.2.0 — 2015-01-13

## README

# markdown-it-sanitizer

[![Build Status](https://img.shields.io/travis/svbergerem/markdown-it-sanitizer/master.svg?style=flat)](https://travis-ci.org/svbergerem/markdown-it-sanitizer)
[![Coverage Status](https://img.shields.io/coveralls/svbergerem/markdown-it-sanitizer/master.svg?style=flat)](https://coveralls.io/r/svbergerem/markdown-it-sanitizer?branch=master)
[![npm version](https://img.shields.io/npm/v/markdown-it-sanitizer.svg?style=flat)](https://npmjs.com/package/markdown-it-sanitizer)

> sanitizer plugin for [markdown-it](https://github.com/markdown-it/markdown-it) markdown parser.

## Accepted tags

All tags are parsed case insensitive.

### Balanced
`<b>`, `<blockquote>`, `<code>`, `<em>`, `<h1>`, ..., `<h6>`, `<li>`, `<ol>`, `<ol start="42">`, `<p>`, `<pre>`, `<sub>`, `<sup>`, `<strong>`, `<strike>`, `<ul>`

### Standalone
`<br>`, `<hr>`

### Links
`<a href="http://example.com" title="link">text</a>`

The `title` attribute is optional.

### Images
`<img src="http://example.com" alt="cat" title="image">`

The `alt` and `title` attributes are optional.

## Install

node.js, bower:

```bash
npm install markdown-it-sanitizer --save
bower install markdown-it-sanitizer --save
```

## Use

#### Basic

```js
var md = require('markdown-it')({ html: true })
            .use(require('markdown-it-sanitizer'));

md.render('<b>test<p></b>'); // => '<p><b>test</b></p>'
```

#### Advanced

For not whitelisted tags and tags that don't have a matching opening/closing tag you can define whether you would like to remove or escape them. You can also define a class attribute that will be added to image tags. Here is an example with default values:

```js
var md = require('markdown-it')({ html: true })
            .use(require('markdown-it-sanitizer'), {
              imageClass: '',
              removeUnbalanced: false,
              removeUnknown: false
            });

// unknown tag
md.render('<u>test</u>'); // => '<p>&lt;u&gt;test&lt;/u&gt;</p>'
// unknown tag with removeUnknown: true
md.render('<u>test</u>'); // => '<p>test</p>'

// unbalanced tags
md.render('<b>test</em>'); // => '<p>&lt;b&gt;test&lt;/em&gt;</p>'
// unbalanced tags with removeUnbalanced: true
md.render('<b>test</em>'); // => '<p>test</p>'

// imageClass: 'img-responsive'
md.render('<img src="http://example.com/image.png" alt="image" title="example">'); // => '<p><img src="http://example.com/image.png" alt="image" title="example" class="img-responsive"></p>'

```

_Differences in the browser._ If you load the script directly into the page, without
package system, the module will add itself globally as `window.markdownitSanitizer`.

## License

[MIT](https://github.com/svbergerem/markdown-it-sanitizer/blob/master/LICENSE)

---
_Source: https://npm.io/package/markdown-it-sanitizer · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
