New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

simple-marked-sanitizer

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simple-marked-sanitizer

Simple sanitizer for marked

  • 0.3.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
Maintainers
1
Weekly downloads
 
Created
Source

simple-marked-sanitizer

A simple sanitizer implementation for marked.
You can use this as a node module or you can use it from browser directly.

Install

npm install simple-marked-sanitizer

About element(tag name)

It is whitelist based. If tag name is not in whitelist, it will be escaped.

About attributes

It is also whitelist based.
If attribute is not in whitelist, it will be removed.

How to use

Simple

const marked = require("marked");
const SimpleMarkedSanitizer = require("simple-marked-sanitizer");

const sanitizer = new SimpleMarkedSanitizer();

const htmlString = marked(markdownString, {
  sanitize: true,
  sanitizer: sanitizer.getSanitizer()
});

With custom whitelist.

const marked = require("marked");
const SimpleMarkedSanitizer = require("simple-marked-sanitizer");

const sanitizer = new SimpleMarkedSanitizer().elementWhiteList([ // Define name of tags as an array.
    "a", 
    "sup",
    "sub",
    ...
  ]).attributeWhiteList({ // Define name of attributes for each tags.
    "a": ["href", "target"],
    ...
    "*": [class", "id", "style"] // `*` means these attributes are allowed to all tags.
  }).debug(true); // If you want to see conversion result in console.log, switch debug flag to true.

const htmlString = marked(markdownString, {
  sanitize: true,
  sanitizer: sanitizer.getSanitizer()
});

The default whiltelist for elements/attributes are defined in [index.js].
You can get them as a property of SimpleMarkedSanitizer.

const elementWhiteList = SimpleMarkedSanitizer.ELEMENT_WHITELIST;
const attributeWhiteList = SimpleMarkedSanitizer.ATTRIBUTE_WHITELIST;

Element whiltelist is based on marked-sanitizer-github.
Very thanks.

Attribute whitelist is my original.

If there are some other safe elements/attributes, I will add them to default.

Keywords

FAQs

Package last updated on 29 Nov 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc