Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
safe-marked
Advanced tools
Convert Markdown to HTML using marked and DOMPurify.
marked does not sanitized by default.
Also, marked will remove sanitize
option in the future.
We want to get safe converter from Markdown to HTML.
Install with npm:
npm install safe-marked
import { createMarkdown } from "safe-marked";
const markdown = createMarkdown();
const html = markdown(`# Header
This is [CommonMark](https://commonmark.org/) text.
`);
console.log(html);
/* <h1 id="header">Header</h1>
<p>This is <a href="https://commonmark.org/">CommonMark</a> text.</p>
*/
The output is sanitized by default.
import { createMarkdown } from "safe-marked";
const markdown = createMarkdown();
const html = markdown(`<script>alert(1)</script>
<iframe src="https://example.com"></iframe>
This is [XSS](javascript:alert(1))`);
// sanitized by default
assert.strictEqual(html, `
<p>This is <a>XSS</a></p>
`);
You can pass options for these library.
An example for options:
import { createMarkdown } from "safe-marked";
const markdown = createMarkdown({
// same options for https://marked.js.org/#/USING_ADVANCED.md
marked: {
headerIds: false
},
// same options for https://github.com/cure53/DOMPurify
dompurify: {
ADD_TAGS: ["iframe"]
}
});
const html = markdown(`# Header
<iframe src="https://example.com"></iframe>
This is [CommonMark](https://commonmark.org/) text.
`);
assert.strictEqual(html, `<h1>Header</h1>
<iframe src="https://example.com"></iframe>
This is [CommonMark](https://commonmark.org/) text.
`);
See Releases page.
Install devDependencies and Run npm test
:
npm test
Pull requests and stars are always welcome.
For bugs and feature requests, please create an issue.
git checkout -b my-new-feature
git commit -am 'Add some feature'
git push origin my-new-feature
MIT © azu
FAQs
Markdown to HTML using marked and DOMPurify. Safe by default.
The npm package safe-marked receives a total of 1,410 weekly downloads. As such, safe-marked popularity was classified as popular.
We found that safe-marked demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.