Markdown grammar for tree-sitter
  • C 45.1%
  • JavaScript 32.2%
  • Rust 16.3%
  • Makefile 2.7%
  • CMake 2.4%
  • Other 1.3%
Find a file
Christian Clason f969cd3ae3 release v0.5.3
2026-02-26 19:04:19 +01:00
.github ci: add query validation job 2026-01-11 11:39:08 +01:00
bindings fix: Rename 'a to 'tree 2026-02-01 02:53:16 -05:00
common release v0.5.3 2026-02-26 19:04:19 +01:00
scripts feat: update to tree-sitter 0.24 2024-10-21 10:13:04 +03:00
tree-sitter-markdown release v0.5.3 2026-02-26 19:04:19 +01:00
tree-sitter-markdown-inline release v0.5.3 2026-02-26 19:04:19 +01:00
.editorconfig feat: update to tree-sitter 0.24 2024-10-21 10:13:04 +03:00
.gitattributes feat: update bindings with 0.26.3 2026-01-11 11:39:08 +01:00
.gitignore feat: update bindings with 0.26.3 2026-01-11 11:39:08 +01:00
.tsqueryrc.json ci: add query validation job 2026-01-11 11:39:08 +01:00
binding.gyp feat: update bindings 2024-03-13 23:31:48 +02:00
Cargo.toml release v0.5.3 2026-02-26 19:04:19 +01:00
CMakeLists.txt release v0.5.3 2026-02-26 19:04:19 +01:00
CONTRIBUTING.md feat: update to tree-sitter 0.24 2024-10-21 10:13:04 +03:00
LICENSE Create LICENSE 2021-12-30 00:26:52 +01:00
Makefile feat: separate C bindings 2024-03-13 23:31:48 +02:00
package-lock.json release v0.5.3 2026-02-26 19:04:19 +01:00
package.json release v0.5.3 2026-02-26 19:04:19 +01:00
Package.resolved feat: update to tree-sitter 0.24 2024-10-21 10:13:04 +03:00
Package.swift feat: update bindings with 0.26.3 2026-01-11 11:39:08 +01:00
pyproject.toml release v0.5.3 2026-02-26 19:04:19 +01:00
README.md feat: update to tree-sitter 0.24 2024-10-21 10:13:04 +03:00
setup.py chore: regenerate parser and bindings with 0.26.6 2026-02-26 10:10:19 +01:00
tree-sitter.json release v0.5.3 2026-02-26 19:04:19 +01:00

tree-sitter-markdown

CI discord matrix npm crates pypi

A Markdown parser for tree-sitter.

screenshot

The parser is designed to read markdown according to the CommonMark Spec, but some extensions to the spec from different sources such as Github flavored markdown are also included. These can be toggled on or off at compile time. For specifics see Extensions

Goals

Even though this parser has existed for some while and obvious issues are mostly solved, there are still lots of inaccuracies in the output. These stem from restricting a complex format such as markdown to the quite restricting tree-sitter parsing rules.

As such it is not recommended to use this parser where correctness is important. The main goal for this parser is to provide syntactical information for syntax highlighting in parsers such as neovim and helix.

Contributing

All contributions are welcome. For details refer to CONTRIBUTING.md.

Extensions

Extensions can be enabled at compile time through environment variables. Some of them are on by default, these can be disabled with the environment variable NO_DEFAULT_EXTENSIONS.

Name Environment variable Specification Default Also enables
Github flavored markdown EXTENSION_GFM link Task lists, strikethrough, pipe tables
Task lists EXTENSION_TASK_LIST link
Strikethrough EXTENSION_STRIKETHROUGH link
Pipe tables EXTENSION_PIPE_TABLE link
YAML metadata EXTENSION_MINUS_METADATA link
TOML metadata EXTENSION_PLUS_METADATA link
Tags EXTENSION_TAGS link
Wiki Link EXTENSION_WIKI_LINK link

Usage in Editors

For guides on how to use this parser in a specific editor, refer to that editor's specific documentation, e.g.

Standalone usage

To use the two grammars, first parse the document with the block grammar. Then perform a second parse with the inline grammar using ts_parser_set_included_ranges to specify which parts are inline content. These parts are marked as inline nodes. Children of those inline nodes should be excluded from these ranges. For an example implementation see lib.rs in the bindings folder.

Usage with WASM

Unfortunately using this parser with WASM/web-tree-sitter does not work out of the box at the moment. This is because the parser uses some C functions that are not exported by tree-sitter by default. To fix this you can statically link the parser to tree-sitter. See also https://github.com/tree-sitter/tree-sitter/issues/949, https://github.com/MDeiml/tree-sitter-markdown/issues/126, and https://github.com/MDeiml/tree-sitter-markdown/issues/93