tinymist/syntaxes/textmate
Myriad-Dreamin 4bfb5c22da
fix: stop atom expressions before backslash (#1835)
* fix: stop atom expressions before marks

* dev: fix it
2025-06-23 11:32:55 +08:00
..
scripts feat: add scripts to test syntax highlight (#1121) 2025-01-07 14:15:20 +08:00
tests fix: stop atom expressions before backslash (#1835) 2025-06-23 11:32:55 +08:00
.gitignore fix: exclude content block syntax when parsing math arguments (#1124) 2025-01-07 14:18:11 +08:00
feature.mts feat: stop expressions before hash and comma (#1129) 2025-01-08 11:26:44 +08:00
fenced.meta.mts docs: improve and add contribution guide for syntaxes (#471) 2024-07-27 23:04:52 +08:00
fenced.mts feat: add experimental math syntax highlighting (#1096) 2025-01-03 23:15:42 +08:00
main.mts fix: stop atom expressions before backslash (#1835) 2025-06-23 11:32:55 +08:00
package.json fix: vesrion in package.json files are wrong (#1834) 2025-06-22 22:31:36 +08:00
README.md docs: documenting textmate grammar (#1131) 2025-01-08 12:40:19 +08:00
textmate.mts docs: documenting textmate grammar (#1131) 2025-01-08 12:40:19 +08:00
tsconfig.json dev: fix errors after upgrading tsc and update resolution (#449) 2024-07-22 18:45:59 +08:00

Syntax Highlighting for Typst

This folder contains the syntax highlighting in the TextMate format for Typst.

To tackle challenge of making the complex grammar for typst markup, the grammar is described by neither JSON nor YAML, but a TypeScript generator program, the ./main.ts. TypeScript ensures correct grammar by static and strong types from ./textmate.ts.

Building

The following script running the TypeScript program will generate the TextMate grammar file:

yarn compile

Testing

// Run unit tests
yarn test
// Test on typst/typst
yarn test:official
// Test on typst/packages
yarn test:packages

Register languages for raw highlighting

Goto fenced.meta.mts and add a line like this:

{ "candidates": ["erlang"] }

Three possible kinds:

  • { candidates: ["someLanguage", ...rests] } - using textmate parser registered as source.someLanguage.
    • The rests of the candidates can also be used as language tag of fenced code blocks.
  • { as: "text.xxx", candidates } - using textmate parser registered as text.xxx.
  • { as: ["text.xxx", ...restScopes], candidates } - using textmate parser text.xxx first, and restScopes parsers in order.

GitHub Integration

A variant satisfying GitHub's requirement is managed on Typst Grammar Repo. You can check which version the repository is using by checking the build-ref.md or build-ref.json.

The grammar is built by the build branch's CI.

The grammar is tested continuously by the main branch's CI. Specifically, it is tested by the command in the CI script:

script/grammar-compiler add vendor/grammars/typst-grammar

You can setup your owned environment according to github-linguist's CONTRIBUTING.md to develop the variant locally.

Contributing

See CONTRIBUTING.md.