Skip to main content

Yet another markdown parser, inspired by marked in JavaScript.

https://travis-ci.org/lepture/mistune.png?branch=master https://coveralls.io/repos/lepture/mistune/badge.png?branch=master Downloads Version

Features

  • Pure Python. Tested in Python 2.6+, Python 3.3+ and PyPy.

  • Very Fast. It is the fastest in all pure Python markdown parsers.

  • More Features. Table, footnotes, autolink, fenced code etc.

View the benchmark results.

Installation

Installing mistune with pip:

$ pip install mistune

If pip is not available, try easy_install:

$ easy_install mistune

Cython Feature

Mistune can be faster, if you compile with cython:

$ pip install cython mistune

Basic Usage

A simple API that render a markdown formatted text:

import mistune

mistune.markdown('I am using **markdown**')
# output: <p>I am using <strong>markdown</strong></p>

Mistune has all features by default. You don’t have to configure anything.

Renderer

Like misaka/sundown, you can influence the rendering by custom renderers. All you need to do is subclassing a Renderer class.

Here is an example of code highlighting:

import mistune
from pygments import highlight
from pygments.lexers import get_lexer_by_name
from pygments.formatters import HtmlFormatter

class MyRenderer(mistune.Renderer):
    def block_code(self, code, lang):
        if not lang:
            return '\n<pre><code>%s</code></pre>\n' % \
                mistune.escape(code)
        lexer = get_lexer_by_name(lang, stripall=True)
        formatter = HtmlFormatter()
        return highlight(code, lexer, formatter)

renderer = MyRenderer()
md = mistune.Markdown(renderer=renderer)
print(md.render('Some Markdown text.'))

Block Level

Here is a list of block level renderer API:

block_code(code, language=None)
block_quote(text)
block_html(html)
header(text, level, raw=None)
hrule()
list(body, ordered=True)
list_item(text)
paragraph(text)
table(header, body)
table_row(content)
table_cell(content, **flags)

The flags tells you whether it is header with flags['header']. And it also tells you the align with flags['align'].

Span Level

Here is a list of span level renderer API:

autolink(link, is_email=False)
codespan(text)
double_emphasis(text)
emphasis(text)
image(src, title, alt_text)
linebreak()
link(link, title, content)
raw_html(raw_html)
strikethrough(text)

Options

Here is a list of all options that will affect the rendering results:

mistune.markdown(text, escape=True)

md = mistune.Markdown(escape=True)
md.render(text)
  • escape: if set to True, all raw html tags will be escaped.

  • use_xhtml: if set to True, all tags will be in xhtml, for example: <hr />.

Release files for mistune 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mistune 0.1.0
File Size Uploaded
mistune-0.1.0.tar.gz 12.1 kB Details

Release files / mistune-0.1.0.tar.gz

Download URL mistune-0.1.0.tar.gz
Size 12.1 kB
Tags Source
SHA-256 checksum
How to use checksums
a8817d660daa7de2a51b4a1a1c4b7d74675715eb5321ea453387d86bb13805eb
BLAKE2b-256 checksum
How to use checksums
14a0ffbfbc3de7c94340ac5e379da711e4b600917eae5ad595fdce7dfcab4092
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

3.3.4

2 release files

3.3.3

2 release files

3.3.2

2 release files

3.3.1

2 release files

3.3.0

2 release files

3.2.1

2 release files

3.2.0

2 release files

3.1.4

2 release files

3.1.3

2 release files

3.1.2

2 release files

3.1.1

2 release files

3.1.0

2 release files

3.0.2

2 release files

3.0.1

2 release files

3.0.0

2 release files

2.1.0

2 release files

2.0.5

2 release files

2.0.4

2 release files

2.0.3

2 release files

2.0.2

2 release files

2.0.1

2 release files

2.0.0

2 release files

0.8.4

2 release files

0.8.3

2 release files

0.8.2

2 release files

0.8.1

2 release files

0.8

2 release files

0.7.4

4 release files

0.7.3

2 release files

0.7.2

2 release files

0.7.1

5 release files

0.7

5 release files

0.6

5 release files

0.5.1

5 release files

0.5

5 release files

0.4.1

5 release files

0.4

5 release files

0.3.1

1 release file

0.3.0

1 release file

0.2.0

1 release file

This release

0.1.0 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page