Enable inline css styles if -style argument is given.

This commit is contained in:
bratekarate 2024-08-29 00:47:21 +02:00
parent cd31fa00c5
commit a22809f00e
No known key found for this signature in database
GPG Key ID: 7FA4488395F8E7F3
1 changed files with 13 additions and 9 deletions

22
main.go
View File

@ -56,13 +56,17 @@ func highlight(w io.Writer, source, lexer, style string) error {
}
l = chroma.Coalesce(l)
// Determine formatter.
f := html.New(html.WithClasses(true), html.TabWidth(4))
// Determine style.
s := styles.Get(style)
if s == nil {
s = styles.Fallback
// Determine formatter and style, depending on whether a specific style is
// requested. If no style is requestd, use classes instead of inline css,
// leaving the CSS handling to the consumer.
var f *html.Formatter
var s *chroma.Style
if style == "" {
f = html.New(html.WithClasses(true))
s = new(chroma.Style)
} else {
f = html.New()
s = styles.Get(style)
}
it, err := l.Tokenise(nil, source)
@ -72,11 +76,11 @@ func highlight(w io.Writer, source, lexer, style string) error {
return f.Format(w, s, it)
}
const Version = "0.0"
const Version = "0.1"
func main() {
css := flag.String("css", "", "Path to a CSS import to include at the beginning of the output")
style := flag.String("style", "native", "CSS style to use")
style := flag.String("style", "", "CSS style to use")
version := flag.Bool("version", false, "Print the version string")
v := flag.Bool("v", false, "Print the version string")
flag.Parse()