tree-sitter-markdown-text
Markdown grammar for tree-sitter, shaped so that its AST lines up with the textlint TxtNode model.
Parses .md (and .markdown, .mdown, .mkd, .mkdn) files into a concrete syntax tree covering the full CommonMark block structure plus common extensions (GFM pipe tables, task lists, GFM alerts, YAML/TOML front matter, Pandoc math and directive blocks, footnotes, MDX JSX). Inline content is surfaced as structured children of the inline wrapper: classified tokens (word_token, numeric_token, identifier_like_token, path_like_token) and punctuation-class nodes (terminator, separator, bracket, operator_like), plus inline structural nodes (emphasis, strong, strikethrough, link, image, autolink, inline_code, html_inline, math_inline, mdx_jsx_inline, footnote_reference).
Features
Block nodes
- Document structure —
document, nestedsectionwrappers around ATX headings,paragraph,blank_line(as a first-class node). - Headings — ATX (
#..######) and setext (===/---) with the heading level exposed as alevelfield on bothatx_headingandsetext_heading. - Code blocks — indented code blocks and fenced code blocks (backtick and tilde), with
info_string/languagechildren for the GFM language tag. - Math blocks — Pandoc/GitLab/KaTeX display math (
$$…$$) as a dedicatedmath_blockwithmath_block_delimiter/math_block_contentchildren. - Lists — unordered (
+/-/*) and ordered (1./1)) list markers. GFM task list items are promoted totask_list_item(distinct fromlist_item), withtask_list_marker_checked/task_list_marker_uncheckedmarkers. - Block quotes and callouts — nested quotes and lazy continuations. A block quote whose first paragraph begins with
[!NOTE]/[!TIP]/[!IMPORTANT]/[!WARNING]/[!CAUTION](or any uppercase-only label) is surfaced ascalloutwith acallout_typefield. - Thematic breaks —
---,***,___. - HTML blocks — all 7 CommonMark HTML block types; block-level HTML comments are aliased to
html_comment_blockfor easy metric extraction. - MDX JSX blocks — shallow
mdx_jsx_blockfor lines that start with an MDX-style JSX element (<Component ...>,<Component/>,</Component>). Component-style mixed-case names disambiguate from all-caps HTML blocks such as<DIV>. - Pipe tables —
pipe_tablewithpipe_table_header,pipe_table_delimiter_row,pipe_table_row,pipe_table_cell,pipe_table_align_left/pipe_table_align_right. - Link reference definitions —
link_reference_definitionwithlink_label/link_destination/link_titlechildren. - Footnote definitions —
footnote_definition([^id]: …) with afootnote_labelchild. - Directive blocks — generic container directives (
:::name … :::, per remark-directive / MyST / Pandoc fenced divs) asdirective_blockwithdirective_block_delimiter/directive_name/directive_block_contentchildren. - Image blocks — a paragraph consisting of a single block-level image (
on its own line) is surfaced asimage_blockwithlink_label/link_destinationchildren. - Front matter — YAML (
---fenced) asminus_metadata, TOML (+++fenced) asplus_metadata.
Inline nodes (children of the inline wrapper)
-
Classified text tokens —
text_spanwraps runs of classified tokens:word_token(Unicode alphabetic),numeric_token(integers, decimals, versions),identifier_like_token(camelCase / PascalCase / snake_case),path_like_token(paths with/separators or dotted identifiers). -
Punctuation classes — every punctuation lexeme is classified:
terminator(.,?,!,。,…),separator(,,;,:),bracket((,),[,],{,},<,>),operator_like(::,->,=>,=,+,-,*,/,|,&, and other punctuation). -
Emphasis / strong / strikethrough —
emphasis(*…*or_…_),strong(**…**or__…__),strikethrough(~~…~~), each with a_delimiter/_content/_delimitersub-tree. -
Code spans —
inline_codewith matched backtick-run delimiters (1 or 2 backticks). -
Links and images —
link(inline, full-reference, collapsed-reference, shortcut-reference forms) andimage(or![alt][ref]). Both exposelink_label/link_destination/link_titlechildren. -
Autolinks —
autolinkwithurioremailchildren for<https://…>and<user@example.com>. -
Raw HTML inline —
html_inlinewithhtml_open_tag/html_close_tag/html_comment/html_cdata/html_declaration/html_processing_instructionchildren. -
MDX JSX inline — shallow
mdx_jsx_inlinewithmdx_jsx_open_tag/mdx_jsx_close_tag/mdx_jsx_expressionchildren. -
Inline math —
math_inline($…$) withmath_inline_delimiter/math_inline_contentchildren. Disambiguated frommath_block($$…$$). -
Footnote references —
footnote_reference([^id]inside prose) with afootnote_reference_labelchild. -
Injections query — ships a
queries/injections.scmthat injects into fenced-code-block info strings, HTML blocks, and front matter.
Example
# Heading
A paragraph with inline content.
- one
- two
```go
func main() {}
Parsed tree (abbreviated):
(document (section (atx_heading level: (atx_h1_marker) heading_content: (inline)) (blank_line) (paragraph (inline)) (blank_line) (list (list_item (list_marker_minus) (paragraph (inline))) (list_item (list_marker_minus) (paragraph (inline)))) (blank_line) (fenced_code_block (fenced_code_block_delimiter) (info_string (language)) (code_fence_content) (fenced_code_block_delimiter))))
## Relationship to textlint
The grammar is structurally close to the textlint AST. Every block-level `TxtNode` type has a direct counterpart here; inline `TxtNode` types (`Str`, `Emphasis`, `Strong`, `Link`, `Image`, `Code`, `Html`, `Delete`, `FootnoteReference`) also have direct counterparts as children of the `inline` wrapper. Names stay snake_case per the tree-sitter convention; consumers map names themselves. See [docs/textlint-mapping.md](docs/textlint-mapping.md) for the full table.
## Installation
### npm
```sh
npm install tree-sitter-markdown-text
Cargo
cargo add tree-sitter-markdown-text
PyPI
pip install tree-sitter-markdown-text
Go
import tree_sitter_markdown_text "github.com/ophidiarium/tree-sitter-markdown-text/bindings/go"
The root package also exports the bundled queries via go:embed:
import markdown "github.com/ophidiarium/tree-sitter-markdown-text"
lang := markdown.GetLanguage()
query, _ := markdown.GetHighlightsQuery()
Usage
Node.js
import Parser from "tree-sitter";
import Markdown from "tree-sitter-markdown-text";
const parser = new Parser();
parser.setLanguage(Markdown);
const tree = parser.parse("# hello\n");
console.log(tree.rootNode.toString());
Rust
let mut parser = tree_sitter::Parser::new();
let language = tree_sitter_markdown_text::LANGUAGE;
parser.set_language(&language.into()).unwrap();
let tree = parser.parse("# hello\n", None).unwrap();
println!("{}", tree.root_node().to_sexp());
Python
from tree_sitter import Language, Parser
import tree_sitter_markdown_text
parser = Parser(Language(tree_sitter_markdown_text.language()))
tree = parser.parse(b"# hello\n")
print(tree.root_node.sexp())
Credits and references
- tree-sitter-grammars/tree-sitter-markdown — upstream grammar, specifically the
split_parserbranch's block grammar, which this grammar is derived from. - textlint TxtNode — the AST shape this grammar targets for compatibility.
- CommonMark Spec — the block structure this grammar implements.
- Github Flavored Markdown — for the pipe-table and task-list extensions.
License
Metadata
Release files for tree-sitter-markdown-text 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| tree_sitter_markdown_text-0.2.1.tar.gz | 312.7 kB | Details |
Built distributions (wheels)
Total release size: 1.7 MB
Release files / tree_sitter_markdown_text-0.2.1.tar.gz
| Download URL | tree_sitter_markdown_text-0.2.1.tar.gz |
|---|---|
| Size | 312.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
26fa99a02defb0b425602e4a30c756de26dca3e83e985f8621867f50afeb0673
|
|
BLAKE2b-256 checksum How to use checksums |
aae5a987f244e182d94b9e729518c6b65a1a0fec7814e8b91a504eaf2ad92298
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 12, 2026.
Transparency logRelease files / tree_sitter_markdown_text-0.2.1-cp310-abi3-win_arm64.whl
| Download URL | tree_sitter_markdown_text-0.2.1-cp310-abi3-win_arm64.whl |
|---|---|
| Size | 140.9 kB |
| Tags | CPython 3.10 Windows ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
73caccd5cd30fcb7c406ec8b183dc7c37ba40a04c0a7df9eaeccf27f137cbd99
|
|
BLAKE2b-256 checksum How to use checksums |
78f052b75fc42df6f1fe29c8b9f49333fb95f2b4cdc8f726a3f2c1c24c1ebc69
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 12, 2026.
Transparency logRelease files / tree_sitter_markdown_text-0.2.1-cp310-abi3-win_amd64.whl
| Download URL | tree_sitter_markdown_text-0.2.1-cp310-abi3-win_amd64.whl |
|---|---|
| Size | 146.1 kB |
| Tags | CPython 3.10 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
94c18f4a8d76bb1b5eb89b4b58c323367b6594c9773cfa20b82b1dca0f9034b9
|
|
BLAKE2b-256 checksum How to use checksums |
26d1c63c260c2a84684fe7eff07638597c7470ba03faf0b085ba54c05092dc73
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 12, 2026.
Transparency logRelease files / tree_sitter_markdown_text-0.2.1-cp310-abi3-musllinux_1_2_x86_64.whl
| Download URL | tree_sitter_markdown_text-0.2.1-cp310-abi3-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 190.8 kB |
| Tags | CPython 3.10 Linux musl 1.2+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
874e54182ae68d9c34037c7408a6aaf95cafc19e37bcab1345fbff9d364302be
|
|
BLAKE2b-256 checksum How to use checksums |
6e7410cbec941926987a3f312eede67a069054f4ece1163d42be3dab24e7d63e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 12, 2026.
Transparency logRelease files / tree_sitter_markdown_text-0.2.1-cp310-abi3-musllinux_1_2_aarch64.whl
| Download URL | tree_sitter_markdown_text-0.2.1-cp310-abi3-musllinux_1_2_aarch64.whl |
|---|---|
| Size | 187.9 kB |
| Tags | CPython 3.10 Linux musl 1.2+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
4f69dc3e2dbd38c1e22e1077a7e3c32de4bd893a66e6c95663d99dcdc497f83c
|
|
BLAKE2b-256 checksum How to use checksums |
f60197001e94e947dc80cebb8c0c57768171a4601372bc0cd16789cce37e9beb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 12, 2026.
Transparency logRelease files / tree_sitter_markdown_text-0.2.1-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
| Download URL | tree_sitter_markdown_text-0.2.1-cp310-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl |
|---|---|
| Size | 189.7 kB |
| Tags | CPython 3.10 Linux glibc 2.17+ ARM64 Linux glibc 2.28+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
de9b1253c5fa97461f72f8723898db54ed6d7666ae044e5235a6fb8f129327ae
|
|
BLAKE2b-256 checksum How to use checksums |
b7a5073b0f69034bf998884799683735b1a95a8e082db4241d9f94be3a67d8a8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 12, 2026.
Transparency logRelease files / tree_sitter_markdown_text-0.2.1-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl
| Download URL | tree_sitter_markdown_text-0.2.1-cp310-abi3-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl |
|---|---|
| Size | 193.7 kB |
| Tags | CPython 3.10 Linux glibc 2.28+ x86-64 Linux glibc 2.5+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
e8f1e591ef9bcbcbbef4132ae2c231a612c91b1ef5aa956e69119db3d7bbfb46
|
|
BLAKE2b-256 checksum How to use checksums |
a823f32d714fc285e3b8fe23cf420dee6185ff667a59f07f065d692941c43287
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 12, 2026.
Transparency logRelease files / tree_sitter_markdown_text-0.2.1-cp310-abi3-macosx_11_0_arm64.whl
| Download URL | tree_sitter_markdown_text-0.2.1-cp310-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 151.1 kB |
| Tags | CPython 3.10 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
4efd1bb601c75c4cef08e17313806692775604684b75375946669bc9b9defba4
|
|
BLAKE2b-256 checksum How to use checksums |
1e0732e1f5a72b433191274ac69f3b69c7fe7050ae0d550876c6dd6c5402b02f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 12, 2026.
Transparency logRelease files / tree_sitter_markdown_text-0.2.1-cp310-abi3-macosx_10_9_x86_64.whl
| Download URL | tree_sitter_markdown_text-0.2.1-cp310-abi3-macosx_10_9_x86_64.whl |
|---|---|
| Size | 142.8 kB |
| Tags | CPython 3.10 abi3 macOS 10.9+ x86-64 |
|
SHA-256 checksum How to use checksums |
93f7b47a8bdea1b058b5f8885c695536e4a7a9fa5a7cd24b6313f82b34c111e3
|
|
BLAKE2b-256 checksum How to use checksums |
2cca3b9378358925362ce8f7a78a47cc72111991e92bbfc950fb2f3dbf62090b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on May 12, 2026.
Transparency log