syntax highlight via bfchroma

This commit is contained in:
Sebastian Frank
2019-02-18 18:02:35 +01:00
parent 5409a62021
commit 1187291938
2 changed files with 18 additions and 131 deletions

17
main.go
View File

@@ -11,6 +11,7 @@ import (
"github.com/imdario/mergo"
"github.com/Depado/bfchroma"
"github.com/davecgh/go-spew/spew"
"github.com/flosch/pongo2"
"github.com/gosimple/slug"
@@ -94,6 +95,10 @@ type PathConfig struct {
OutputExtension *string `yaml:"OutputExtension"`
} `yaml:"Filename"`
Markdown struct {
SyntaxHighlight *bool `yaml:"SyntaxHighlight"`
} `yaml:"Markdown"`
Data interface{} `yaml:"Data"`
}
@@ -430,15 +435,21 @@ RewriteRule ^$ %{REQUEST_URI}`+goToFixed+`/ [R,L]
outFile := conf.OutputPath + "/" + outputFilename
log.Debugf("using '%s' as output file", outFile)
//html := blackfriday.Run(input, blackfriday.WithRenderer(bfchroma.NewRenderer()))
html := blackfriday.Run(input)
var option blackfriday.Option
synH := conf.Config.Markdown.SyntaxHighlight
if synH != nil && *synH {
option = blackfriday.WithRenderer(bfchroma.NewRenderer())
}
html := blackfriday.Run(input, option)
// use --- for splitting document in markdown parts
regex := regexp.MustCompile("\\r?\\n\\r?---\\r?\\n\\r?")
inputParts := regex.Split(string(input), -1)
htmlParts := make([]*pongo2.Value, 0)
for _, iPart := range inputParts {
htmlParts = append(htmlParts, pongo2.AsSafeValue(string(blackfriday.Run([]byte(iPart)))))
htmlParts = append(htmlParts, pongo2.AsSafeValue(string(blackfriday.Run([]byte(iPart), option))))
}
log.Debugf("rendering template '%s' for '%s'", *newConfig.Template, outFile)