Getting Emacs 31's experimental Markdown tree-sitter mode running
Emacs 31 ships a new built-in markdown-ts-mode, a tree-sitter-based major mode for editing Markdown. Despite being flagged experimental, it is already feature-rich: it covers the full CommonMark spec and most of GitHub Flavored Markdown, adds syntax highlighting for fenced code blocks in many languages, and offers extras like table-of-contents tools and hooks into external converters such as pandoc. Because it is experimental, Emacs does not enable it automatically—users must load the library themselves, for example via use-package or an autoload plus auto-mode-alist entries, and also require the markdown-ts-mode-x extension for the added conveniences. Notably, the old MELPA package should be avoided, as it won’t install on Emacs 31 and lacks the built-in mode’s capabilities.
The bulk of the guide addresses tree-sitter’s main friction point: grammars. Opening a Markdown file may prompt Emacs to clone and compile the grammar on the spot (Markdown actually needs two—one for block structure, one for inline parsing). Anything that fails to highlight, such as a YAML or TOML front-matter header or an embedded code block, usually signals a missing grammar for that language, installable with treesit-install-language-grammar. The author walks through a real snag where yaml-ts-mode didn’t advertise its grammar source, showing how to read the mode’s own source to find the correct repository, and notes that C-x x f can force fontification and prompt for every grammar a document requires.
The practical takeaway is that markdown-ts-mode’s power comes from composing with every other -ts-mode, so a Markdown buffer can highlight embedded code in its native language—but that same design means editing quality depends on having each relevant grammar compiled and installed. Users need Emacs built with tree-sitter support, a working toolchain (make, gcc), and ideally the tree-sitter CLI, whether they compile grammars themselves or pull prebuilt ones from a trusted source.
Read the full article
Continue reading at Hacker News →This is an AI-generated summary. Read the original for the full story.