Documentation
¶
Index ¶
- func DetectLanguage(path string) string
- func IsValidationSupported(language string) bool
- func SupportedValidationLanguages() []string
- type Highlighter
- func (h *Highlighter) Highlight(code string, language string) (string, error)
- func (h *Highlighter) HighlightAfterGlamour(renderedMarkdown string) string
- func (h *Highlighter) HighlightMarkdownCodeBlocks(markdown string) string
- func (h *Highlighter) HighlightMarkdownCodeBlocksPlain(markdown string) string
- type SyntaxError
- type ValidationResult
- type Validator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DetectLanguage ¶
DetectLanguage determines the programming language from file extension or filename. This is shared across syntax highlighting and validation to ensure consistency.
func IsValidationSupported ¶
IsValidationSupported checks if a language has tree-sitter validation support.
func SupportedValidationLanguages ¶
func SupportedValidationLanguages() []string
SupportedValidationLanguages returns the list of languages supported for syntax validation. This is a subset of all detected languages, limited to those with tree-sitter grammars.
Types ¶
type Highlighter ¶
type Highlighter struct {
// contains filtered or unexported fields
}
Highlighter provides syntax highlighting for code using tree-sitter
func NewHighlighter ¶
func NewHighlighter() *Highlighter
NewHighlighter creates a new syntax highlighter with support for multiple languages
func (*Highlighter) Highlight ¶
func (h *Highlighter) Highlight(code string, language string) (string, error)
Highlight applies syntax highlighting to code and returns an ANSI-colored string
func (*Highlighter) HighlightAfterGlamour ¶
func (h *Highlighter) HighlightAfterGlamour(renderedMarkdown string) string
HighlightAfterGlamour applies syntax highlighting to code blocks in markdown that has already been rendered by glamour. This function looks for code blocks in glamour's output format and applies highlighting to them.
DEPRECATED: This function is no longer used and doesn't work correctly. Glamour consumes markdown code fences during rendering, so this function cannot find code blocks in Glamour's output. Instead, syntax highlighting is now handled entirely by Glamour's built-in Chroma support. See commit history for context on the ANSI control sequence issue this was meant to solve.
func (*Highlighter) HighlightMarkdownCodeBlocks ¶
func (h *Highlighter) HighlightMarkdownCodeBlocks(markdown string) string
HighlightMarkdownCodeBlocks finds all code blocks in markdown and applies syntax highlighting
func (*Highlighter) HighlightMarkdownCodeBlocksPlain ¶
func (h *Highlighter) HighlightMarkdownCodeBlocksPlain(markdown string) string
HighlightMarkdownCodeBlocksPlain highlights code blocks and returns them without markdown fencing This is useful for displaying code directly in the terminal without markdown rendering
type SyntaxError ¶
type SyntaxError struct {
Line int `json:"line"`
Column int `json:"column"`
Message string `json:"message"`
ErrorNode string `json:"error_node"` // Type of error node (e.g., "ERROR", "MISSING")
}
SyntaxError represents a single syntax error found during validation.
type ValidationResult ¶
type ValidationResult struct {
Valid bool `json:"valid"`
Errors []SyntaxError `json:"errors,omitempty"`
Language string `json:"language"`
ParsedBytes int `json:"parsed_bytes"`
}
ValidationResult contains the results of syntax validation.
type Validator ¶
type Validator struct {
// contains filtered or unexported fields
}
Validator provides syntax validation for code using tree-sitter parsers.
func NewValidator ¶
func NewValidator() *Validator
NewValidator creates a new syntax validator with support for multiple languages.
func (*Validator) SupportsLanguage ¶
SupportsLanguage checks if the validator supports a given language.
func (*Validator) Validate ¶
func (v *Validator) Validate(code string, language string) (*ValidationResult, error)
Validate validates code syntax using tree-sitter. Returns a ValidationResult with syntax errors, if any.
func (*Validator) ValidateFile ¶
func (v *Validator) ValidateFile(ctx context.Context, readFile func(context.Context, string) ([]byte, error), path string) (*ValidationResult, error)
ValidateFile validates a file's syntax. This is a convenience method that can be used when the file system is available.