{"id":20092357,"url":"https://github.com/rubixdev/syntastica-typst","last_synced_at":"2025-05-06T04:31:42.065Z","repository":{"id":217018046,"uuid":"695048454","full_name":"RubixDev/syntastica-typst","owner":"RubixDev","description":"Tree-sitter syntax highlighting for code blocks in Typst.","archived":false,"fork":false,"pushed_at":"2023-09-23T02:03:21.000Z","size":3596,"stargazers_count":10,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-05-21T12:52:47.500Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RubixDev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-09-22T08:38:42.000Z","updated_at":"2024-06-04T13:56:47.933Z","dependencies_parsed_at":null,"dependency_job_id":"3c0c29ca-83e6-4c67-9937-f24b5c71d22c","html_url":"https://github.com/RubixDev/syntastica-typst","commit_stats":null,"previous_names":["rubixdev/syntastica-typst"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RubixDev%2Fsyntastica-typst","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RubixDev%2Fsyntastica-typst/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RubixDev%2Fsyntastica-typst/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RubixDev%2Fsyntastica-typst/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RubixDev","download_url":"https://codeload.github.com/RubixDev/syntastica-typst/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252622084,"owners_count":21777917,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-13T16:36:45.347Z","updated_at":"2025-05-06T04:31:42.053Z","avatar_url":"https://github.com/RubixDev.png","language":"Rust","readme":"# `syntastica` for Typst\n\nTree-sitter syntax highlighting for code blocks.\n\n## Showcase\n\n![Comparison between normal and syntastica highlighting](https://raw.githubusercontent.com/RubixDev/syntastica-typst/main/examples/comparison.png)\n\n````typ\n#import \"syntastica.typ\": syntastica\n\n#set page(height: auto, width: auto, margin: 1cm)\n\nWithout `syntastica`:\n\n```rust\nfn fib(n: usize) -\u003e usize {\n    if n \u003c 2 {\n        n\n    } else {\n        fib(n - 1) + fib(n - 2)\n    }\n}\n```\n\n#show raw: syntastica\n\nWith `syntastica`:\n\n```rust\nfn fib(n: usize) -\u003e usize {\n    if n \u003c 2 {\n        n\n    } else {\n        fib(n - 1) + fib(n - 2)\n    }\n}\n```\n````\n\nFor more examples, have a look at the\n['examples'](https://github.com/RubixDev/syntastica-typst/tree/main/examples/)\ndirectory.\n\n## Installation\n\nDue to its large size, this package\n[was not accepted](https://github.com/typst/packages/pull/143) for the\n[official package repository](https://github.com/typst/packages). However, you\ncan still use it in one of two ways:\n\n### Option 1: Install as a local package\n\nIf you are using Typst locally, you can install this package to your local\npackage repository. The easiest way to do that is to clone this repository and\nrun the `install_local.sh` script (Linux only):\n\n```bash\ngit clone https://github.com/RubixDev/syntastica-typst\ncd syntastica-typst\n./install_local.sh\n```\n\nAlternatively you can manually create the appropriate directory as described\n[here](https://github.com/typst/packages#local-packages), and copy the following\nfiles from this repo into that folder:\n\n- [`typst.toml`](https://github.com/RubixDev/syntastica-typst/blob/main/typst.toml)\n- [`syntastica.typ`](https://github.com/RubixDev/syntastica-typst/blob/main/syntastica.typ)\n- [`syntastica_typst.wasm`](https://github.com/RubixDev/syntastica-typst/blob/main/syntastica_typst.wasm)\n\nAfter that is done, you can import the functions like this:\n\n```typ\n#import \"@local/syntastica:0.1.0\": syntastica, languages, themes, theme-bg, theme-fg\n```\n\n### Option 2: Copy the files into your project\n\nYou can also just simply copy the package files into your project and import\nthem like usual. Note that because this package uses a Wasm plugin, you must\ncopy that too.\n\nRequired files:\n\n- [`syntastica.typ`](https://github.com/RubixDev/syntastica-typst/blob/main/syntastica.typ)\n- [`syntastica_typst.wasm`](https://github.com/RubixDev/syntastica-typst/blob/main/syntastica_typst.wasm)\n\nImport with:\n\n```typ\n#import \"syntastica.typ\": syntastica, languages, themes, theme-bg, theme-fg\n```\n\n## Performance\n\nPlease bear in mind that this package is **slow**. And the more different\nlanguages you make use of, the slower it will get. This is actually somewhat\nfine when using an LSP, which will run the language initialization code in the\nplugin once, and then keep it in memory for following compilations.\n\nOne way to go about this is to add a top-level variable for toggling\n`syntastica` and only set it to `true` for production builds. See the\n[`prod_toggle` example](https://github.com/RubixDev/syntastica-typst/blob/main/examples/prod_toggle.typ)\nfor an implementation of this approach.\n\n\u003e [!NOTE] Typst 0.13.0 drastically improved performance of WebAssambly plugins,\n\u003e but sadly this package is still _very_ slow compared to not using it.\n\n## Usage\n\n### `syntastica`\n\nApply `syntastica` highlighting to a raw code element.\n\n```typ\n#let syntastica(it, theme: \"one::light\") = { ... }\n```\n\n**Arguments:**\n\n- `it`: [`content`] \u0026mdash; The\n  [raw element](https://typst.app/docs/reference/text/raw/) to apply\n  highlighting to.\n- `theme`: [`str`] \u0026mdash; The theme to use. See\n  [here](https://github.com/RubixDev/syntastica-typst/blob/main/examples/all_themes.pdf)\n  for a list of all themes.\n\n### `languages`\n\nGet a list of all supported languages.\n\n```typ\n#let languages() = { ... }\n```\n\n**Returns:** An [`array`] of [`str`]s.\n\n### `themes`\n\nGet a list of all supported themes.\n\n```typ\n#let themes() = { ... }\n```\n\n**Returns:** An [`array`] of [`str`]s.\n\n### `theme-bg`\n\nGet the default background color of a theme.\n\n```typ\n#let theme-bg(theme) = { ... }\n```\n\n**Arguments:**\n\n- `theme`: [`str`] \u0026mdash; The theme name.\n\n**Returns:** [`color`] or `none`\n\n### `theme-fg`\n\nGet the default foreground color of a theme.\n\n```typ\n#let theme-fg(theme) = { ... }\n```\n\n**Arguments:**\n\n- `theme`: [`str`] \u0026mdash; The theme name.\n\n**Returns:** [`color`] or `none`\n\n[`array`]: https://typst.app/docs/reference/foundations/array/\n[`str`]: https://typst.app/docs/reference/foundations/str/\n[`content`]: https://typst.app/docs/reference/foundations/content/\n[`color`]: https://typst.app/docs/reference/visualize/color/\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frubixdev%2Fsyntastica-typst","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frubixdev%2Fsyntastica-typst","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frubixdev%2Fsyntastica-typst/lists"}