mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-06-02 14:38:20 +08:00
* Rewrite sanitize-html typings from scratch, reflect new version, full API. * Remove superfluous exports, concat author instead of replace.
23 lines
651 B
TypeScript
23 lines
651 B
TypeScript
/// <reference path="sanitize-html.d.ts" />
|
|
|
|
import * as sanitize from 'sanitize-html';
|
|
|
|
let options: sanitize.IOptions = {
|
|
allowedTags: sanitize.defaults.allowedTags.concat('h1', 'h2', 'img'),
|
|
allowedAttributes: {
|
|
'a': sanitize.defaults.allowedAttributes['a'].concat('rel'),
|
|
'img': ['src', 'height', 'width', 'alt']
|
|
},
|
|
transformTags: {
|
|
'a': sanitize.simpleTransform('a', { 'rel': 'nofollow' }),
|
|
'img': 'canvas'
|
|
},
|
|
exclusiveFilter: function(frame: sanitize.IFrame) {
|
|
return frame.tag === 'a' && !frame.text.trim();
|
|
}
|
|
};
|
|
|
|
let unsafe = '<div><script>alert("hello");</script></div>';
|
|
|
|
let safe = sanitize(unsafe, options);
|