Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Highlight ¶
func Highlight(cfg types.Configuration, source string, injectionCallback types.InjectionCallback, attributeCallback types.AttributeCallback) (string, error)
Highlight highlights the given source code using the given configuration. The source code is expected to be UTF-8 encoded. The function returns the highlighted HTML or an error.
cfg := tsh.NewConfiguration(...)
source := "..."
injectionCallback := func(languageName string) *Configuration { ... }
attributeCallback := func(h uint, languageName string) string { ... }
highlighted, err := tsh.Highlight(cfg, source, injectionCallback, attributeCallback)
func NewConfiguration ¶
func NewConfiguration(lang Language, recognisedNames []string) (*types.Configuration, error)
NewConfiguration creates a new highlight configuration from a Language and a list of recognised names.
lang := tsh.NewLanguage(...)
recognisedNames := []string{"function", "variable", "keyword", ...}
cfg, err := tsh.NewConfiguration(lang, recognisedNames)
Types ¶
type Language ¶
type Language struct {
Name string
HighlightsQuery []byte
InjectionQuery []byte
LocalsQuery []byte
Lang *tree_sitter.Language
}
A language object. This collects all the fields used in this library into a single struct for easier usage and cleaner code. This includes the Name, the HighlightsQuery, InjectionQuery and LocalsQuery, and the tree_sitter.Language in Lang.
func NewLanguage ¶
func NewLanguage(name string, ptr unsafe.Pointer, highlightsQuery, injectionQuery, localsQuery []byte) Language
This function is used to create a new Language. highlightsQuery, injectionQuery, and localsQuery can all be nil, though highlightsQuery being nil wouldn't serve much purpose in a syntax highlighter.
highlightsQuery := []byte("...")
injectionQuery := []byte("...")
localsQuery := []byte("...")
lang := tsh.NewLanguage("go", tree_sitter_go.Language(), highlightsQuery, injectionQuery, localsQuery)
Source Files
¶
- config.go
- highlight.go
- language.go