Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable syntax guessing for PygmentsCodeFences #2034

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions commands/hugo.go
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions docs/content/overview/configuration.md
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions helpers/content_renderer.go
Expand Up @@ -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))
Expand Down Expand Up @@ -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 {
Expand Down