Disable syntax highlighting when output is no terminal

This commit is contained in:
Christian Muehlhaeuser
2019-11-25 07:58:13 +01:00
parent ef9ee10b74
commit 4de0a10e9e
+7 -6
View File
@@ -433,18 +433,19 @@ func (tr *TermRenderer) RenderNode(w io.Writer, node *bf.Node, entering bool) bf
for _, f := range e.Fragments { for _, f := range e.Fragments {
if node.Type == bf.CodeBlock { if node.Type == bf.CodeBlock {
theme := "monokai" theme := ""
if rules, ok := tr.style[f.Style]; ok { if rules, ok := tr.style[f.Style]; ok {
if len(rules.Theme) > 0 { if len(rules.Theme) > 0 {
theme = rules.Theme theme = rules.Theme
} }
} }
if len(theme) > 0 {
err := quick.Highlight(w, f.Token, string(node.CodeBlockData.Info), "terminal16m", theme) err := quick.Highlight(w, f.Token, string(node.CodeBlockData.Info), "terminal16m", theme)
if err == nil { if err == nil {
continue continue
}
// if chroma failed, render the fragment as text below
} }
// if chroma failed, render the fragment as text below
} }
if f.Token == "" { if f.Token == "" {