logo

Marked Documentation

Marked is

  1. built for speed.*
  2. a low-level markdown compiler for parsing markdown without caching or blocking for long periods of time.**
  3. light-weight while implementing all markdown features from the supported flavors & specifications.***
  4. available as a command line interface (CLI) and running in client- or server-side JavaScript projects.

* Still working on metrics for comparative analysis and definition.
** As few dependencies as possible.
*** Strict compliance could result in slower processing when running comparative benchmarking.

Demo

Checkout the demo page to see marked in action ⛹ī¸

These documentation pages are also rendered using marked đŸ’¯

Installation

CLI: npm install -g marked

In-browser:

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')">`));

⚠ī¸ Input: special ZERO WIDTH unicode characters (for example \uFEFF) might interfere with parsing. Some text editors add them at the start of the file (see: #2139).

// remove the most common zerowidth characters from the start of the file
marked.parse(
  contents.replace(/^[\u200B\u200C\u200D\u200E\u200F\uFEFF]/,"")
)

CLI

# 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

CLI Config

A config file can be used to configure the marked cli.

If it is a .json file it should be a JSON object that will be passed to marked as options.

If .js is used it should have a default export of a marked options object or a function that takes marked as a parameter. It can use the marked parameter to install extensions using marked.use.

By default the marked cli will look for a config file in your home directory in the following order.

  • ~/.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>

Browser

<!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>

or import esm module

<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>

Node.js

import { marked } from 'marked';
// or const { marked } = require('marked');

const html = marked.parse('# Marked in Node.js\n\nRendered by **marked**.');

Marked offers advanced configurations and extensibility as well.

Supported Markdown specifications

We actively support the features of the following Markdown flavors.

Markdown 1.0 (100%)
Section Passing Percent
amps_and_angles_encoding 1 of 1 100%
auto_links 1 of 1 100%
backslash_escapes 1 of 1 100%
blockquotes_with_code_blocks 1 of 1 100%
code_blocks 1 of 1 100%
code_spans 1 of 1 100%
hard_wrapped_paragraphs_with_list_like_lines 1 of 1 100%
horizontal_rules 1 of 1 100%
inline_html_advanced 1 of 1 100%
inline_html_comments 1 of 1 100%
inline_html_simple 1 of 1 100%
links_inline_style 1 of 1 100%
links_reference_style 1 of 1 100%
links_shortcut_references 1 of 1 100%
literal_quotes_in_titles 1 of 1 100%
markdown_documentation_basics 1 of 1 100%
markdown_documentation_syntax 1 of 1 100%
nested_blockquotes 1 of 1 100%
ordered_and_unordered_lists 1 of 1 100%
tabs 1 of 1 100%
tidyness 1 of 1 100%
CommonMark 0.31 (96%)
Section Passing Percent
Tabs 11 of 11 100%
Backslash escapes 13 of 13 100%
Entity and numeric character references 15 of 17 88%
Precedence 1 of 1 100%
Thematic breaks 19 of 19 100%
ATX headings 18 of 18 100%
Setext headings 27 of 27 100%
Indented code blocks 12 of 12 100%
Fenced code blocks 29 of 29 100%
HTML blocks 44 of 44 100%
Link reference definitions 27 of 27 100%
Paragraphs 8 of 8 100%
Blank lines 1 of 1 100%
Block quotes 25 of 25 100%
List items 48 of 48 100%
Lists 26 of 26 100%
Inlines 1 of 1 100%
Code spans 22 of 22 100%
Emphasis and strong emphasis 132 of 132 100%
Links 75 of 90 83%
Images 15 of 22 68%
Autolinks 19 of 19 100%
Raw HTML 20 of 20 100%
Hard line breaks 15 of 15 100%
Soft line breaks 2 of 2 100%
Textual content 3 of 3 100%
GitHub Flavored Markdown 0.29 (95%)
Section Passing Percent
Tabs 11 of 11 100%
Backslash escapes 13 of 13 100%
Entity and numeric character references 15 of 17 88%
Precedence 1 of 1 100%
Thematic breaks 19 of 19 100%
ATX headings 18 of 18 100%
Setext headings 27 of 27 100%
Indented code blocks 12 of 12 100%
Fenced code blocks 29 of 29 100%
HTML blocks 44 of 44 100%
Link reference definitions 27 of 27 100%
Paragraphs 8 of 8 100%
Blank lines 1 of 1 100%
Block quotes 25 of 25 100%
List items 48 of 48 100%
Lists 26 of 26 100%
Inlines 1 of 1 100%
Code spans 22 of 22 100%
Emphasis and strong emphasis 132 of 132 100%
Links 75 of 90 83%
Images 15 of 22 68%
Autolinks 15 of 19 79%
Raw HTML 20 of 20 100%
Hard line breaks 15 of 15 100%
Soft line breaks 2 of 2 100%
Textual content 3 of 3 100%
[extension] Tables 8 of 8 100%
[extension] Task list items 2 of 2 100%
[extension] Strikethrough 3 of 3 100%
[extension] Autolinks 11 of 14 79%
[extension] Disallowed Raw HTML 0 of 1 0%

By supporting the above Markdown flavors, it's possible that Marked can help you use other flavors as well; however, these are not actively supported by the community.

List of Tools Using Marked

We actively support the usability of Marked in super-fast markdown transformation, some of Tools using Marked for single-page creations are

Tools Description
zero-md A native markdown-to-html web component to load and display an external MD file.It uses Marked for super-fast markdown transformation.
texme TeXMe is a lightweight JavaScript utility to create self-rendering Markdown + LaTeX documents.
StrapDown.js StrapDown.js is an awesome on-the-fly Markdown to HTML text processor.
raito Mini Markdown Wiki/CMS in 8kb of JavaScript.
Homebrewery The Homebrewery is a tool for making authentic looking D&D content using Markdown. It is distributed under the terms of the MIT.
marked_reader marked_reader is an open source Markdown reader packed by Electron.

Security

The only completely secure system is the one that doesn't exist in the first place. Having said that, we take the security of Marked very seriously.

Therefore, please disclose potential security issues by email to the project committers as well as the listed owners within NPM. We will provide an initial assessment of security reports within 48 hours and should apply patches within 2 weeks (also, feel free to contribute a fix for the issue).