Project markdown-it

Expand description

markdown-it

CI NPM version Coverage Status

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.
Note

If you are upgrading to v15, see the migration guide.

npm install markdown-it

For a quick look at dist/ folder contents, see https://unpkg.com/markdown-it/. For browser you can use unpkg.com, esm.sh or any other CDN, which mirror npm registry.

import MarkdownIt from 'markdown-it'
const md = new MarkdownIt()
const result = md.render('# markdown-it rulezz!')

More usage examples.

Main§

Usage examples
Syntax plugins
Safety
default

Default package export.

MarkdownIt

Parses Markdown into tokens and renders them to HTML.

MarkdownItOptions

Options controlling Markdown parsing and rendering.

Documents§

Architecture
Development
Benchmark
Authors
References

Plugin API§

md.utils

Common utility functions exposed through md.utils for use by plugins.

md.helpers

Functions used to parse links and images, split out of parser rules because of their size.

MarkdownItPreset

Parser preset containing options and enabled rules for each parser component.

ParserBlock

Block-level tokenizer.

ParserCore

Top-level rules executor. Glues block/inline parsers and does intermediate transformations.

ParserInline

Tokenizes paragraph content.

RendererRule

Function that renders a token at a given position in a token stream.

Renderer

Generates HTML from parsed token stream. Each instance has independent copy of rules. Those can be rewritten with ease. Also, you can add new rules if you create plugin and adds new token types.

Ruler

Helper class, used by MarkdownIt.core, MarkdownIt.block and MarkdownIt.inline to manage sequences of functions (rules):

StateBlock

Mutable state passed to block rules while tokenizing a source document.

StateCore

Mutable state passed through the core rules chain.

StateInline

Mutable state passed to inline rules while tokenizing inline content.

Token

Represents one item in the parsed token stream, storing parsed data and providing helpers for managing HTML attributes.

Env

Shared environment passed through parsing and rendering.

Delimiter

Delimiter entry used by emphasis-like inline rules.