mdchroma
Integrating Chroma syntax highlighter as
a Go Markdown renderer.
Install and prerequisites
This project requires and uses the
Go Markdown package.
$ go get -u github.com/saward/mdchroma
This project uses the module approach of go 1.11
Features
This renderer integrates chroma to highlight code with triple backtick notation.
It will try to use the given language when available otherwise it will try to
detect the language. If none of these two method works it will fallback to sane
defaults.
This is a fork of the mdchroma package,
modified to instead work with
Go Markdown.
Usage
output := markdown.ToHTML(md, nil, mdchroma.NewRenderer())
Examples
package main
import (
"fmt"
chroma "github.com/saward/mdchroma"
"github.com/gomarkdown/markdown"
)
var md = "This is some sample code.\n\n```go\n" +
`func main() {
fmt.Println("Hi")
}
` + "```"
func main() {
html := markdown.ToHTML([]byte(md), nil, chroma.NewRenderer())
fmt.Println(string(html))
}
Will output :
<p>This is some sample code.</p>
<pre style="color:#f8f8f2;background-color:#272822"><span style="color:#66d9ef">func</span> <span style="color:#a6e22e">main</span>() {
<span style="color:#a6e22e">fmt</span>.<span style="color:#a6e22e">Println</span>(<span style="color:#e6db74">"Hi"</span>)
}
</pre>