view env/lib/python3.9/site-packages/mistune-0.8.4.dist-info/METADATA @ 0:4f3585e2f14b draft default tip

"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
author shellac
date Mon, 22 Mar 2021 18:12:50 +0000
line wrap: on
line source

Metadata-Version: 2.0
Name: mistune
Version: 0.8.4
Summary: The fastest markdown parser in pure Python
Author: Hsiaoming Yang
License: BSD
Platform: any
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Web Environment
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: BSD License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 2
Classifier: Programming Language :: Python :: 2.7
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.5
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: Implementation :: PyPy
Classifier: Topic :: Text Processing :: Markup
Classifier: Topic :: Software Development :: Libraries :: Python Modules


The fastest markdown parser in pure Python with renderer features,
inspired by marked_.

.. image::
   :alt: Donate lepture
.. image::
   :alt: Wheel Status
.. image::
   :alt: Conda Version
.. image::
   :alt: Latest Version
.. image::
   :alt: Travis CI Status
.. image::
   :alt: Coverage Status
.. image::
   :alt: App Veyor CI Status

.. _marked:


* **Pure Python**. Tested in Python 2.7, Python 3.5+ 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 <>`_.


Installing mistune with pip::

    $ pip install mistune

Mistune can be faster, if you compile with cython::

    $ pip install cython mistune

Basic Usage

A simple API that render a markdown formatted text:

.. code:: python

    import mistune

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

If you care about performance, it is better to re-use the Markdown instance:

.. code:: python

    import mistune

    markdown = mistune.Markdown()
    markdown('I am using **mistune markdown parser**')

Mistune has enabled all features by default. You don't have to configure
anything. But there are options for you to change the parser behaviors.


Here is a list of all options that will affect the rendering results,
configure them with ``mistune.Renderer``:

.. code:: python

    renderer = mistune.Renderer(escape=True, hard_wrap=True)
    # use this renderer instance
    markdown = mistune.Markdown(renderer=renderer)

* **escape**: if set to *False*, all raw html tags will not be escaped.
* **hard_wrap**: if set to *True*, it will has GFM line breaks feature.
  All new lines will be replaced with ``<br>`` tag
* **use_xhtml**: if set to *True*, all tags will be in xhtml, for example: ``<hr />``.
* **parse_block_html**: parse text only in block level html.
* **parse_inline_html**: parse text only in inline level html.

When using the default renderer, you can use one of the following shortcuts::

    mistune.markdown(text, escape=True, hard_wrap=True)

    markdown = mistune.Markdown(escape=True, hard_wrap=True)


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:

.. code:: python

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

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

    renderer = HighlightRenderer()
    markdown = mistune.Markdown(renderer=renderer)
    print(markdown('```python\nassert 1 == 1\n```'))

Find more renderers in `mistune-contrib`_.

Block Level

Here is a list of block level renderer API::

    block_code(code, language=None)
    header(text, level, raw=None)
    list(body, ordered=True)
    table(header, body)
    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)
    image(src, title, alt_text)
    link(link, title, content)


Here is a list of renderers related to footnotes::

    footnote_ref(key, index)
    footnote_item(key, text)


Sometimes you want to add your own rules to Markdown, such as GitHub Wiki
links. You can't achieve this goal with renderers. You will need to deal
with the lexers, it would be a little difficult for the first time.

We will take an example for GitHub Wiki links: ``[[Page 2|Page 2]]``.
It is an inline grammar, which requires custom ``InlineGrammar`` and

.. code:: python

    import copy,re
    from mistune import Renderer, InlineGrammar, InlineLexer

    class WikiLinkRenderer(Renderer):
        def wiki_link(self, alt, link):
            return '<a href="%s">%s</a>' % (link, alt)

    class WikiLinkInlineLexer(InlineLexer):
        def enable_wiki_link(self):
            # add wiki_link rules
            self.rules.wiki_link = re.compile(
                r'\[\['                   # [[
                r'([\s\S]+?\|[\s\S]+?)'   # Page 2|Page 2
                r'\]\](?!\])'             # ]]

            # Add wiki_link parser to default rules
            # you can insert it some place you like
            # but place matters, maybe 3 is not good
            self.default_rules.insert(3, 'wiki_link')

        def output_wiki_link(self, m):
            text =
            alt, link = text.split('|')
            # you can create an custom render
            # you can also return the html if you like
            return self.renderer.wiki_link(alt, link)

You should pass the inline lexer to ``Markdown`` parser:

.. code:: python

    renderer = WikiLinkRenderer()
    inline = WikiLinkInlineLexer(renderer)
    # enable the feature
    markdown = Markdown(renderer, inline=inline)
    markdown('[[Link Text|Wiki Link]]')

It is the same with block level lexer. It would take a while to understand
the whole mechanism. But you won't do the trick a lot.

Contribution & Extensions

Mistune itself doesn't accept any extension. It will always be a simple one
file script.

If you want to add features, you can head over to `mistune-contrib`_.

Here are some extensions already in `mistune-contrib`_:

* Math/MathJax features
* Highlight Code Renderer
* TOC table of content features
* MultiMarkdown Metadata parser

Get inspired with the contrib repository.

.. _`mistune-contrib`: