https://github.com/azu/marked-plugin-sanitizer
[WIP] marked plugin to sanitize HTML
https://github.com/azu/marked-plugin-sanitizer
escape html marked plugin sanitize
Last synced: 27 days ago
JSON representation
[WIP] marked plugin to sanitize HTML
- Host: GitHub
- URL: https://github.com/azu/marked-plugin-sanitizer
- Owner: azu
- License: mit
- Created: 2020-04-21T14:19:16.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2020-04-21T14:39:00.000Z (about 5 years ago)
- Last Synced: 2025-02-06T12:47:52.018Z (3 months ago)
- Topics: escape, html, marked, plugin, sanitize
- Language: TypeScript
- Homepage:
- Size: 49.8 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# marked-plugin-sanitizer
[marked](https://github.com/markedjs/marked) plugin to sanitize HTML
## Install
Install with [npm](https://www.npmjs.com/):
npm install marked-plugin-sanitizer
## Usage
```js
const marked = require("marked");
const { createSanitizer } = require("marked-plugin-sanitizer");
marked.use(createSanitizer());
const html = marked(`alert(1)This is [XSS](javascript:alert)`);
console.log(html)
/*This is XSS
*/
```### Options:
- `dompurify`: See [DOMPurify](https://github.com/cure53/DOMPurify)'s options
An example for options:
```js
const marked = require("marked");
const { createSanitizer } = require("marked-plugin-sanitizer");
marked.setOptions({
headerIds: false,
});
marked.use(
createSanitizer({
dompurify: {
ADD_TAGS: ["iframe"],
},
})
);
const html = marked(`# HeaderThis is [CommonMark](https://commonmark.org/) text.
`);
assert.strictEqual(
html,
`Header
This is [CommonMark](https://commonmark.org/) text.
`
);
```## Changelog
See [Releases page](https://github.com/azu/marked-plugin-sanitizer/releases).
## Running tests
Install devDependencies and Run `npm test`:
npm test
## Contributing
Pull requests and stars are always welcome.
For bugs and feature requests, [please create an issue](https://github.com/azu/marked-plugin-sanitizer/issues).
1. Fork it!
2. Create your feature branch: `git checkout -b my-new-feature`
3. Commit your changes: `git commit -am 'Add some feature'`
4. Push to the branch: `git push origin my-new-feature`
5. Submit a pull request :D## Author
- [github/azu](https://github.com/azu)
- [twitter/azu_re](https://twitter.com/azu_re)## License
MIT © azu