Skip to main content

Markdown HTML converters for Python made in Rust

Project description

Markdown HTML converters for Python made in Rust

Exposes two Rust crates which parse markdown to Python using PyO3.

Using Comrak

The first crate exposed is comrak from which we inherited the name:

Example:

  >>> from python_comrak import markdown_to_html
  >>> markdown_to_html("\tfoo\tbaz\t\tbim\n")
  "<pre><code>foo\tbaz\t\tbim\n</code></pre>\n"

markdown_to_html activates the extensions:

Using pulldown-cmark

The second crate is pulldown-cmark. Example:

  >>> from python_comrak import commonmark_to_html
  >>> commonmark_to_html("\tfoo\tbaz\t\tbim\n")
  "<pre><code>foo\tbaz\t\tbim\n</code></pre>\n"

commonmark_to_html activates the extensions:

Notice that pulldown-cmark doesn't implement 100% of CommonMark yet. Also it doesn't have the same set of extensions we use with comrak.

Benchmarks

This implementation is quite simple and doesn't allow much of the underlying crates. The extensions and options are fixed. The following is just a micro-benchmark parsing the text of this README file:

>>> with open('README.md', 'r') as f:
...     contents = f.read()

>>> from python_comrak import markdown_to_html, commonmark_to_html

>>> %timeit markdown_to_html(contents)
54.4 µs ± 1.24 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)

>>> %timeit commonmark_to_html(contents)
12.5 µs ± 97.3 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

python_comrak-0.3.2-cp38-cp38-manylinux2010_x86_64.whl (1.5 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

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