🔧 Remove optional dependency on the unmaintained `commonmark` package (#427) ## Summary Supersedes #401 by @nikolas, whose fork does not allow maintainer pushes; their commit is carried here verbatim with authorship preserved (thank you!). The `commonmark` PyPI package was deprecated in 2022 (last release 2019). #401 dropped it from the `compare` extra but left `benchmarking/bench_packages.py::test_commonmark_py` importing it unguarded, so `tox -e py311-bench-packages` (which installs `benchmarking,compare`) would have errored. This PR removes that benchmark too. The `commonmark-py` row in `docs/performance.md` is **kept**, with a footnote explaining that the package is deprecated, has been removed from the benchmark suite, and that the figures are from the last run that included it. The historical comparison is still informative. A changelog line with the rationale is added. ## Commits 1. `Remove optional dependency on commonmark` — the contributor's commit, unchanged. 2. `🔧 MAINTAIN: Remove remaining commonmark references` — drops the orphaned benchmark, adds the changelog line. 3. `📚 DOCS: Keep the commonmark-py benchmark row, with a deprecation footnote`, plus a changelog wording tweak. ## Verification - All tests pass; all pre-commit hooks pass under the new pins. - Local docs build renders the footnote and adds no warnings over master. - Remaining `commonmark` mentions in `pyproject.toml`, `tox.ini` and `benchmarking/` refer to the CommonMark spec or the `commonmark` preset, none to the package. --------- Co-authored-by: Nikolas Nyby <nikolas@gnu.org> GitOrigin-RevId: a5950caef3434ed83045b43311aefcf7e0578aa3 Change-Id: I825f71718b1eb46179dad9ef20cdab36efd6839b
Markdown parser done right.
This is a Python port of markdown-it, and some of its associated plugins. For more details see: https://markdown-it-py.readthedocs.io.
For details on markdown-it itself, see:
See also: markdown-it-pyrs for an experimental Rust binding, for even more speed!
pip install markdown-it-py[plugins]
or with extras
pip install markdown-it-py[linkify,plugins]
conda install -c conda-forge markdown-it-py
or with extras
conda install -c conda-forge markdown-it-py linkify-it-py mdit-py-plugins
Render markdown to HTML with markdown-it-py and a custom configuration with and without plugins and features:
from markdown_it import MarkdownIt from mdit_py_plugins.front_matter import front_matter_plugin from mdit_py_plugins.footnote import footnote_plugin md = ( MarkdownIt("commonmark", {"breaks": True, "html": True}) .use(front_matter_plugin) .use(footnote_plugin) .enable("table") ) text = """ --- a: 1 --- a | b - | - 1 | 2 A footnote [^1] [^1]: some details """ tokens = md.parse(text) html_text = md.render(text) ## To export the html to a file, uncomment the lines below: # from pathlib import Path # Path("output.html").write_text(html_text)
Render markdown to HTML with markdown-it-py from the command-line:
usage: markdown-it [-h] [-v] [--stdin] [--enable-tables] [filenames ...] Parse one or more markdown files, convert each to HTML, and print to stdout positional arguments: filenames specify an optional list of files to convert options: -h, --help show this help message and exit -v, --version show program's version number and exit --stdin read Markdown from standard input --enable-tables enable table parsing Interactive: $ markdown-it markdown-it-py [version 0.0.0] (interactive) Type Ctrl-D to complete input, or Ctrl-C to exit. >>> # Example ... > markdown *input* ... <h1>Example</h1> <blockquote> <p>markdown <em>input</em></p> </blockquote> Batch: $ markdown-it README.md README.footer.md > index.html
Tables are disabled by default, as in CommonMark. Use --enable-tables with any input mode to enable them:
markdown-it --enable-tables README.md > index.html markdown-it --enable-tables --stdin < README.md > index.html markdown-it --enable-tables
Big thanks to the authors of markdown-it:
Also John MacFarlane for his work on the CommonMark spec and reference implementations.