types

package
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 21, 2025 License: Apache-2.0 Imports: 1 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AttributeCallback

type AttributeCallback func(h uint, languageName string) string

This runs for every single output `<span>` element, and is used to add attributes to the element. You can use this to add class names, inline styles based on a theme, or whatever else you'd like. For example, if you return `class="ts-highlight"` from inside the function, every `<span>` element in your output will look like `<span class="ts-highlight">`.

highlightNames := []string{"function", "variable", "keyword", "constant"}
var attributeCallback AttributeCallback = func(h uint, languageName string) string {
	return fmt.Sprintf(`data-lang="%s" class="%s"`, languageName, highlightNames[i])
}

type Configuration

type Configuration struct {
	Language                      *tree_sitter.Language
	LanguageName                  string
	Query                         *tree_sitter.Query
	CombinedInjectionsQuery       *tree_sitter.Query
	LocalsPatternIndex            uint
	HighlightsPatternIndex        uint
	HighlightIndices              []*uint
	NonLocalVariablePatterns      []bool
	InjectionContentCaptureIndex  *uint
	InjectionLanguageCaptureIndex *uint
	LocalScopeCaptureIndex        *uint
	LocalDefCaptureIndex          *uint
	LocalDefValueCaptureIndex     *uint
	LocalRefCaptureIndex          *uint
}

type InjectionCallback

type InjectionCallback func(languageName string) *Configuration

This function runs when tree-sitter encounters an injection. This is when another language is embedded into one currently being parsed. For example, CSS and JS can be embedded into HTML. If you were parsing HTML, this function would run when it encountered CSS or JS, provided it was included in `injections.scm`. Simply return a new Configuration from inside the function for the new language.

recognisedNames := []string{"function", "variable", "keyword", "constant"}
var injectionCallback InjectionCallback = func(languageName string) *Configuration {
	lang, _ := languages.Get(languageName)
	config, _ := NewConfiguration(lang, recognisedNames)
	return config
}

Source Files

  • types.go

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL