Disable syntax guessing for PygmentsCodeFences by default
authorPhilipp Oppermann <dev@phil-opp.com>
Thu, 31 Mar 2016 11:14:57 +0000 (13:14 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Mon, 4 Apr 2016 20:19:36 +0000 (22:19 +0200)
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.

commands/hugo.go
docs/content/overview/configuration.md
helpers/content_renderer.go

index 131879ce936fee2cc59ac768ae36367d3bc66e3a..f7eb4cbc04d66f1dc5b16cc9b177531386369014 100644 (file)
@@ -309,6 +309,7 @@ func loadDefaultSettings() {
        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.
index 600e420d7618fae093af1522f26a8a0b37f5554d..33813beb44cd10ac4f7a399060f36e6820ffaaac 100644 (file)
@@ -126,6 +126,8 @@ Following is a list of Hugo-defined variables that you can configure and their c
     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
index 427bfc390a39e61a4cf9b829cc6291e6a6f2cec9..aedf0e1d0d8f37ec092e22abe2b8b16693aee8f7 100644 (file)
@@ -35,7 +35,7 @@ type HugoHTMLRenderer struct {
 }
 
 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 @@ type HugoMmarkHTMLRenderer struct {
 }
 
 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 {