markdown-it-py

Python port of markdown-it. Markdown parsing, done right!

45 个版本 Python >=3.10
安装
pip install markdown-it-py
poetry add markdown-it-py
pipenv install markdown-it-py
conda install markdown-it-py
描述

markdown-it-py

Github-CI Coverage Status PyPI Conda PyPI - Downloads

markdown-it-py icon

Markdown parser done right.

This is a Python port of markdown-it, and some of its associated plugins. For more details see: https://markdown-it-py.readthedocs.io.

For details on markdown-it itself, see:

See also: markdown-it-pyrs for an experimental Rust binding, for even more speed!

Installation

PIP

pip install markdown-it-py[plugins]

or with extras

pip install markdown-it-py[linkify,plugins]

Conda

conda install -c conda-forge markdown-it-py

or with extras

conda install -c conda-forge markdown-it-py linkify-it-py mdit-py-plugins

Usage

Python API Usage

Render markdown to HTML with markdown-it-py and a custom configuration with and without plugins and features:

from markdown_it import MarkdownIt
from mdit_py_plugins.front_matter import front_matter_plugin
from mdit_py_plugins.footnote import footnote_plugin

md = (
    MarkdownIt('commonmark', {'breaks':True,'html':True})
    .use(front_matter_plugin)
    .use(footnote_plugin)
    .enable('table')
)
text = ("""
---
a: 1
---

a | b
- | -
1 | 2

A footnote [^1]

[^1]: some details
""")
tokens = md.parse(text)
html_text = md.render(text)

## To export the html to a file, uncomment the lines below:
# from pathlib import Path
# Path("output.html").write_text(html_text)

Command-line Usage

Render markdown to HTML with markdown-it-py from the command-line:

usage: markdown-it [-h] [-v] [--stdin|filenames [filenames ...]]

Parse one or more markdown files, convert each to HTML, and print to stdout

positional arguments:
  --stdin        read source Markdown file from standard input
  filenames      specify an optional list of files to convert

optional arguments:
  -h, --help     show this help message and exit
  -v, --version  show program's version number and exit

Interactive:

  $ markdown-it
  markdown-it-py [version 0.0.0] (interactive)
  Type Ctrl-D to complete input, or Ctrl-C to exit.
  >>> # Example
  ... > markdown *input*
  ...
  <h1>Example</h1>
  <blockquote>
  <p>markdown <em>input</em></p>
  </blockquote>

Batch:

  $ markdown-it README.md README.footer.md > index.html

References / Thanks

Big thanks to the authors of markdown-it:

Also John MacFarlane for his work on the CommonMark spec and reference implementations.

版本列表
4.2.0 2026-05-07
4.1.0 2026-05-06
4.0.0 2025-08-11
3.0.0 2023-06-03
2.2.0 2023-02-22
2.1.0 2022-04-16
2.0.1 2022-01-24
2.0.0 2021-12-03
1.1.0 2021-05-08
1.0.0 2021-05-02
1.0.0b3 2021-05-01
1.0.0b2 2021-04-25
1.0.0b1 2021-03-31
0.6.2 2021-02-06
0.6.1 2021-01-01
0.6.0 2020-12-15
0.5.8 2020-12-13
0.5.7 2020-12-13
0.5.6 2020-10-21
0.5.5 2020-09-27
0.5.4 2020-09-08
0.5.3 2020-09-04
0.5.2 2020-08-22
0.5.1 2020-08-21
0.5.0 2020-08-18
0.4.9 2020-08-11
0.4.8 2020-07-13
0.4.7 2020-06-22
0.4.6 2020-05-28
0.4.5 2020-04-01
0.4.4 2020-03-30
0.4.3 2020-03-29
0.4.2 2020-03-29
0.4.1 2020-03-28
0.4.0 2020-03-28
0.3.3 2020-03-28
0.3.2 2020-03-27
0.3.1 2020-03-27
0.3.0 2020-03-27
0.2.3 2020-03-27
0.2.2 2020-03-26
0.2.1 2020-03-26
0.2.0 2020-03-26
0.1.1 2020-03-25
0.1.0 2020-03-25