
Security News
ECMAScript 2025 Finalized with Iterator Helpers, Set Methods, RegExp.escape, and More
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
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 and easy library that convert Markdown to HTML.
package size minified gzipped
safe-marked 90.15 KB 39.36 KB 13.82 KB (browser bundle size)
marked@0.7.0 45.05 KB 23.87 KB 7.87 KB
dompurify@1.0.11 45.21 KB 15.3 KB 5.99 KB
# Other Markdown library
markdown-it@9.0.0 325.52 KB 92.69 KB 32.77 KB
showdown@1.9.0 157.28 KB 71.06 KB 23.55 KB
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.
marked
: See marked's options
onInit(marked: Marked): unknown
: You can use onInit
to customize marked
instance.marked
.dompurify
: See DOMPurify's optionsAn example for options:
import { createMarkdown } from "safe-marked";
import { gfmHeadingId } from "marked-gfm-heading-id";
const markdown = createMarkdown({
marked: {
// Add plugin to marked
onInit(marked) {
// add plugin
marked.use(gfmHeadingId());
},
// same options for https://marked.js.org/#/USING_ADVANCED.md
gfm: 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.
`);
No. safe-marked has two type of entry point.
Browser entrypoint does not includes jsdom. (just use marked + dompurify)
Browser demo: https://stackblitz.com/edit/js-pquqgx?file=index.js,package.json
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 2,425 weekly downloads. As such, safe-marked popularity was classified as popular.
We found that safe-marked demonstrated a not healthy version release cadence and project activity because the last version was released 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
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
Research
North Korean threat actors linked to the Contagious Interview campaign return with 35 new malicious npm packages using a stealthy multi-stage malware loader.