diff options
-rw-r--r-- | commands/hugo.go | 1 | ||||
-rw-r--r-- | helpers/content.go | 5 | ||||
-rw-r--r-- | helpers/content_renderer.go | 23 |
3 files changed, 28 insertions, 1 deletions
diff --git a/commands/hugo.go b/commands/hugo.go index c57f5fe4e..cc4e19516 100644 --- a/commands/hugo.go +++ b/commands/hugo.go @@ -148,6 +148,7 @@ func LoadDefaultSettings() { viper.SetDefault("PygmentsStyle", "monokai") viper.SetDefault("DefaultExtension", "html") viper.SetDefault("PygmentsUseClasses", false) + viper.SetDefault("PygmentsCodeFences", false) viper.SetDefault("DisableLiveReload", false) viper.SetDefault("PluralizeListTitles", true) viper.SetDefault("PreserveTaxonomyNames", false) diff --git a/helpers/content.go b/helpers/content.go index cd4563441..a846d2fa1 100644 --- a/helpers/content.go +++ b/helpers/content.go @@ -167,9 +167,12 @@ func GetHTMLRenderer(defaultFlags int, ctx *RenderingContext) blackfriday.Render htmlFlags |= blackfriday.HTML_SMARTYPANTS_LATEX_DASHES } - return blackfriday.HtmlRendererWithParameters(htmlFlags, "", "", renderParameters) + return &HugoHtmlRenderer{ + blackfriday.HtmlRendererWithParameters(htmlFlags, "", "", renderParameters), + } } + func getMarkdownExtensions(ctx *RenderingContext) int { flags := 0 | blackfriday.EXTENSION_NO_INTRA_EMPHASIS | blackfriday.EXTENSION_TABLES | blackfriday.EXTENSION_FENCED_CODE | diff --git a/helpers/content_renderer.go b/helpers/content_renderer.go new file mode 100644 index 000000000..bb5b810ae --- /dev/null +++ b/helpers/content_renderer.go @@ -0,0 +1,23 @@ +package helpers + +import ( + "bytes" + "html" + + "github.com/russross/blackfriday" + "github.com/spf13/viper" +) + +// Wraps a blackfriday.Renderer, typically a blackfriday.Html +type HugoHtmlRenderer struct { + blackfriday.Renderer +} + +func (renderer *HugoHtmlRenderer) BlockCode(out *bytes.Buffer, text []byte, lang string) { + if viper.GetBool("PygmentsCodeFences") { + str := html.UnescapeString(string(text)) + out.WriteString(Highlight(str, lang, "")) + } else { + renderer.Renderer.BlockCode(out, text, lang) + } +} |