Gathering detailed insights and metrics for markdown-it
Gathering detailed insights and metrics for markdown-it
Gathering detailed insights and metrics for markdown-it
Gathering detailed insights and metrics for markdown-it
Markdown parser, done right. 100% CommonMark support, extensions, syntax plugins & high speed
npm install markdown-it
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
18,361 Stars
1,132 Commits
1,711 Forks
178 Watching
2 Branches
84 Contributors
Updated on 28 Nov 2024
Minified
Minified + Gzipped
JavaScript (97.11%)
HTML (1.73%)
CSS (1.16%)
Cumulative downloads
Total Downloads
Last day
-9.7%
1,241,297
Compared to previous day
Last week
1.8%
7,381,834
Compared to previous week
Last month
15.6%
30,240,174
Compared to previous month
Last year
24%
312,285,691
Compared to previous year
6
31
Markdown parser done right. Fast and easy to extend.
Table of content
node.js:
1npm install markdown-it
browser (CDN):
See also:
1// node.js 2// can use `require('markdown-it')` for CJS 3import markdownit from 'markdown-it' 4const md = markdownit() 5const result = md.render('# markdown-it rulezz!'); 6 7// browser with UMD build, added to "window" on script load 8// Note, there is no dash in "markdownit". 9const md = window.markdownit(); 10const result = md.render('# markdown-it rulezz!');
Single line rendering, without paragraph wrap:
1import markdownit from 'markdown-it' 2const md = markdownit() 3const result = md.renderInline('__markdown-it__ rulezz!');
(*) presets define combinations of active rules and options. Can be
"commonmark"
, "zero"
or "default"
(if skipped). See
API docs for more details.
1import markdownit from 'markdown-it' 2 3// commonmark mode 4const md = markdownit('commonmark') 5 6// default mode 7const md = markdownit() 8 9// enable everything 10const md = markdownit({ 11 html: true, 12 linkify: true, 13 typographer: true 14}) 15 16// full options list (defaults) 17const md = markdownit({ 18 // Enable HTML tags in source 19 html: false, 20 21 // Use '/' to close single tags (<br />). 22 // This is only for full CommonMark compatibility. 23 xhtmlOut: false, 24 25 // Convert '\n' in paragraphs into <br> 26 breaks: false, 27 28 // CSS language prefix for fenced blocks. Can be 29 // useful for external highlighters. 30 langPrefix: 'language-', 31 32 // Autoconvert URL-like text to links 33 linkify: false, 34 35 // Enable some language-neutral replacement + quotes beautification 36 // For the full list of replacements, see https://github.com/markdown-it/markdown-it/blob/master/lib/rules_core/replacements.mjs 37 typographer: false, 38 39 // Double + single quotes replacement pairs, when typographer enabled, 40 // and smartquotes on. Could be either a String or an Array. 41 // 42 // For example, you can use '«»„“' for Russian, '„“‚‘' for German, 43 // and ['«\xA0', '\xA0»', '‹\xA0', '\xA0›'] for French (including nbsp). 44 quotes: '“”‘’', 45 46 // Highlighter function. Should return escaped HTML, 47 // or '' if the source string is not changed and should be escaped externally. 48 // If result starts with <pre... internal wrapper is skipped. 49 highlight: function (/*str, lang*/) { return ''; } 50});
1import markdownit from 'markdown-it' 2 3const md = markdownit 4 .use(plugin1) 5 .use(plugin2, opts, ...) 6 .use(plugin3);
Apply syntax highlighting to fenced code blocks with the highlight
option:
1import markdownit from 'markdown-it' 2import hljs from 'highlight.js' // https://highlightjs.org 3 4// Actual default values 5const md = markdownit({ 6 highlight: function (str, lang) { 7 if (lang && hljs.getLanguage(lang)) { 8 try { 9 return hljs.highlight(str, { language: lang }).value; 10 } catch (__) {} 11 } 12 13 return ''; // use external default escaping 14 } 15});
Or with full wrapper override (if you need assign class to <pre>
or <code>
):
1import markdownit from 'markdown-it' 2import hljs from 'highlight.js' // https://highlightjs.org 3 4// Actual default values 5const md = markdownit({ 6 highlight: function (str, lang) { 7 if (lang && hljs.getLanguage(lang)) { 8 try { 9 return '<pre><code class="hljs">' + 10 hljs.highlight(str, { language: lang, ignoreIllegals: true }).value + 11 '</code></pre>'; 12 } catch (__) {} 13 } 14 15 return '<pre><code class="hljs">' + md.utils.escapeHtml(str) + '</code></pre>'; 16 } 17});
linkify: true
uses linkify-it. To
configure linkify-it, access the linkify instance through md.linkify
:
1md.linkify.set({ fuzzyEmail: false }); // disables converting email to link
If you are going to write plugins, please take a look at Development info.
Embedded (enabled by default):
Via plugins:
By default all rules are enabled, but can be restricted by options. On plugin load all its rules are enabled automatically.
1import markdownit from 'markdown-it' 2 3// Activate/deactivate rules, with currying 4const md = markdownit() 5 .disable(['link', 'image']) 6 .enable(['link']) 7 .enable('image'); 8 9// Enable everything 10const md = markdownit({ 11 html: true, 12 linkify: true, 13 typographer: true, 14});
You can find all rules in sources:
Here is the result of readme parse at MB Pro Retina 2013 (2.4 GHz):
1npm run benchmark-deps 2benchmark/benchmark.mjs readme 3 4Selected samples: (1 of 28) 5 > README 6 7Sample: README.md (7774 bytes) 8 > commonmark-reference x 1,222 ops/sec ±0.96% (97 runs sampled) 9 > current x 743 ops/sec ±0.84% (97 runs sampled) 10 > current-commonmark x 1,568 ops/sec ±0.84% (98 runs sampled) 11 > marked x 1,587 ops/sec ±4.31% (93 runs sampled)
Note. CommonMark version runs with simplified link normalizers for more "honest" compare. Difference is ≈1.5×.
As you can see, markdown-it
doesn't pay with speed for its flexibility.
Slowdown of "full" version caused by additional features not available in
other implementations.
Available as part of the Tidelift Subscription.
The maintainers of markdown-it
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. Learn more.
markdown-it is the result of the decision of the authors who contributed to 99% of the Remarkable code to move to a project with the same authorship but new leadership (Vitaly and Alex). It's not a fork.
Big thanks to John MacFarlane for his work on the CommonMark spec and reference implementations. His work saved us a lot of time during this project's development.
Related Links:
Ports
The latest stable version of the package.
Stable Version
1
7.5/10
Summary
markdown-it vulnerable to Inefficient Regular Expression Complexity
Affected Versions
< 3.0.0
Patched Versions
3.0.0
1
5.3/10
Summary
Uncontrolled Resource Consumption in markdown-it
Affected Versions
< 12.3.2
Patched Versions
12.3.2
Reason
3 commit(s) out of 30 and 13 issue activity out of 30 found in the last 90 days -- score normalized to 10
Reason
no vulnerabilities detected
Reason
security policy file detected
Details
Reason
update tool detected
Details
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
no binaries found in the repo
Reason
dependency not pinned by hash detected -- score normalized to 7
Details
Reason
GitHub code reviews found for 10 commits out of the last 30 -- score normalized to 3
Details
Reason
no badge detected
Reason
non read-only tokens detected in GitHub workflows
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
project is not fuzzed
Score
Last Scanned on 2022-08-15
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More