diff options
-rw-r--r-- | commands/hugo.go | 1 | ||||
-rw-r--r-- | docs/content/overview/configuration.md | 2 | ||||
-rw-r--r-- | helpers/content_renderer.go | 4 |
3 files changed, 5 insertions, 2 deletions
diff --git a/commands/hugo.go b/commands/hugo.go index 131879ce9..f7eb4cbc0 100644 --- a/commands/hugo.go +++ b/commands/hugo.go @@ -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. diff --git a/docs/content/overview/configuration.md b/docs/content/overview/configuration.md index 600e420d7..33813beb4 100644 --- a/docs/content/overview/configuration.md +++ b/docs/content/overview/configuration.md @@ -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 diff --git a/helpers/content_renderer.go b/helpers/content_renderer.go index 427bfc390..aedf0e1d0 100644 --- a/helpers/content_renderer.go +++ b/helpers/content_renderer.go @@ -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 { |