百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
T

tree-sitter-typst

> 开发工具
开源

Typst 的树坐者语法

189 stars0 点赞3 次浏览
访问官网GitHub

工具介绍

Typst 的树坐者语法

A Typst grammar for Tree-Sitter

Typst official page https://typst.app

Tree-Sitter documentation page https://tree-sitter.github.io

Typst doesn't have yet an official Tree-Sitter grammar. This grammar is complete but may contains bug as it is very recent.

Get involved

Your help is welcome. You don't have to know anything about Tree-Sitter to help. You just have to use this grammar and report any bad highlighting you see! You can open an issue or simply send me by email the Typst code causing the bug. See below installation instructions for this grammar. Even if your not sure it is a bug, it doesn't hurt to repport it.

I need help to:

  • write the different "queries" for the different editors like Neovim or Helix. Indeed, the queries like the highlights or the indentation may vary between editors.
  • have more tests, by either directly writing some or by improving https://github.com/uben0/tree-sitter-typst-utils/tree/main/test-gen
  • implement the full rewrite on branch rewrite. This time the code is documented and you may get involve however you want. Ask me how to help, ask me what needs to be explained and documented. I aim at making this new implementation maintainable by the community.

Don't hesitate to contact me (mailto:[email protected]) or to open an issue, even if you're not sure. It doesn't hurt.

The documentation of the current implementation (not the rewrite) is available in DOC. But I suggest to ignore the current implementation as it is a spaghetti mess. However, the DOC brings up interesting chalenges.

TODO

  • Update 0.13
    • Identify changes
  • More tests, objectif 1000, current 433
    • generate tests from official Typst parser. https://github.com/uben0/tree-sitter-typst-utils/tree/main/test-gen
  • Editor support
    • Helix
    • Emacs
    • NeoVim
  • Simplification
    • Full rewrite for a correct and maintainable code base (on branch rewrite)
    • Implement a type 3/4 parser generator (work in progress). The rewrite have a lexer based on the official parser but may benefit from automatic code generation.
    • Migrate all lexing to external scanner (work in progress on rewrite branch)

Features

  • Markup mode
  • Code mode
  • Math mode
  • Indentation
  • Foldable sections
  • Unicode characters

Installation

Language Server

Having syntax highlighting is great but having syntax highlighting and the language server is even greater. If you have cargo installed (Rust's package manager), you can install Typst language server with the following command (you don't have to be in any particular directory):

bash
cargo install --git https://github.com/Myriad-Dreamin/tinymist --locked tinymist

Neovim

The https://github.com/nvim-treesitter/nvim-treesitter provides this grammar.

Emacs

Typst support for Emacs is available through the following package:

typst-ts-mode

scheme
(use-package typst-ts-mode
  :elpaca (:type git :host sourcehut :repo "meow_king/typst-ts-mode")
  :custom
  (typst-ts-mode-watch-options "--open"))

Helix

This grammar is already builtin Helix. But it might not be up to date. To manyally install it:

  1. Locate the configuration directory:
  • Local ~/.config/helix
  • Global /usr/share/helix
  1. Append the following configuration to the languages.toml file (create it if it doesn't exist).
toml
[[language]]
name = "typst"
scope = "source.typst"
file-types = ["typst", "typ"]
indent = { tab-width = 2, unit = "  " }
comment-token = "//"
injection-regex = "typ(st)?"
roots = ["typst.toml"]
language-servers = [ "typst-lsp" ]

[language.auto-pairs]
'(' = ')'
'{' = '}'
'[' = ']'
'$' = '$'
'"' = '"'

[[grammar]]
name = "typst"
source.git = "https://github.com/uben0/tree-sitter-typst"
source.rev = "master"
  1. Copy the content of the queries directory (highlights.scm and injections.scm) inside your corresponding runtime/queries/typst directory. You should have the following structure:
config.toml
languages.toml
runtime
└── queries
    └── typst
        ├── highlights.scm
        └── injections.scm
  1. And finally execute (you don't have to be in any particular directory):
bash
hx --grammar fetch
hx --grammar build

The fetch command will clone the git repository, and the build command will compile the grammar. Open the logs to have insightfull messages in case it doesn't work.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Ceditorshelix-editortree-sittertree-sitter-parser

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类开发工具
定价开源

> 相关工具

V
VS Code
流行的开源代码编辑器
G
Git
分布式版本控制系统
V
Vite
下一代前端构建工具