Scripts2026年5月19日·1 分钟阅读

markdown-it — Fast Pluggable Markdown Parser for JavaScript

A CommonMark-compliant markdown parser with a rich plugin ecosystem, GFM support, and configurable syntax extensions for both Node.js and browsers.

Agent 就绪

这个资产可以被 Agent 直接读取和安装

TokRepo 同时提供通用 CLI 命令、安装契约、metadata JSON、按适配器生成的安装计划和原始内容链接,方便 Agent 判断适配度、风险和下一步动作。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
Quick Use
通用 CLI 安装命令
npx tokrepo install 0c32f40e-535c-11f1-9bc6-00163e2b0d79

Introduction

markdown-it is a fast, spec-compliant markdown parser for JavaScript. It follows the CommonMark specification and adds GFM (GitHub Flavored Markdown) extensions through plugins. The library runs in Node.js and browsers, making it suitable for both server-side rendering and client-side previews.

What markdown-it Does

  • Parses markdown text into HTML following the CommonMark spec
  • Supports tables, strikethrough, and other GFM extensions via plugins
  • Provides a plugin API for adding custom syntax rules
  • Generates an AST (token stream) for programmatic manipulation
  • Handles typographic replacements and smart quotes

Architecture Overview

markdown-it uses a two-stage pipeline: the parser tokenizes markdown input into a flat token stream, and the renderer converts tokens into HTML output. The parser is split into block-level and inline-level rule chains. Plugins can inject rules at any point in either chain, making it possible to add custom block elements or inline syntax without modifying the core.

Self-Hosting & Configuration

  • Install via npm: npm install markdown-it
  • Enable presets: markdownit('commonmark') for strict CommonMark
  • Add GFM features: markdownit().enable(['table', 'strikethrough'])
  • Use plugins: md.use(require('markdown-it-footnote'))
  • Configure options: html, linkify, typographer, breaks

Key Features

  • Full CommonMark compliance with the official test suite
  • Plugin ecosystem: footnotes, containers, task lists, anchors, math
  • Linkify support for auto-detecting URLs
  • Configurable security: HTML tag filtering, link validation
  • Fast performance suitable for real-time preview rendering

Comparison with Similar Tools

  • Marked — simpler API but fewer plugin options
  • Remark (unified) — AST-based ecosystem, more powerful transforms but heavier
  • Showdown — older library, less actively maintained
  • CommonMark.js — reference implementation, strict but no plugin system
  • Micromark — low-level parser used by remark, not meant for direct use

FAQ

Q: How do I enable GitHub-style tables? A: Tables are enabled by default in the default preset. For commonmark preset, call md.enable('table').

Q: Is HTML pass-through safe? A: Set html: false (the default) to strip raw HTML. For user-generated content, also use a sanitizer like DOMPurify on the output.

Q: Can I render to something other than HTML? A: Yes, you can write a custom renderer that processes the token stream into any output format.

Q: How does performance compare to other parsers? A: markdown-it is among the fastest JS parsers, suitable for real-time keystroke-level rendering in editors.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产