Skip to main content

mkconvert

PyPI License Package status Monthly downloads Distribution format Wheel availability Python version Implementation Releases Github Contributors Github Forks Github Issues Github Issues Github Watchers Github Stars Github Repository size Github last commit Github release date Github language count Github commits this month Package status PyUp

Read the documentation!

One API for many Markdown → HTML parsers (Rust and Python), with a common set of options that maps onto every parser, parser-specific options on top, and the same pattern for HTML → Markdown. Every backend is an optional extra: install only what you use.

Installation

pip install "mkconvert[comrak]"            # Rust-based comrak (recommended)
pip install "mkconvert[pyromark,htmd-py]"  # pulldown-cmark parser + Rust HTML -> Markdown

Parser extras: comrak, pyromark, markdown_it_pyrs, cmarkgfm, mistune, marko, markdown2, markdown (Python-Markdown + pymdown-extensions). HTML → Markdown: htmd-py, markdownify. Sanitizing: nh3. comrak, pyromark and markdown_it_pyrs are limited to Python < 3.14 for now (no wheels / crashes there), so their extras install nothing on newer Pythons.

Quickstart

import mkconvert
from mkconvert import MarkdownOptions

html = mkconvert.to_html("# Hello\n\n~~old~~ **new**", options=MarkdownOptions.gfm())

# Pick a parser, add common options and parser-specific ones:
html = mkconvert.to_html(
    "# Title\n\nx^2^",
    parser="comrak",
    options=MarkdownOptions(heading_ids=True, footnotes=True),
    superscript=True,  # comrak-specific
)

# Reuse a configured parser for many documents:
parser = mkconvert.get_parser("comrak", MarkdownOptions.gfm(math=True))
pages = [parser.convert(text) for text in ["# A", "# B"]]

# Or use the classes directly (typed, documented parameters):
from mkconvert import ComrakParser

html = ComrakParser(MarkdownOptions(tables=True), header_id_prefix="h-").convert("| a |\n|---|")

Without parser=, the first installed parser is used, in this order: comrak, pyromark, markdown-it-pyrs, cmarkgfm, mistune, marko, markdown2, python-markdown. mkconvert.list_parsers(available_only=True) lists the installed ones. A missing package raises MissingDependencyError naming the extra to install.

Common options

MarkdownOptions() is plain CommonMark (all extensions off, raw HTML passed through), except that a leading --- front matter block is dropped (front_matter=False renders it). MarkdownOptions.gfm(**changes) turns on tables, strikethrough, autolinks and task lists.

Option comrak pyromark markdown-it-pyrs cmarkgfm mistune marko markdown2 python-markdown
tables ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓
strikethrough ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓
autolinks ✓ – ✓ ✓ ✓¹ ✓ – ✓
task_lists ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓
footnotes ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓
heading_ids ✓ – ✓ – ✓ ✓ ✓ ✓
alerts ✓ ✓ – – – ✓ ✓ –
math ✓ ✓ – – ✓ – – ✓
definition_lists ✓ ✓ ✓ – ✓ – – ✓
hard_breaks ✓ – – ✓ ✓ ✓ ✓ ✓
smart_punctuation ✓ ✓ ✓ ✓ – – ✓ ✓
raw_html=False ✓ – ✓ ✓² ✓ ✓ ✓ ✓
front_matter ✓ ✓ ✓ ✓ ✓ ✓ ✓ ✓

¹ bare https:// URLs only, not www. ² raw HTML is omitted instead of escaped.

Each option is documented on MarkdownOptions. A parser's supported_options tells what it can do (mkconvert.get_parser_class("pyromark").supported_options). Setting an option the parser can't honour warns (UnsupportedOptionWarning) and is ignored; on_unsupported="raise" raises UnsupportedOptionError instead, "ignore" stays quiet.

raw_html=False keeps raw HTML out of the output, but it is no sanitizer. For untrusted input run the result through mkconvert.sanitize(html) (nh3).

Parser-specific options

Passed as keyword arguments to to_html / get_parser or the parser class:

Parser Options
comrak header_id_prefix, tagfilter, superscript, subscript, underline, spoiler, greentext, wikilinks, multiline_block_quotes, math_code, relaxed_autolinks, relaxed_tasklist_matching, default_info_string, github_pre_lang, full_info_string, sourcepos
pyromark heading_attributes, superscript, subscript, wikilinks, old_footnotes, highlight
markdown-it-pyrs xhtml, sourcepos, plugins
cmarkgfm tagfilter, github_pre_lang, sourcepos
mistune plugins (e.g. ["abbr", "mark", "superscript"])
marko extensions (e.g. ["codehilite", "pangu"])
markdown2 extras, highlight, html4tags
python-markdown extensions, extension_configs, output_format

HTML → Markdown

from mkconvert import HtmlToMarkdownOptions, to_markdown

md = to_markdown("<h1>Title</h1><p><b>bold</b></p>")
md = to_markdown(
    html,
    converter="markdownify",
    options=HtmlToMarkdownOptions(heading_style="setext", skip_tags=("script", "style")),
    code_language="python",  # markdownify-specific
)
Option htmd markdownify
heading_style ("atx", "setext") ✓ ✓
bullet_marker ("-", "*") ✓ ✓
emphasis_marker ("*", "_") – ✓
code_block_style ("fenced", "indented") ✓ –
code_fence ("```", "~~~") ✓ –
line_break ("spaces", "backslash") ✓ ✓
link_style ("inline", "reference") ✓ –
skip_tags ✓ ✓

Converter-specific options: htmd: hr_style, link_reference_style, preformatted_code, ul_bullet_spacing, ol_number_spacing, translation_mode; markdownify: bullets, strip, convert, autolinks, default_title, code_language, code_language_callback, escape_asterisks, escape_underscores, escape_misc, sub_symbol, sup_symbol, table_infer_header, wrap, wrap_width, strip_document.

Helpers

  • sanitize(html, extra_attributes=None, **nh3_options): clean HTML with nh3, e.g. sanitize(html, extra_attributes={"*": {"id", "class"}}) to keep heading ids and code classes.
  • extract_title(html): text of the first <h1>, or None.
  • split_front_matter(text): (front_matter, body) for a leading --- block.

Custom parsers

Subclass MarkdownParser (set name, requires, extra, supported_options, implement _render) and register it with mkconvert.register_parser; likewise HtmlToMarkdownConverter and register_converter.

Metadata

Release files for mkconvert 2.0.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 mkconvert 2.0.0
File Size Uploaded Provenance Actions
mkconvert-2.0.0.tar.gz 25.3 kB With provenance Details for mkconvert-2.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mkconvert 2.0.0
File Interpreter ABI Platform Actions
mkconvert-2.0.0-py3-none-any.whl Python 3 none any Details for mkconvert-2.0.0-py3-none-any.whl

Total release size: 54.2 kB

Release files / mkconvert-2.0.0.tar.gz

Download URL mkconvert-2.0.0.tar.gz
Size 25.3 kB
Tags Source
SHA-256 checksum
How to use checksums
6f505ef765ab683e298f4ee45e2b71278dc6f58292a20e22d200f90897b71972
BLAKE2b-256 checksum
How to use checksums
1f7a9517efb028610c5202cf3190a619645014a618a3105fc50862fb80e51fac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

Release files / mkconvert-2.0.0-py3-none-any.whl

Download URL mkconvert-2.0.0-py3-none-any.whl
Size 28.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fc0fb2015de765c78e47458869f029b89075c0ba3addef6fe327707472b71bc6
BLAKE2b-256 checksum
How to use checksums
badea5707aa0e4351fcc5c7c44441104110d99ec84a1d400f67c60a85ccd1c6e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

Security for mkconvert 2.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for mkconvert-2.0.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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