2015-07-03 17:53:50 -04:00
|
|
|
package helpers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"html"
|
|
|
|
|
|
|
|
"github.com/russross/blackfriday"
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
)
|
|
|
|
|
2015-08-07 14:09:40 -04:00
|
|
|
// Wraps a blackfriday.Renderer, typically a blackfriday.Html
|
|
|
|
type HugoHtmlRenderer struct {
|
2015-07-03 17:53:50 -04:00
|
|
|
blackfriday.Renderer
|
|
|
|
}
|
|
|
|
|
2015-08-07 14:09:40 -04:00
|
|
|
func (renderer *HugoHtmlRenderer) BlockCode(out *bytes.Buffer, text []byte, lang string) {
|
2015-07-03 17:53:50 -04:00
|
|
|
if viper.GetBool("PygmentsCodeFences") {
|
|
|
|
str := html.UnescapeString(string(text))
|
|
|
|
out.WriteString(Highlight(str, lang, ""))
|
|
|
|
} else {
|
|
|
|
renderer.Renderer.BlockCode(out, text, lang)
|
|
|
|
}
|
|
|
|
}
|