Registry / serialization / tree-sitter-markdown

tree-sitter-markdown

JSON →
library0.5.1pypypi✓ verified 23d ago

tree-sitter-markdown provides a robust and comprehensive Markdown grammar for the Tree-sitter parsing library. It enables high-performance syntactic parsing of Markdown content, exposing an abstract syntax tree (AST) for various applications like code highlighting, refactoring, and static analysis. The library is actively maintained, with frequent minor releases addressing grammar improvements and compatibility updates.

pip install tree-sitter-markdown
INSTALL
IMPORT
SIG · TREE-SITTER-MARKDO
T
tree-sitter-markdown
serializationpythonv0.5.1
Install
1.5s avg
Import
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.5.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 18.7MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.5s · import 0.000s · 19MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

language
from tree_sitter_markdown import language
from tree_sitter_markdown.grammar import language_spec
The primary entry point for the pre-compiled Tree-sitter Language object is exposed directly from the package root, not from internal modules.

This quickstart demonstrates how to initialize the Tree-sitter Markdown parser, parse a sample Markdown string, and inspect the resulting syntax tree using S-expressions and node access.

import tree_sitter from tree_sitter import Parser from tree_sitter_markdown import language # Load the Tree-sitter Markdown language # The `tree_sitter_markdown` package provides a pre-compiled language object. MARKDOWN_LANGUAGE = language() # Initialize a parser and set its language parser = Parser() parser.set_language(MARKDOWN_LANGUAGE) # Parse a Markdown string markdown_text = "## Hello Tree-sitter\n\nThis is a *paragraph* with **bold** text." tree = parser.parse(bytes(markdown_text, "utf8")) # Print the S-expression representation of the syntax tree print("Parsed S-expression:") print(tree.root_node.sexp()) # Example: Accessing a specific node root_node = tree.root_node # Assuming the first child is the heading based on the input markdown if root_node.child_count > 0: heading_node = root_node.children[0] print(f"\nFirst node type: {heading_node.type}, text: {heading_node.text.decode('utf8')}")
Debug
Known issues
breakingVersion 0.5.2 updated Rust bindings to require `tree-sitter >=0.26.3` and replaced the `parse_with` API method with `parse_with_options` in the core `tree-sitter` library. Users with older `tree-sitter` versions or those using the Rust bindings directly will need to update and adjust their code.
fix
Ensure `tree-sitter` is installed at version `0.26.3` or newer (`pip install 'tree-sitter>=0.26.3'`). If using Rust bindings, update `parse_with` calls to `parse_with_options`.
affects: >=0.5.2
breakingVersion 0.5.0 involved regenerating parsers with ABI 15. This change in the core Tree-sitter Application Binary Interface (ABI) might require users with custom-built `tree-sitter` libraries or older pre-compiled grammars to recompile them or update their `tree-sitter` installation to maintain compatibility.
fix
Update your `tree-sitter` installation and ensure any custom or locally built Tree-sitter grammars are recompiled against the latest ABI. Using `pip install tree-sitter-markdown` will generally handle the correct ABI for the distributed wheel.
affects: >=0.5.0
gotchaWhile `tree-sitter-markdown` provides pre-compiled language bindings via wheels for common platforms, `tree-sitter` itself (and thus any custom language builds) often requires a C/C++ compiler toolchain (e.g., `gcc`, `clang`) to be present on the system for installation or compilation from source.
fix
Ensure a compatible C/C++ compiler is installed on your system if you encounter build errors during `pip install tree-sitter` or when trying to compile custom Tree-sitter grammars. For Debian/Ubuntu, `sudo apt-get install build-essential` is often sufficient.
affects: all
Upgrade
Version history
0.5.1latest on PyPI · released Sep 16, 2025
Audit
Dependencies
tree-sitterrequiredCore parsing library that tree-sitter-markdown's grammar and Python bindings depend on. Requires specific versions for full compatibility.
Agent activity
10 hits · last 30 days
node
8
OpenAI (training)
1
Resources
tree-sitter-markdown — pip install tree-sitter-markdown · libregistry