ref: 43b5dfabb5fb36bb4574289912c66a46ef20ffce
parent: 0698f294c6d335031951f1cb528c90f2a120eebb
author: Philipp Oppermann <[email protected]>
date: Thu Mar 31 09:14:57 EDT 2016
Disable syntax guessing for PygmentsCodeFences by default This disables highlighting for fenced code blocks without explicitly specified language. It also introduces a new `PygmentsCodeFencesGuessSyntax` config option (defaulting to false). To enable syntax guessing again, add the following to your config file: `PygmentsCodeFencesGuessSyntax = true` This is a breaking change.
--- a/commands/hugo.go
+++ b/commands/hugo.go
@@ -309,6 +309,7 @@
viper.SetDefault("DisablePathToLower", false)
viper.SetDefault("HasCJKLanguage", false)
viper.SetDefault("EnableEmoji", false)
+ viper.SetDefault("PygmentsCodeFencesGuessSyntax", false)
}
// InitializeConfig initializes a config file with sensible default configuration flags.
--- a/docs/content/overview/configuration.md
+++ b/docs/content/overview/configuration.md
@@ -126,6 +126,8 @@
preserveTaxonomyNames: false
# filesystem path to write files to
publishdir: "public"
+ # enables syntax guessing for code fences without specified language
+ pygmentsCodeFencesGuessSyntax: false
# color-codes for highlighting derived from this style
pygmentsStyle: "monokai"
# true: use pygments-css or false: color-codes directly
--- a/helpers/content_renderer.go
+++ b/helpers/content_renderer.go
@@ -35,7 +35,7 @@
}
func (renderer *HugoHTMLRenderer) BlockCode(out *bytes.Buffer, text []byte, lang string) {
- if viper.GetBool("PygmentsCodeFences") {
+ if viper.GetBool("PygmentsCodeFences") && (lang != "" || viper.GetBool("PygmentsCodeFencesGuessSyntax")) {
opts := viper.GetString("PygmentsOptions")
str := html.UnescapeString(string(text))
out.WriteString(Highlight(str, lang, opts))
@@ -78,7 +78,7 @@
}
func (renderer *HugoMmarkHTMLRenderer) BlockCode(out *bytes.Buffer, text []byte, lang string, caption []byte, subfigure bool, callouts bool) {
- if viper.GetBool("PygmentsCodeFences") {
+ if viper.GetBool("PygmentsCodeFences") && (lang != "" || viper.GetBool("PygmentsCodeFencesGuessSyntax")) {
str := html.UnescapeString(string(text))
out.WriteString(Highlight(str, lang, ""))
} else {