Enable code highlighting with chroma

This commit is contained in:
Christian Muehlhaeuser
2019-11-25 05:47:14 +01:00
parent 16c2b7a239
commit e6a9122041
3 changed files with 52 additions and 0 deletions
+9
View File
@@ -9,6 +9,7 @@ import (
"strconv"
"strings"
"github.com/alecthomas/chroma/quick"
"github.com/logrusorgru/aurora"
bf "gopkg.in/russross/blackfriday.v2"
)
@@ -425,6 +426,14 @@ func (tr *TermRenderer) RenderNode(w io.Writer, node *bf.Node, entering bool) bf
}
for _, f := range e.Fragments {
if node.Type == bf.CodeBlock {
err := quick.Highlight(w, f.Token, string(node.CodeBlockData.Info), "terminal16m", "monokai")
if err == nil {
continue
}
// if chroma failed, render the fragment as text below
}
if f.Token == "" {
continue
}