Skip to main content

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

Project description

markdown-it-py

Github-DI Coverage Status PyPI Conda Code style: black

Markdown parser done right. Fast and easy to extend.

  • 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.
  • Pluginable

This is a Python port of markdown-it, and some of its associated plugins. It is still under development, so for now should be used with caution.

For details on markdown-it itself, see:

Table of content

The Port

Details of the port can be found in markdown_it/port.yaml and in port.yaml within the extension folders. But the driving design philosophy has been to change as little of the fundamental code structure (file names, function name, etc) as possible, just sprinkling in a little Python syntactic sugar. It is very simple to write complimentary extensions for both language implementations!

Install

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

or

pip install markdown-it-py

Basic usage

See also:

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

md = (
    MarkdownIt()
    .use(front_matter_plugin)
    .use(footnote_plugin)
    .disable('image')
    .enable('table')
)
text = ("""
---
a: 1
---

a | b
- | -
1 | 2

A footnote [^1]

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

Also you can use it from the command-line:

$ markdown-it
markdown-it-py [version 0.1.0] (interactive)
Type Ctrl-D to complete input, or Ctrl-C to exit.
>>> > **hallo** there!
...
<blockquote>
<p><strong>hallo</strong> there!</p>
</blockquote>

Benchmarking

markdown-it-py is the fastest CommonMark compliant parser written in python!

$ markdown-it-bench -n 30
Test document: spec.md
Test iterations: 30
Running 7 test(s) ...
=====================
[mistune         (0.8.4): 3.62 s]*
markdown-it-py   (0.1.0): 9.03 s
mistletoe        (0.10.0): 9.89 s
commonmark-py    (0.9.1): 20.82 s
pymarkdown       (3.2.1): 34.50 s
pymarkdown:extra (3.2.1): 41.86 s
panflute         (1.12.5): 35.02 s

As you can see, markdown-it-py doesn't pay with speed for it's flexibility.

*Note mistune is not CommonMark compliant, which is what allows for its faster parsing, at the expense of issues, for example, with nested inline parsing. See mistletoes's explanation for further details.

Syntax extensions

Embedded (enabled when using the "default" preset configuration):

Via plugins:

A list of plugins that have/can be ported:

Authors

References / Thanks

Big thanks to the authors of markdown-it

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

Related Links

Other Ports

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

markdown-it-py-0.4.5.tar.gz (117.9 kB view details)

Uploaded Source

Built Distribution

markdown_it_py-0.4.5-py2-none-any.whl (105.7 kB view details)

Uploaded Python 2

File details

Details for the file markdown-it-py-0.4.5.tar.gz.

File metadata

  • Download URL: markdown-it-py-0.4.5.tar.gz
  • Upload date:
  • Size: 117.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.7.7

File hashes

Hashes for markdown-it-py-0.4.5.tar.gz
Algorithm Hash digest
SHA256 62d6cc6d648e957f89c663923180821fd8c36fd044e8aa21f85af6908d0171c4
MD5 27bea16f3c6f3eb487b78ee4b3d35d97
BLAKE2b-256 dae58fafd6d40b669230affb2f9849b6e0b9c7b0e609b67e01847d9944fa463a

See more details on using hashes here.

File details

Details for the file markdown_it_py-0.4.5-py2-none-any.whl.

File metadata

  • Download URL: markdown_it_py-0.4.5-py2-none-any.whl
  • Upload date:
  • Size: 105.7 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.7.7

File hashes

Hashes for markdown_it_py-0.4.5-py2-none-any.whl
Algorithm Hash digest
SHA256 81094db2cdc2427f8923ad9d6fcf175c3dee9e04c029a7108fe9b73c8da4bc21
MD5 19188923f5278d5e4b5e65f038f92f90
BLAKE2b-256 255fd9965f7cfb2d936e366ee6e40f1589892384ab071034225b179bcf5ec38d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page