Skip to content

gsxhq/gsxhl

Repository files navigation

gsxhl

Syntax highlighting for gsx source, built on tree-sitter. Renders to HTML with semantic classes, so one stylesheet themes light and dark without re-highlighting.

h, err := gsxhl.New()
if err != nil {
	return err
}
html, err := h.Highlight(gsxhl.LangGSX, source)
// <span class="ts-keyword">component</span> <span class="ts-function">Card</span>…

Highlight returns inner HTML only — wrap it in your own <pre><code>.

Languages

Constant Covers
LangGSX gsx markup and Go — the gsx grammar parses Go natively
LangCSS standalone CSS
LangJS standalone JavaScript

Inside gsx source, CSS and JavaScript are injected automatically into <style>/<script> bodies and css`…` /js`…` literals. Because Go is native to the grammar, a plain .go snippet highlights through LangGSX with no separate configuration.

Styling

Every token carries a ts- class derived from its tree-sitter capture: ts-keyword, ts-tag, ts-attribute, ts-function-method, and so on. CaptureNames() returns every capture the package can emit, in highlight order — useful for generating a stylesheet that covers all of them.

.ts-keyword { color: #7c3aed; }
.ts-tag     { color: #1e3a8a; }

cgo

tree-sitter is C, so this package requires cgo. Callers that ship a CGO_ENABLED=0 binary (a static/distroless server, say) should highlight at build time and embed the resulting HTML, rather than linking this in.

Queries

The gsx highlight and injection queries arrive with the parser from tree-sitter-gsx, so they can never disagree with the grammar they run against. The CSS and JavaScript queries are copies — //go:embed cannot read across module boundaries — refreshed with make sync-queries and checked against their pinned grammars by TestQueriesCompile.

About

Syntax highlighting for gsx

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages