Skip to main content

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

Project description

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.

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-4.1.0.tar.gz (81.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

markdown_it_py-4.1.0-py3-none-any.whl (91.0 kB view details)

Uploaded Python 3

File details

Details for the file markdown_it_py-4.1.0.tar.gz.

File metadata

  • Download URL: markdown_it_py-4.1.0.tar.gz
  • Upload date:
  • Size: 81.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.33.1

File hashes

Hashes for markdown_it_py-4.1.0.tar.gz
Algorithm Hash digest
SHA256 760e3f87b2787c044c5138a5ba107b7c2be26c03b13cc7f8fe42756b65b1df6c
MD5 42c5be8d8e882488c5c7fa6855ead8b6
BLAKE2b-256 5c5cf3aedc83549aae71cd52b9e9687fe896e3dc6e966ba20eba04718605d198

See more details on using hashes here.

File details

Details for the file markdown_it_py-4.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for markdown_it_py-4.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d4939a62a2dd0cd9cb80a191a711ba1d39bac8ed5ef9e9966895b0171c01c46d
MD5 d423d5e4fa318d5a35e26c6a70ca7bda
BLAKE2b-256 a888802c82060c54bc7dde21eb0033e337838b8181a1323254aa9ec41cbfc3d1

See more details on using hashes here.

Supported by

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