树座器的 Templ 语法
A tree-sitter grammar for Templ.
To use this parser for syntax highlighting in Neovim, you need nvim-treesitter.
First, install nvim-treesitter. If using lazy.nvim:
require('lazy').setup({
{
'nvim-treesitter/nvim-treesitter',
lazy = false,
branch = 'main',
build = ':TSUpdate'
}
})Then install the Templ parser:
require('nvim-treesitter').install({ 'templ' })Finally, enable syntax highlighting for Templ files by adding this autocmd:
vim.api.nvim_create_autocmd('FileType', {
pattern = 'templ',
callback = function()
vim.treesitter.start()
end,
})If you want to use a specific branch, version, or local development path, you can manually configure the parser:
vim.api.nvim_create_autocmd('User', {
pattern = 'TSUpdate',
callback = function()
require('nvim-treesitter.parsers').templ = {
install_info = {
url = 'https://github.com/vrischmann/tree-sitter-templ',
branch = 'main', -- or specific branch/tag
-- path = "~/dev/perso/projects/tree-sitter-templ", -- for local development
queries = 'queries/templ',
},
}
end
})Then run :TSInstall templ to install the parser with your custom configuration.
You can check its status with :checkhealth, you should see something like this:
…Finally you can open a templ file and run :InspectTree to see the parse tree.
The official tree-sitter documentation for creating a parser contains everything you need to start contributing to this parser.
To make it easier, we use a Justfile to simplify some tasks:
just test [filter...] to run testsjust gen to generate the parserjust build to generate and build the parserIf you want to modify the parser, make sure to add a test or modify an existing one in the corpus directory.
暂无开放 Issues,或尚未同步最近议题。