Skip to main content

Markdown grammar for tree-sitter

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tree_sitter_markdown-0.3.2.tar.gz (251.9 kB view hashes)

Uploaded Source

Built Distributions

tree_sitter_markdown-0.3.2-cp39-abi3-win_arm64.whl (136.4 kB view hashes)

Uploaded CPython 3.9+ Windows ARM64

tree_sitter_markdown-0.3.2-cp39-abi3-win_amd64.whl (142.0 kB view hashes)

Uploaded CPython 3.9+ Windows x86-64

tree_sitter_markdown-0.3.2-cp39-abi3-musllinux_1_2_x86_64.whl (184.0 kB view hashes)

Uploaded CPython 3.9+ musllinux: musl 1.2+ x86-64

tree_sitter_markdown-0.3.2-cp39-abi3-musllinux_1_2_aarch64.whl (184.5 kB view hashes)

Uploaded CPython 3.9+ musllinux: musl 1.2+ ARM64

tree_sitter_markdown-0.3.2-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (194.6 kB view hashes)

Uploaded CPython 3.9+ manylinux: glibc 2.17+ x86-64

tree_sitter_markdown-0.3.2-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (237.7 kB view hashes)

Uploaded CPython 3.9+ manylinux: glibc 2.17+ ARM64

tree_sitter_markdown-0.3.2-cp39-abi3-macosx_11_0_arm64.whl (147.6 kB view hashes)

Uploaded CPython 3.9+ macOS 11.0+ ARM64

tree_sitter_markdown-0.3.2-cp39-abi3-macosx_10_9_x86_64.whl (139.3 kB view hashes)

Uploaded CPython 3.9+ macOS 10.9+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page