|
||
---|---|---|
.. | ||
scripts | ||
tests | ||
.gitignore | ||
feature.mts | ||
fenced.meta.mts | ||
fenced.mts | ||
main.mts | ||
package.json | ||
README.md | ||
textmate.mts | ||
tsconfig.json |
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 assource.someLanguage
.- The
rests
of the candidates can also be used as language tag of fenced code blocks.
- The
{ as: "text.xxx", candidates }
- using textmate parser registered astext.xxx
.{ as: ["text.xxx", ...restScopes], candidates }
- using textmate parsertext.xxx
first, andrestScopes
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.