{"id":5083,"library":"tree-sitter-markdown","title":"Tree-sitter Markdown Grammar","description":"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.","status":"active","version":"0.5.3","language":"en","source_language":"en","source_url":"https://github.com/tree-sitter-grammars/tree-sitter-markdown","tags":["tree-sitter","markdown","parsing","grammar","ast"],"install":[{"cmd":"pip install tree-sitter-markdown","lang":"bash","label":"Install with pip"}],"dependencies":[{"reason":"Core parsing library that tree-sitter-markdown's grammar and Python bindings depend on. Requires specific versions for full compatibility.","package":"tree-sitter","optional":false}],"imports":[{"note":"The primary entry point for the pre-compiled Tree-sitter Language object is exposed directly from the package root, not from internal modules.","wrong":"from tree_sitter_markdown.grammar import language_spec","symbol":"language","correct":"from tree_sitter_markdown import language"}],"quickstart":{"code":"import tree_sitter\nfrom tree_sitter import Parser\nfrom tree_sitter_markdown import language\n\n# Load the Tree-sitter Markdown language\n# The `tree_sitter_markdown` package provides a pre-compiled language object.\nMARKDOWN_LANGUAGE = language()\n\n# Initialize a parser and set its language\nparser = Parser()\nparser.set_language(MARKDOWN_LANGUAGE)\n\n# Parse a Markdown string\nmarkdown_text = \"## Hello Tree-sitter\\n\\nThis is a *paragraph* with **bold** text.\"\ntree = parser.parse(bytes(markdown_text, \"utf8\"))\n\n# Print the S-expression representation of the syntax tree\nprint(\"Parsed S-expression:\")\nprint(tree.root_node.sexp())\n\n# Example: Accessing a specific node\nroot_node = tree.root_node\n# Assuming the first child is the heading based on the input markdown\nif root_node.child_count > 0:\n    heading_node = root_node.children[0]\n    print(f\"\\nFirst node type: {heading_node.type}, text: {heading_node.text.decode('utf8')}\")\n","lang":"python","description":"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."},"warnings":[{"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`.","message":"Version 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.","severity":"breaking","affected_versions":">=0.5.2"},{"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.","message":"Version 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.","severity":"breaking","affected_versions":">=0.5.0"},{"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.","message":"While `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.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}