markdown-it-sanitizer
sanitizer plugin for 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:
npm install markdown-it-sanitizer --savebower install markdown-it-sanitizer --save
Use
Basic
var md = html: true ; md; // => '<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:
var md = html: true ; // unknown tagmd; // => '<p><u>test</u></p>'// unknown tag with removeUnknown: truemd; // => '<p>test</p>' // unbalanced tagsmd; // => '<p><b>test</em></p>'// unbalanced tags with removeUnbalanced: truemd; // => '<p>test</p>' // imageClass: 'img-responsive'md; // => '<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
.