Skip to main content

Extended Python bindings for the Comrak Rust library, a fast CommonMark/GFM parser

Reason this release was yanked:

Release script built only Python 3.11 wheels

Project description

comrak-ext

uv pdm-managed PyPI Supported Python versions License pre-commit.ci status

Extended Python bindings for the comrak Rust crate, a fast CommonMark/GFM parser. Fork of lmmx/comrak.

Installation

pip install comrak-ext

Requirements

  • Python 3.11+

Features

Fast Markdown parser implemented in Rust, shipped for Python via PyO3.

API

Parsing

parse_document

Parse Markdown into an abstract syntax tree (AST):

from comrak import ExtensionOptions, Document, Text, Paragraph, parse_document

extension_options = ExtensionOptions(front_matter_delimiter = "---")

md_content = """---
This is a text in FrontMatter
---

Hello, Markdown!
"""

x = parse_document(md_content, extension_options)
assert isinstance(x.node_value, Document)
assert not hasattr(x.node_value, "value")
assert len(x.children) == 2

assert isinstance(x.children[0].node_value, FrontMatter)
assert isinstance(x.children[0].node_value.value, str)
assert x.children[0].node_value.value.strip() == "---\nThis is a text in FrontMatter\n---"

assert isinstance(x.children[1].node_value, Paragraph)
assert len(x.children[1].children) == 1
assert isinstance(x.children[1].children[0].node_value, Text)
assert isinstance(x.children[1].children[0].node_value.value, str)
assert x.children[1].children[0].node_value.value == "Hello, Markdown!"

Rendering

markdown_to_commonmark

Render Markdown to CommonMark:

from comrak import RenderOptions, ListStyleType, markdown_to_commonmark

render_options = RenderOptions()
markdown_to_commonmark("- one\n- two\n- three", render_options=render_options)

# '- one\n- two\n- three\n' – default is Dash
render_options.list_style = ListStyleType.Plus
markdown_to_commonmark("- one\n- two\n- three", render_options=render_options)
# '+ one\n+ two\n+ three\n'

markdown_to_html

Render Markdown to HTML:

from comrak import ExtensionOptions, markdown_to_html
extension_options = ExtensionOptions()
markdown_to_html("foo :smile:", extension_options)
# '<p>foo :smile:</p>\n'

extension_options.shortcodes = True
markdown_to_html("foo :smile:", extension_options)
# '<p>foo 😄</p>\n'

markdown_to_xml

Render Markdown to XML:

from comrak import RenderOptions, markdown_to_xml

render_options = RenderOptions(sourcepos=True)
markdown_to_xml("Hello, **Markdown**!", render_options=render_options)
# '<?xml version="1.0" encoding="UTF-8"?>\n<!DOCTYPE document SYSTEM "CommonMark.dtd">\n<document sourcepos="1:1-1:20" xmlns="http://commonmark.org/xml/1.0">\n  <paragraph sourcepos="1:1-1:20">\n    <text sourcepos="1:1-1:7" xml:space="preserve">Hello, </text>\n    <strong sourcepos="1:8-1:19">\n      <text sourcepos="1:10-1:17" xml:space="preserve">Markdown</text>\n    </strong>\n    <text sourcepos="1:20-1:20" xml:space="preserve">!</text>\n  </paragraph>\n</document>\n'

Formatting AST

format_commonmark

Format an AST back to CommonMark:

from comrak import parse_document, format_commonmark

p = parse_document("> Greentext blockquote requires a space after `>`")

format_commonmark(p)
# '> Greentext blockquote requires a space after `>`\n'

format_html

Format an AST back to HTML:

from comrak import parse_document, format_html

p = parse_document("> Greentext blockquote requires a space after `>`")

format_html(p)
# '<blockquote>\n<p>Greentext blockquote requires a space after <code>&gt;</code></p>\n</blockquote>\n'

format_xml

Format an AST back to XML:

from comrak import parse_document, format_xml

p = parse_document("> Greentext blockquote requires a space after `>`")

format_xml(p)
# '<?xml version="1.0" encoding="UTF-8"?>\n<!DOCTYPE document SYSTEM "CommonMark.dtd">\n<document xmlns="http://commonmark.org/xml/1.0">\n  <block_quote>\n    <paragraph>\n      <text xml:space="preserve">Greentext blockquote requires a space after </text>\n      <code xml:space="preserve">&gt;</code>\n    </paragraph>\n  </block_quote>\n</document>\n'

Options

All options are exposed in a simple manner and can be used with all functions.

Refer to the Comrak docs for all available options.

Benchmarks

Tested with small (8 lines) and medium (1200 lines) markdown strings

Contributing

Maintained by Martin005. Contributions welcome!

  1. Issues & Discussions: Please open a GitHub issue or discussion for bugs, feature requests, or questions.
  2. Pull Requests: PRs are welcome!
    • Install the dev extra (e.g. with uv: uv pip install -e .[dev])
    • Run tests (when available) and include updates to docs or examples if relevant.
    • If reporting a bug, please include the version and the error message/traceback if available.

License

Licensed under the 2-Clause BSD License. See LICENSE for all the details.

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

comrak_ext-0.2.0.tar.gz (54.2 kB view details)

Uploaded Source

Built Distributions

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

comrak_ext-0.2.0-cp311-abi3-win_amd64.whl (567.7 kB view details)

Uploaded CPython 3.11+Windows x86-64

comrak_ext-0.2.0-cp311-abi3-win32.whl (543.2 kB view details)

Uploaded CPython 3.11+Windows x86

comrak_ext-0.2.0-cp311-abi3-musllinux_1_2_x86_64.whl (969.3 kB view details)

Uploaded CPython 3.11+musllinux: musl 1.2+ x86-64

comrak_ext-0.2.0-cp311-abi3-musllinux_1_2_i686.whl (929.6 kB view details)

Uploaded CPython 3.11+musllinux: musl 1.2+ i686

comrak_ext-0.2.0-cp311-abi3-musllinux_1_2_armv7l.whl (951.2 kB view details)

Uploaded CPython 3.11+musllinux: musl 1.2+ ARMv7l

comrak_ext-0.2.0-cp311-abi3-musllinux_1_2_aarch64.whl (904.3 kB view details)

Uploaded CPython 3.11+musllinux: musl 1.2+ ARM64

comrak_ext-0.2.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (709.4 kB view details)

Uploaded CPython 3.11+manylinux: glibc 2.17+ x86-64

comrak_ext-0.2.0-cp311-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl (848.4 kB view details)

Uploaded CPython 3.11+manylinux: glibc 2.17+ s390x

comrak_ext-0.2.0-cp311-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (794.8 kB view details)

Uploaded CPython 3.11+manylinux: glibc 2.17+ ppc64le

comrak_ext-0.2.0-cp311-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (675.1 kB view details)

Uploaded CPython 3.11+manylinux: glibc 2.17+ ARMv7l

comrak_ext-0.2.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (726.6 kB view details)

Uploaded CPython 3.11+manylinux: glibc 2.17+ ARM64

comrak_ext-0.2.0-cp311-abi3-manylinux_2_5_i686.manylinux1_i686.whl (726.1 kB view details)

Uploaded CPython 3.11+manylinux: glibc 2.5+ i686

comrak_ext-0.2.0-cp311-abi3-macosx_11_0_arm64.whl (616.1 kB view details)

Uploaded CPython 3.11+macOS 11.0+ ARM64

comrak_ext-0.2.0-cp311-abi3-macosx_10_12_x86_64.whl (639.9 kB view details)

Uploaded CPython 3.11+macOS 10.12+ x86-64

File details

Details for the file comrak_ext-0.2.0.tar.gz.

File metadata

  • Download URL: comrak_ext-0.2.0.tar.gz
  • Upload date:
  • Size: 54.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.14.1

File hashes

Hashes for comrak_ext-0.2.0.tar.gz
Algorithm Hash digest
SHA256 377f818a0832818fc2459e5866a836d281a02bc8077b3e95c3532b5b2a820a7b
MD5 df54f10c338bda78ae75039e50a43ee7
BLAKE2b-256 4dc12725f2a6788cb59d443d0a2f8d98f9fa181c0a936a62c356836fa4e387fe

See more details on using hashes here.

File details

Details for the file comrak_ext-0.2.0-cp311-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for comrak_ext-0.2.0-cp311-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 e3be3c68d67be299f45f3223358d8115f59ca590ed2904c01858b11fa9c0a83b
MD5 153f1e0292dad5c459c41524dc0979bf
BLAKE2b-256 54ff5ecef0c6825de855ee0cd868e32cc7aec596387a8a56fb7429c8f01fef9b

See more details on using hashes here.

File details

Details for the file comrak_ext-0.2.0-cp311-abi3-win32.whl.

File metadata

  • Download URL: comrak_ext-0.2.0-cp311-abi3-win32.whl
  • Upload date:
  • Size: 543.2 kB
  • Tags: CPython 3.11+, Windows x86
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: maturin/1.14.1

File hashes

Hashes for comrak_ext-0.2.0-cp311-abi3-win32.whl
Algorithm Hash digest
SHA256 5edbf5d5e26ca8520f186db449abfca7ce85f96aa2c4a24e130cb64ae002b469
MD5 e314fd921ece82bba7deab508692bf1d
BLAKE2b-256 37369fccca9ad1a6ead5b6f849a34b3e1436c8b2750b2fadb2d18d79ad1ee669

See more details on using hashes here.

File details

Details for the file comrak_ext-0.2.0-cp311-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for comrak_ext-0.2.0-cp311-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 b020333135993716314c949b287985f6c793715380dd06d9859847367319d409
MD5 84b90698f270fbfa4a2acbcc5572ea17
BLAKE2b-256 9cf300728d8ce16119388303f240575a8a0e0c8c8bc083135871b85293a1436e

See more details on using hashes here.

File details

Details for the file comrak_ext-0.2.0-cp311-abi3-musllinux_1_2_i686.whl.

File metadata

File hashes

Hashes for comrak_ext-0.2.0-cp311-abi3-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 f99825946c54ccb983476a3fc703d5faef50a7f631d72ced2b1c6841bfbd665b
MD5 784809a12fa4af456ecca9c516778409
BLAKE2b-256 1c2a0f90f9e217d1c8a1a76cdbfe87bbae945563b64cdb1d7c00733ced44ddc5

See more details on using hashes here.

File details

Details for the file comrak_ext-0.2.0-cp311-abi3-musllinux_1_2_armv7l.whl.

File metadata

File hashes

Hashes for comrak_ext-0.2.0-cp311-abi3-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 6e474017255f67029709e17d915a373f1255f859d62892d2eb325cf99cc349a6
MD5 9f8ed8bd6daba23bdaff39e98744b1c7
BLAKE2b-256 1c22b62612b78ab20ddf4e16ef912f375ed6e74a8ac27ed2c2c7f9dde3cdef5a

See more details on using hashes here.

File details

Details for the file comrak_ext-0.2.0-cp311-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for comrak_ext-0.2.0-cp311-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 74bc35fc4abb03d38fae2ab9b991c6f31e59f05cef5b3dfe810e54e286614939
MD5 e0f9ddd2177cd7a716ad1788447bb8b7
BLAKE2b-256 53f1eca89b41d5c912fd84d608aa41c7b2df401e4b9064d5b7f0ec374cbf1e1f

See more details on using hashes here.

File details

Details for the file comrak_ext-0.2.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for comrak_ext-0.2.0-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 aa1bbd8e25956f60604e41d0486ff86bf0d10600db79003e5d23e29471afd1ea
MD5 e8fd4e4b72b19d28b533b6ff560911e3
BLAKE2b-256 a1106a1404651dcefb781acf4ba6d8bc8e775718ca640124cb4bb72f4a2e59ca

See more details on using hashes here.

File details

Details for the file comrak_ext-0.2.0-cp311-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl.

File metadata

File hashes

Hashes for comrak_ext-0.2.0-cp311-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 55beda4ee9124979235576922d109f69eeac6feff97e30c717eded2638e82a1b
MD5 e9276cb36ff05a5715efe88989e6488f
BLAKE2b-256 62bb1dc3f0c18fe5d01388eab5b30fbc321a88b602c83b0fc83a714e39c8c971

See more details on using hashes here.

File details

Details for the file comrak_ext-0.2.0-cp311-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl.

File metadata

File hashes

Hashes for comrak_ext-0.2.0-cp311-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 f555c7b7ae3826dc02fdaca56ed38860ae897d0697ed137f62ee7ff7c4c8562d
MD5 d2c4fb0315921cc151e69f1fd5debc6c
BLAKE2b-256 59f0aeadee6389aa77c67ecd3b1332e3a31e8840b3bfbeb72960d00881d48407

See more details on using hashes here.

File details

Details for the file comrak_ext-0.2.0-cp311-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.

File metadata

File hashes

Hashes for comrak_ext-0.2.0-cp311-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 78a52c52609e1f5d50ebac62c5dada63fab4333c6e9b8041e5e19143214d56d7
MD5 2bd906674f0db3702c69788a3477a050
BLAKE2b-256 f2b9b7b6701b58ffe9bedb2ddcb0479da3949d7e56e94462a6a906f7632b0a1e

See more details on using hashes here.

File details

Details for the file comrak_ext-0.2.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for comrak_ext-0.2.0-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 09e1d52df3de1d6bd9ecd061cd5f8af5a1f804fc7579eb6f23d8de3563628cd9
MD5 d172fa36aa9f143c8f0c2779af04cced
BLAKE2b-256 84ef8f236f24eba8c9f567c987cf89f90aaffafbf6afd1239a1e7dfd2694d771

See more details on using hashes here.

File details

Details for the file comrak_ext-0.2.0-cp311-abi3-manylinux_2_5_i686.manylinux1_i686.whl.

File metadata

File hashes

Hashes for comrak_ext-0.2.0-cp311-abi3-manylinux_2_5_i686.manylinux1_i686.whl
Algorithm Hash digest
SHA256 01e45688060b9c255f7810051e918e2ee9bbb038c1b907a19712198daec6149d
MD5 a40e1b9b7a1e5f37a64a4cf48d8a7fcc
BLAKE2b-256 70af1b0c0540517f183dbe3e32e85873008eeb5494606747ad1ce22e64380e66

See more details on using hashes here.

File details

Details for the file comrak_ext-0.2.0-cp311-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for comrak_ext-0.2.0-cp311-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 63021eae5083d0583537d4f4b68f55e739de34dd243ede7ecc8ebc8160ae32e5
MD5 13aee44e4958996878490790b9ad2c93
BLAKE2b-256 7f2b2044cbeb3f3cc7ad8bdd2f8a3cb52f4c79f99018b1f7ecc5f1544f4b288b

See more details on using hashes here.

File details

Details for the file comrak_ext-0.2.0-cp311-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for comrak_ext-0.2.0-cp311-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 351a3d3434ed3fed07b7513304075376dd4810e1b11b0f2f67888ba029398fda
MD5 3bed51ef7ce87ea085b60a942128fd07
BLAKE2b-256 7c1e51ed6389a8a00076a836064d1c66a2af032ef4511daaf786edf5ff5f6b9e

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