Github url

markdown-it

by markdown-it

markdown-it /markdown-it

Markdown parser, done right. 100% CommonMark support, extensions, syntax plugins & high speed

9.9K Stars 899 Forks Last release: Not found MIT License 939 Commits 61 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:

markdown-it

Build StatusNPM versionCoverage StatusGitter

Markdown parser done right. Fast and easy to extend.

Live demo

  • Follows the CommonMark spec + adds syntax extensions & sugar (URL autolinking, typographer).
  • Configurable syntax! You can add new rules and even replace existing ones.
  • High speed.
  • Safe by default.
  • Community-written plugins and other packages on npm.

Table of content

Install

node.js & bower:

npm install markdown-it --save bower install markdown-it --save

browser (CDN):

Usage examples

See also:

Simple

// node.js, "classic" way: var MarkdownIt = require('markdown-it'), md = new MarkdownIt(); var result = md.render('# markdown-it rulezz!'); // node.js, the same, but with sugar: var md = require('markdown-it')(); var result = md.render('# markdown-it rulezz!'); // browser without AMD, added to "window" on script load // Note, there is no dash in "markdownit". var md = window.markdownit(); var result = md.render('# markdown-it rulezz!');

Single line rendering, without paragraph wrap:

var md = require('markdown-it')(); var result = md.renderInline('\_\_markdown-it\_\_ rulezz!');

Init with presets and options

(*) presets define combinations of active rules and options. Can be

"commonmark"

,

"zero"

or

"default"

(if skipped). SeeAPI docs for more details.

// commonmark mode var md = require('markdown-it')('commonmark'); // default mode var md = require('markdown-it')(); // enable everything var md = require('markdown-it')({ html: true, linkify: true, typographer: true }); // full options list (defaults) var md = require('markdown-it')({ html: false, // Enable HTML tags in source xhtmlOut: false, // Use '/' to close single tags (
). // This is only for full CommonMark compatibility. breaks: false, // Convert '\n' in paragraphs into 
 langPrefix: 'language-', // CSS language prefix for fenced blocks. Can be // useful for external highlighters. linkify: false, // Autoconvert URL-like text to links // Enable some language-neutral replacement + quotes beautification typographer: false, // Double + single quotes replacement pairs, when typographer enabled, // and smartquotes on. Could be either a String or an Array. // // For example, you can use '«»„“' for Russian, '„“‚‘' for German, // and ['«\xA0', '\xA0»', '‹\xA0', '\xA0›'] for French (including nbsp). quotes: '“”‘’', // Highlighter function. Should return escaped HTML, // or '' if the source string is not changed and should be escaped externally. // If result starts with <pre... internal wrapper is skipped. highlight: function lang return>
<h3>Plugins load</h3>
<pre class="js">var md = require('markdown-it')()
            .use(plugin1)
            .use(plugin2, opts, ...)
            .use(plugin3);
</pre>
<h3>Syntax highlighting</h3>

<p>Apply syntax highlighting to fenced code blocks with the </p><pre class="">highlight</pre> option:
<pre class="js">var hljs = require('highlight.js'); // https://highlightjs.org/

// Actual default values
var md = require('markdown-it')({
  highlight: function (str, lang) {
    if (lang &amp;&amp; hljs.getLanguage(lang)) {
      try {
        return hljs.highlight(lang, str).value;
      } catch (__) {}
    }

    return ''; // use external default escaping
  }
});
</pre>
<p>Or with full wrapper override (if you need assign class to </p><pre class=""><pre></pre>):
<pre class="js">var hljs = require('highlight.js'); // https://highlightjs.org/

// Actual default values
var md = require('markdown-it')({
  highlight: function (str, lang) {
    if (lang &amp;&amp; hljs.getLanguage(lang)) {
      try {
        return '<pre class="hljs"><code>' +
               hljs.highlight(lang, str, true).value +
               '</code></pre>';
      } catch (__) {}
    }

    return '<pre class="hljs"><code>' + md.utils.escapeHtml(str) + '</code></pre>';
  }
});
</pre>
<h3>Linkify</h3>

<p></p><pre class="">linkify: true</pre> uses <a href="https://github.com/markdown-it/linkify-it">linkify-it</a>. To
configure linkify-it, access the linkify instance through <pre class="">md.linkify</pre>:
<pre class="js">md.linkify.tlds('.py', false); // disables .py as top level domain
</pre>
<h2>API</h2>

<p><strong><a href="https://markdown-it.github.io/markdown-it/">API documentation</a></strong></p>

<p>If you are going to write plugins - take a look at
<a href="https://github.com/markdown-it/markdown-it/tree/master/docs">Development info</a>.</p>

<h2>Syntax extensions</h2>

<p>Embedded (enabled by default):</p>

</pre><ul>
<li>
<a href="https://help.github.com/articles/organizing-information-with-tables/">Tables</a> (GFM)</li>
<li>
<a href="https://help.github.com/articles/basic-writing-and-formatting-syntax/#styling-text">Strikethrough</a> (GFM)</li>
</ul>

<p>Via plugins:</p>

<ul>
<li><a href="https://github.com/markdown-it/markdown-it-sub">subscript</a></li>
<li><a href="https://github.com/markdown-it/markdown-it-sup">superscript</a></li>
<li><a href="https://github.com/markdown-it/markdown-it-footnote">footnote</a></li>
<li><a href="https://github.com/markdown-it/markdown-it-deflist">definition list</a></li>
<li><a href="https://github.com/markdown-it/markdown-it-abbr">abbreviation</a></li>
<li><a href="https://github.com/markdown-it/markdown-it-emoji">emoji</a></li>
<li><a href="https://github.com/markdown-it/markdown-it-container">custom container</a></li>
<li><a href="https://github.com/markdown-it/markdown-it-ins">insert</a></li>
<li><a href="https://github.com/markdown-it/markdown-it-mark">mark</a></li>
<li>... and <a href="https://www.npmjs.org/browse/keyword/markdown-it-plugin">others</a>
</li>
</ul>

<h3>Manage rules</h3>

<p>By default all rules are enabled, but can be restricted by options. On plugin
load all its rules are enabled automatically.</p>
<pre class="js">// Activate/deactivate rules, with curring
var md = require('markdown-it')()
            .disable(['link', 'image'])
            .enable(['link'])
            .enable('image');

// Enable everything
md = require('markdown-it')({
  html: true,
  linkify: true,
  typographer: true,
});
</pre>
<p>You can find all rules in sources:
<a href="https://github.com/markdown-it/markdown-it/blob/master/lib/parser_core.js">parser_core.js</a>, <a href="https://github.com/markdown-it/markdown-it/blob/master/lib/parser_block.js">parser_block</a>,
<a href="https://github.com/markdown-it/markdown-it/blob/master/lib/parser_inline.js">parser_inline</a>.</p>

<h2>Benchmark</h2>

<p>Here is the result of readme parse at MB Pro Retina 2013 (2.4 GHz):</p>
<pre class="bash">make benchmark-deps
benchmark/benchmark.js readme

Selected samples: (1 of 28)
 &gt; README

Sample: README.md (7774 bytes)
 &gt; commonmark-reference x 1,222 ops/sec ±0.96% (97 runs sampled)
 &gt; current x 743 ops/sec ±0.84% (97 runs sampled)
 &gt; current-commonmark x 1,568 ops/sec ±0.84% (98 runs sampled)
 &gt; marked x 1,587 ops/sec ±4.31% (93 runs sampled)
</pre>
<p><strong>Note.</strong> CommonMark version runs with <a href="https://github.com/markdown-it/markdown-it/blob/master/benchmark/implementations/current-commonmark/index.js">simplified link normalizers</a>
for more "honest" compare. Difference is ~ 1.5x.</p>

<p>As you can see, </p><pre class="">markdown-it</pre> doesn't pay with speed for it's flexibility.
Slowdown of "full" version caused by additional features not available in
other implementations.

<h2>markdown-it for enterprise</h2>

<p>Available as part of the Tidelift Subscription.</p>

<p>The maintainers of </p><pre class="">markdown-it</pre> and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. <a href="https://tidelift.com/subscription/pkg/npm-markdown-it?utm_source=npm-markdown-it&amp;utm_medium=referral&amp;utm_campaign=enterprise&amp;utm_term=repo">Learn more.</a>

<h2>Authors</h2>

<ul>
<li>Alex Kocharin <a href="https://github.com/rlidwka">github/rlidwka</a>
</li>
<li>Vitaly Puzrin <a href="https://github.com/puzrin">github/puzrin</a>
</li>
</ul>

<p><em>markdown-it</em> is the result of the decision of the authors who contributed to
99% of the <em>Remarkable</em> code to move to a project with the same authorship but
new leadership (Vitaly and Alex). It's not a fork.</p>

<h2>References / Thanks</h2>

<p>Big thanks to <a href="https://github.com/jgm">John MacFarlane</a> for his work on the
CommonMark spec and reference implementations. His work saved us a lot of time
during this project's development.</p>

<p><strong>Related Links:</strong></p>

<ul>
<li>https://github.com/jgm/CommonMark - reference CommonMark implementations in C &amp; JS,
also contains latest spec &amp; online demo.</li>
<li>http://talk.commonmark.org - CommonMark forum, good place to collaborate
developers' efforts.</li>
</ul>

<p><strong>Ports</strong></p>

<ul>
<li>
<a href="https://github.com/digitalmoksha/motion-markdown-it">motion-markdown-it</a> - Ruby/RubyMotion</li>
<li>
<a href="https://github.com/ExecutableBookProject/markdown-it-py">markdown-it-py</a>- Python</li>
</ul>
</pre...>

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.