From a22809f00e56469907468138c656e87fdd356c3a Mon Sep 17 00:00:00 2001 From: bratekarate Date: Thu, 29 Aug 2024 00:47:21 +0200 Subject: [PATCH] Enable inline css styles if -style argument is given. --- main.go | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/main.go b/main.go index 2463961..821423f 100644 --- a/main.go +++ b/main.go @@ -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()