12 unstable releases (3 breaking)

0.3.2 Sep 11, 2024
0.2.3 Mar 22, 2024
0.1.7 Nov 10, 2023
0.1.5 Mar 5, 2023
0.1.1 Jun 29, 2022

#24 in Text editors

Download history 941/week @ 2024-08-17 882/week @ 2024-08-24 802/week @ 2024-08-31 1486/week @ 2024-09-07 1113/week @ 2024-09-14 1184/week @ 2024-09-21 722/week @ 2024-09-28 1321/week @ 2024-10-05 1241/week @ 2024-10-12 685/week @ 2024-10-19 413/week @ 2024-10-26 602/week @ 2024-11-02 713/week @ 2024-11-09 703/week @ 2024-11-16 588/week @ 2024-11-23 662/week @ 2024-11-30

2,749 downloads per month
Used in 9 crates (6 directly)

MIT license

4.5MB
138K SLoC

C 137K SLoC // 0.0% comments JavaScript 835 SLoC // 0.2% comments Rust 422 SLoC Scheme 78 SLoC // 0.0% comments

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 inaccuarcies 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

Dependencies

~0–1MB
~19K SLoC