markdown-it vs marked vs remark vs showdown
Markdown 解析库
markdown-itmarkedremarkshowdown类似的npm包:

Markdown 解析库

Markdown 解析库用于将 Markdown 格式的文本转换为 HTML。这些库各自具有不同的特性和设计理念,适用于不同的使用场景和需求。选择合适的库可以提高开发效率,确保生成的 HTML 质量和性能。

npm下载趋势

3 年

GitHub Stars 排名

统计详情

npm包名称
下载量
Stars
大小
Issues
发布时间
License
markdown-it021,229768 kB592 个月前MIT
marked036,732445 kB1610 天前MIT
remark08,80615.7 kB83 年前MIT
showdown014,844801 kB236-MIT

功能对比: markdown-it vs marked vs remark vs showdown

性能

  • markdown-it:

    markdown-it 以其快速的解析速度而闻名,适合处理大量 Markdown 文本。它采用了高效的算法,能够在短时间内完成解析,适合需要高性能的应用场景。

  • marked:

    marked 是一个专注于速度的库,能够快速将 Markdown 转换为 HTML,适合对性能要求极高的应用。

  • remark:

    remark 的性能取决于插件的使用情况,虽然它提供了强大的功能,但在处理大量文本时可能会稍显缓慢。

  • showdown:

    showdown 是一个轻量级的库,虽然性能较好,但在处理复杂 Markdown 文本时可能不如其他库高效。

扩展性

  • markdown-it:

    markdown-it 提供了丰富的插件支持,允许开发者根据需求扩展功能,适合需要自定义 Markdown 解析的项目。

  • marked:

    marked 的扩展性相对较低,主要专注于快速解析,适合不需要额外功能的简单项目。

  • remark:

    remark 以其强大的插件生态系统而著称,允许用户通过插件进行复杂的 Markdown 处理和转换,适合需要深度定制的项目。

  • showdown:

    showdown 提供了一些基本的扩展功能,但相比其他库,其扩展性较弱,适合简单的使用场景。

学习曲线

  • markdown-it:

    markdown-it 的学习曲线相对平缓,易于上手,适合新手和有经验的开发者。

  • marked:

    marked 的 API 简单明了,学习曲线非常平坦,适合快速上手和使用。

  • remark:

    remark 的学习曲线稍陡,因为它涉及到 AST 的概念,适合有一定基础的开发者。

  • showdown:

    showdown 的学习曲线非常低,易于理解和使用,适合快速开发和原型制作。

社区支持

  • markdown-it:

    markdown-it 拥有活跃的社区和丰富的文档,易于获取支持和资源。

  • marked:

    marked 也有良好的社区支持,文档清晰,适合快速查找解决方案。

  • remark:

    remark 的社区逐渐壮大,提供了许多插件和扩展,支持不断增加。

  • showdown:

    showdown 的社区相对较小,但仍然提供基本的支持和文档。

功能丰富性

  • markdown-it:

    markdown-it 提供了丰富的功能,包括自定义渲染、插件支持和多种 Markdown 语法的支持,适合复杂需求。

  • marked:

    marked 功能相对简单,主要专注于 Markdown 到 HTML 的转换,适合基本需求。

  • remark:

    remark 提供了强大的功能,支持多种 Markdown 解析和转换,适合需要复杂处理的项目。

  • showdown:

    showdown 提供基本的 Markdown 转换功能,适合简单的使用场景,不适合复杂需求。

如何选择: markdown-it vs marked vs remark vs showdown

  • markdown-it:

    选择 markdown-it 如果你需要一个高效且可扩展的 Markdown 解析器,支持插件和自定义功能,适合需要高度自定义的项目。

  • marked:

    选择 marked 如果你需要一个简单、快速的解析器,适合快速转换 Markdown 文本,且对性能有较高要求。

  • remark:

    选择 remark 如果你需要一个基于插件的 Markdown 处理工具,适合需要进行复杂转换和分析的项目,支持 AST(抽象语法树)操作。

  • showdown:

    选择 showdown 如果你需要一个轻量级且易于使用的 Markdown 转换库,适合简单的项目或快速原型开发。

markdown-it的README

markdown-it

CI NPM version Coverage Status Gitter

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:

npm install markdown-it

browser (CDN):

Usage examples

See also:

Simple

// node.js
// can use `require('markdown-it')` for CJS
import markdownit from 'markdown-it'
const md = markdownit()
const result = md.render('# markdown-it rulezz!');

// browser with UMD build, added to "window" on script load
// Note, there is no dash in "markdownit".
const md = window.markdownit();
const result = md.render('# markdown-it rulezz!');

Single line rendering, without paragraph wrap:

import markdownit from 'markdown-it'
const md = markdownit()
const 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). See API docs for more details.

import markdownit from 'markdown-it'

// commonmark mode
const md = markdownit('commonmark')

// default mode
const md = markdownit()

// enable everything
const md = markdownit({
  html: true,
  linkify: true,
  typographer: true
})

// full options list (defaults)
const md = markdownit({
  // Enable HTML tags in source
  html:         false,

  // Use '/' to close single tags (<br />).
  // This is only for full CommonMark compatibility.
  xhtmlOut:     false,

  // Convert '\n' in paragraphs into <br>
  breaks:       false,

  // CSS language prefix for fenced blocks. Can be
  // useful for external highlighters.
  langPrefix:   'language-',

  // Autoconvert URL-like text to links
  linkify:      false,

  // Enable some language-neutral replacement + quotes beautification
  // For the full list of replacements, see https://github.com/markdown-it/markdown-it/blob/master/lib/rules_core/replacements.mjs
  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 (/*str, lang*/) { return ''; }
});

Plugins load

import markdownit from 'markdown-it'

const md = markdownit
  .use(plugin1)
  .use(plugin2, opts, ...)
  .use(plugin3);

Syntax highlighting

Apply syntax highlighting to fenced code blocks with the highlight option:

import markdownit from 'markdown-it'
import hljs from 'highlight.js' // https://highlightjs.org

// Actual default values
const md = markdownit({
  highlight: function (str, lang) {
    if (lang && hljs.getLanguage(lang)) {
      try {
        return hljs.highlight(str, { language: lang }).value;
      } catch (__) {}
    }

    return ''; // use external default escaping
  }
});

Or with full wrapper override (if you need assign class to <pre> or <code>):

import markdownit from 'markdown-it'
import hljs from 'highlight.js' // https://highlightjs.org

// Actual default values
const md = markdownit({
  highlight: function (str, lang) {
    if (lang && hljs.getLanguage(lang)) {
      try {
        return '<pre><code class="hljs">' +
               hljs.highlight(str, { language: lang, ignoreIllegals: true }).value +
               '</code></pre>';
      } catch (__) {}
    }

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

Linkify

linkify: true uses linkify-it. To configure linkify-it, access the linkify instance through md.linkify:

md.linkify.set({ fuzzyEmail: false });  // disables converting email to link

API

API documentation

If you are going to write plugins, please take a look at Development info.

Syntax extensions

Embedded (enabled by default):

Via plugins:

Manage rules

By default all rules are enabled, but can be restricted by options. On plugin load all its rules are enabled automatically.

import markdownit from 'markdown-it'

// Activate/deactivate rules, with currying
const md = markdownit()
  .disable(['link', 'image'])
  .enable(['link'])
  .enable('image');

// Enable everything
const md = markdownit({
  html: true,
  linkify: true,
  typographer: true,
});

You can find all rules in sources:

Benchmark

Here is the result of readme parse at MB Pro Retina 2013 (2.4 GHz):

npm run benchmark-deps
benchmark/benchmark.mjs readme

Selected samples: (1 of 28)
 > README

Sample: README.md (7774 bytes)
 > commonmark-reference x 1,222 ops/sec ±0.96% (97 runs sampled)
 > current x 743 ops/sec ±0.84% (97 runs sampled)
 > current-commonmark x 1,568 ops/sec ±0.84% (98 runs sampled)
 > 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.

markdown-it for enterprise

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.

Authors

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.

References / Thanks

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