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 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 ( TermFormatter = "terminal256" TermStyle = "base16-snazzy" )
View Source
const (
// MinimumContentGuessLength is the minimum length of the content to use Guesslang, smaller content will use the fallback lexer.
MinimumContentGuessLength = 64
)
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 Guesslang. If the content's mimetype is not detected as text/plain, it returns "binary"
func GetLexer ¶
func GetLexer(name string) chroma.Lexer
GetLexer returns the lexer for the given name, or the fallback lexer if the lexer is not found.
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.