2 stable releases

2.2.0 Oct 6, 2024
2.1.0 Aug 30, 2024

#114 in Text editors

Download history 117/week @ 2024-08-27 5/week @ 2024-09-03 7/week @ 2024-09-10 7/week @ 2024-09-17 12/week @ 2024-09-24 137/week @ 2024-10-01 34/week @ 2024-10-08

102 downloads per month

MIT license

2.5MB
95K SLoC

C 94K SLoC // 0.0% comments JavaScript 354 SLoC // 0.2% comments Scheme 68 SLoC // 0.0% comments Rust 30 SLoC // 0.1% comments

tree-sitter-templ

A tree-sitter grammar for Templ.

Using this with Neovim

To use this parser for syntax highlighting in Neovim, you need nvim-treesitter. It is highly recommended you go through nvim-treesitter's quickstart, but in any case a minimal configuration to enable syntax highlighting looks like this:

require'nvim-treesitter.configs'.setup {
  highlight = {
    enable = true,
    additional_vim_regex_highlighting = false,
  },
}

Once nvim-treesitter is installed you need to install the parser with the command :TSInstall templ.

You can check its status with :checkhealth, you should see something like this:

nvim-treesitter: require("nvim-treesitter.health").check()

Installation ~
- OK `tree-sitter` found 0.20.8 (parser generator, only needed for :TSInstallFromGrammar)
- OK `node` found v18.16.1 (only needed for :TSInstallFromGrammar)
- OK `git` executable found.
- OK `cc` executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl", "zig" }
  Version: cc (GCC) 13.1.1 20230614 (Red Hat 13.1.1-4)
- OK Neovim was compiled with tree-sitter runtime ABI version 14 (required >=13). Parsers must be compatible with runtime ABI.

Parser/Features         H L F I J
  - templ               ✓ . . . ✓

  Legend: H[ighlight], L[ocals], F[olds], I[ndents], In[j]ections
         +) multiple parsers found, only one will be used
         x) errors found in the query, try to run :TSUpdate {lang} ~

If you are runnning Neovim stable then you also need to add register the templ filetype

vim.filetype.add({
    extension = {
        templ = "templ",
    },
})

Note: _This is not required for nightly builds > NVIM v0.10.0-dev-3070+gcf9f002f3 (3rd May 2024)

Finally you can open a templ file and run :InspectTree to see the parse tree.

Contributing

The official tree-sitter documentation for creating a parser contains everything you need to start contributing to this parser.

To make it slightly easier, we use a Justfile to simplify some things:

  • just test [filter...] to run tests
  • just gen to only generate the parser
  • just build to generate then build the parser

If you want to modify the parser, make sure to add a test or modify an existnig one in the corpus directory.

Dependencies