Skip to content

Add templ lexer - #1277

Closed
bryce-d-greybeard wants to merge 1 commit into
alecthomas:masterfrom
bryce-d-greybeard:add-templ-lexer
Closed

Add templ lexer#1277
bryce-d-greybeard wants to merge 1 commit into
alecthomas:masterfrom
bryce-d-greybeard:add-templ-lexer

Conversation

@bryce-d-greybeard

Copy link
Copy Markdown
Contributor

Summary

Adds a lexer for templ, the Go HTML component/template language used by *.templ files.

The lexer handles templ declarations, Go-like control/code expressions, component calls such as @Button(...), and delegates ordinary HTML markup/text to the existing HTML lexer.

Tests

  • go test ./lexers
  • go test ./...

@alecthomas

Copy link
Copy Markdown
Owner

Is there a reason this is a Go lexer and not an XML lexer? If there isn't a good reason, please convert it.

@alecthomas alecthomas closed this Jun 5, 2026
@alecthomas

Copy link
Copy Markdown
Owner

Feel free to reopen with an XML lexer.

alecthomas pushed a commit that referenced this pull request Jun 8, 2026
Adds a templ lexer as an XML lexer definition under
`lexers/embedded/templ.xml`.

This replaces the earlier Go-based lexer approach from #1277, following
maintainer feedback to use an XML lexer instead.

Includes fixtures for:
- templ component declarations
- HTML tags and attributes
- Go expressions in `{ ... }`
- braced attribute values
- templ control flow (`if` / `else`)
- component calls with `@Button(...)`
- analyser coverage

Local test gates:
- `go test ./lexers -count=1`
- `go test ./... -count=1`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants