Documentation
¶
Index ¶
- Constants
- Variables
- func Analyze(content string) chroma.Lexer
- func DetectFileType(content []byte, hint string, useGuesser bool) string
- func GetLexer(name string) chroma.Lexer
- func GetStyle() *chroma.Style
- func GetSyntaxCSS() template.CSS
- func Guess(content string) string
- func ToMarkdown(fileContent []byte) (template.HTML, error)
- func ToSyntaxHighlightedHTML(fileType string, fileContent []byte) (template.HTML, error)
- func ToSyntaxHighlightedTerm(fileType string, fileContent []byte) (string, error)
Constants ¶
View Source
const (
// MinimumContentGuessLength is the minimum length of the content to use AI guessing, smaller content will use the fallback lexer.
MinimumContentGuessLength = 64
)
View Source
const TermFormatter = "terminal256"
Variables ¶
View Source
var BinaryHTMLPlaceholder = template.HTML(`
<div style="margin:2rem;text-align:center;">
<span role="img" aria-label="warning">⚠️</span>
The file is not displayed because it has been detected as binary data.
</div>
`)
View Source
var FallbackLexer chroma.Lexer = chroma.MustNewLexer(&chroma.Config{ Name: "plaintext", Filenames: []string{"*"}, Priority: -1, }, lexers.PlaintextRules)
Functions ¶
func DetectFileType ¶
DetectFileType returns the type of the file based on the content and the hint. If useGuesser is true, it will try to guess the type of the file using AI guessing. If the content's mimetype is not detected as text/plain, it returns "binary"
func GetLexer ¶
GetLexer returns the lexer for the given name, or the fallback lexer if the lexer is not found.
func GetSyntaxCSS ¶ added in v0.7.0
func ToSyntaxHighlightedHTML ¶
ToSyntaxHighlightedHTML returns HTML of the syntax highlighted code via Chroma
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.