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

Markdown 解析库

Markdown 解析库用于将 Markdown 格式的文本转换为 HTML。这些库为开发者提供了灵活和高效的方式来处理 Markdown 内容,适用于博客、文档和其他需要文本格式化的应用程序。选择合适的 Markdown 解析库可以显著影响开发效率、可维护性和最终用户体验。

npm下载趋势

3 年

GitHub Stars 排名

统计详情

npm包名称
下载量
Stars
大小
Issues
发布时间
License
markdown-it20,527,67021,131768 kB581 个月前MIT
remarkable1,340,0075,824-1326 年前MIT
marked036,645444 kB127 天前MIT
showdown014,837801 kB233-MIT

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

性能

  • markdown-it:

    markdown-it 以性能为重点,能够快速解析大文本量的 Markdown 内容。它通过优化算法和数据结构,确保在处理复杂文档时保持高效。

  • remarkable:

    remarkable 提供了良好的性能,适合需要快速解析的场景。虽然它不如 marked 快,但在功能和性能之间取得了很好的平衡。

  • marked:

    marked 是一个专注于速度的库,经过优化以实现快速解析。它的设计使得在处理大量 Markdown 文本时,性能表现优异。

  • showdown:

    showdown 的性能相对较好,适合小型项目和简单的 Markdown 解析需求。对于大规模文档,可能会遇到性能瓶颈。

可扩展性

  • markdown-it:

    markdown-it 提供了丰富的插件系统,允许开发者轻松扩展其功能。你可以添加自定义规则和渲染器,以满足特定需求。

  • remarkable:

    remarkable 支持自定义规则和扩展,允许开发者根据需求进行调整,适合需要灵活性的项目。

  • marked:

    marked 的可扩展性有限,主要专注于核心功能,不支持插件机制。适合不需要额外功能的简单项目。

  • showdown:

    showdown 允许基本的扩展,但不如 markdown-it 灵活。适合需要简单自定义的场景。

易用性

  • markdown-it:

    markdown-it 的 API 设计优雅,文档清晰,易于上手。适合希望快速集成 Markdown 功能的开发者。

  • remarkable:

    remarkable 提供了直观的 API,易于理解和使用,适合需要快速实现 Markdown 解析的项目。

  • marked:

    marked 的 API 简单明了,易于使用,适合初学者和快速开发。

  • showdown:

    showdown 的使用非常简单,适合快速集成和小型项目,文档也相对友好。

社区支持

  • markdown-it:

    markdown-it 拥有活跃的社区和丰富的插件生态系统,开发者可以轻松找到支持和资源。

  • remarkable:

    remarkable 的社区相对较小,但仍然提供了一定的支持和文档。

  • marked:

    marked 作为一个流行的库,拥有良好的社区支持和文档,开发者可以轻松获取帮助。

  • showdown:

    showdown 也有一定的社区支持,文档清晰,但相比其他库,社区活跃度较低。

功能完整性

  • markdown-it:

    markdown-it 提供了全面的 Markdown 解析功能,支持各种扩展语法,适合需要完整功能的项目。

  • remarkable:

    remarkable 提供了良好的功能集,支持大部分常见的 Markdown 语法,适合一般需求。

  • marked:

    marked 提供基本的 Markdown 解析功能,适合简单需求,不支持复杂的扩展语法。

  • showdown:

    showdown 提供基本的 Markdown 解析功能,适合简单的文本处理需求,但不支持所有扩展语法。

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

  • markdown-it:

    选择 markdown-it 如果你需要一个高度可扩展的解析器,支持插件和自定义规则,且希望在性能和功能之间取得良好平衡。它的 API 设计优雅,适合需要复杂 Markdown 解析的项目。

  • remarkable:

    选择 remarkable 如果你需要一个轻量级的解析器,且希望在速度和功能之间取得良好平衡。它支持自定义规则和扩展,适合需要灵活性的项目。

  • marked:

    选择 marked 如果你需要一个简单、快速的解析器,且不需要太多的自定义功能。它的设计目标是速度,适合对性能要求高的项目。

  • showdown:

    选择 showdown 如果你需要一个易于使用的库,且希望在浏览器和 Node.js 环境中都能运行。它的 API 简单明了,适合快速集成和小型项目。

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