{"id":1427,"library":"commonmark","title":"CommonMark Python Parser","description":"CommonMark-py is a pure Python port of jgm's commonmark.js, a Markdown parser and renderer for the CommonMark specification, using only native modules. It provides functionality to parse Markdown into an Abstract Syntax Tree (AST) and render it to HTML. While it aimed to keep up with CommonMark spec updates, the project is now officially deprecated, with `markdown-it-py` recommended as an alternative for new projects. [7]","status":"deprecated","version":"0.9.1","language":"en","source_language":"en","source_url":"https://github.com/rtfd/commonmark.py","tags":["markdown","parser","commonmark","deprecated"],"install":[{"cmd":"pip install commonmark","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Required for Python 2 compatibility (version 0.9.1 requires future >= 0.14.0 on Python 2). [0.9.1 release notes]","package":"future","optional":true}],"imports":[{"note":"For direct conversion of Markdown string to HTML.","symbol":"commonmark","correct":"from commonmark import commonmark"},{"note":"The top-level 'CommonMark' module was removed in version 0.8.1. You must now use 'import commonmark' or import specific components like 'Parser' and 'HtmlRenderer' from the 'commonmark' package. [10]","wrong":"import CommonMark","symbol":"Parser, HtmlRenderer","correct":"from commonmark import Parser, HtmlRenderer"}],"quickstart":{"code":"import commonmark\nfrom commonmark import Parser, HtmlRenderer\n\nmarkdown_text = \"Hello *World*! This is **CommonMark**.\"\n\n# Simple conversion\nhtml_output_simple = commonmark.commonmark(markdown_text)\nprint(f\"Simple HTML:\\n{html_output_simple}\")\n\n# Advanced usage with AST manipulation\nparser = Parser()\nast = parser.parse(markdown_text)\n\nrenderer = HtmlRenderer()\nhtml_output_advanced = renderer.render(ast)\nprint(f\"\\nAdvanced HTML:\\n{html_output_advanced}\")\n\n# Example of AST inspection (prints a tree structure)\n# commonmark.dumpAST(ast)","lang":"python","description":"This quickstart demonstrates both the simple `commonmark.commonmark()` function for direct conversion and the more advanced `Parser` and `HtmlRenderer` classes for parsing to an AST and then rendering to HTML. [5, 7]"},"warnings":[{"fix":"Consider migrating to `markdown-it-py`. If continuing with `commonmark`, be aware of potential lack of future updates or security fixes.","message":"The commonmark.py project is no longer actively maintained and has been officially deprecated. The maintainers recommend migrating to `markdown-it-py` for new projects or existing ones. [7]","severity":"deprecated","affected_versions":"0.9.1 and later"},{"fix":"Replace all instances of `import CommonMark` with `import commonmark` and update any references to `CommonMark.some_function` to `commonmark.some_function`.","message":"The package and module name changed from `CommonMark` to `commonmark` for PEP8 compliance in version 0.8.0. While 0.8.0 allowed both `import commonmark` and `import CommonMark`, the symlink for `CommonMark` was removed in 0.8.1. This means code using `import CommonMark` will break when upgrading to 0.8.1 or later. [10, 12]","severity":"breaking","affected_versions":">=0.8.1"},{"fix":"Ensure `pip install commonmark[py2]` or `pip install commonmark future` is used when installing on Python 2.","message":"For Python 2 compatibility in version 0.9.1, the `future` library (>=0.14.0) is a required dependency. Users on Python 2 environments should ensure this dependency is installed. The project's testing covered Python 2.7, 3.5-3.8. [0.9.1 release notes, 7]","severity":"gotcha","affected_versions":"0.9.1 (Python 2 environments)"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}