syntax highlight via bfchroma
This commit is contained in:
17
main.go
17
main.go
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user