-
built for speed. * -
a low-level markdown compiler for parsing markdown without caching or blocking for long periods of time. ** -
light-weight while implementing all markdown features from the supported flavors & specifications. *** -
available as a command line interface (CLI) and running in client- or server-side JavaScript projects.
Demo
Installation
npm install marked
Usage
Warning: 🚨 Marked does not sanitize the output HTML. If you are processing potentially unsafe strings, it's important to filter for possible XSS attacks. Some filtering options include DOMPurify (recommended), js-xss , sanitize-html and insane on the output HTML! 🚨
DOMPurify .sanitize (marked .parse (`< img src = "x" onerror= "alert('not happening')" >`));
// remove the most common zerowidth characters from the start of the file marked. parse ( contents. replace ( /^[\u200B\u200C\u200D\u200E\u200F\uFEFF]/ , "" ) )
# Example with stdin input $ marked -o hello.html hello world ^D $ cat hello.html <p>hello world</p>
# Example with string input $ marked -s "*hello world*" <p><em>hello world</em></p>
# Example with file input
echo "**bold text example**" > readme.md $ marked -i readme.md -o readme.html $ cat readme.html <p><strong>bold text example</strong></p>
# Print all options $ marked -- help
~/.marked.json ~/.marked.js ~/.marked/index.js
# Example with custom config
echo '{ "breaks": true }' > config.json $ marked -s 'line1\nline2' -c config.json <p>line1<br>line2</p>
<! doctype html >
< html >
< head >
< meta charset = "utf-8" />
< title > Marked in the browser </ title >
</ head >
< body >
< div id = "content" > </ div >
< script src = " https://cdn.jsdelivr.net/npm/marked/marked.min.js " > </ script >
< script >
document . getElementById ( 'content' ). innerHTML = marked. parse ( '# Marked in browser\n\nRendered by **marked**.' ); </ script >
</ body >
</ html >
< script type = "module" >
import { marked } from " https://cdn.jsdelivr.net/npm/marked/lib/marked.esm.js " ; document . getElementById ( 'content' ). innerHTML = marked. parse ( '# Marked in the browser\n\nRendered by **marked**.' ); </ script >
import { marked } from 'marked' ; // or const { marked } = require('marked');
const html = marked. parse ( '# Marked in Node.js\n\nRendered by **marked**.' );
Supported Markdown specifications
|
|
|
---|---|---|
|
|
|
|
|
|
|
|
|
List of Tools Using Marked
|
|
---|---|
|
|
|
|
|
|
|
|
|
|
Security