From 4a2eda49cdd3180ab884a696ac987d7d6bb375db Mon Sep 17 00:00:00 2001 From: Anthony Fok Date: Tue, 4 Aug 2015 13:05:48 -0600 Subject: [PATCH] Add option to disable Blackfriday Smartypants Can be used in site config or per page front matter: ``` [blackfriday] smartypants = false ``` --- docs/content/overview/configuration.md | 34 ++++++++++++++++++-------- helpers/content.go | 7 +++++- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/docs/content/overview/configuration.md b/docs/content/overview/configuration.md index 4a718d194..a8100634d 100644 --- a/docs/content/overview/configuration.md +++ b/docs/content/overview/configuration.md @@ -165,6 +165,16 @@ But Hugo does expose some options---as listed in the table below, matched with t + +smartypants +true +HTML_USE_SMARTYPANTS + + +Purpose: +Enable enable smart punctuation substitutions. + + angledQuotes false @@ -190,16 +200,6 @@ Blackfriday would still convert 1/2, 1/4 and 3/4 to ½ (&frac12;< but only these three. - -hrefTargetBlank -false -HTML_HREF_TARGET_BLANK - - -Purpose: -Open external links in a new window/tab. - - latexDashes true @@ -210,6 +210,18 @@ but only these three. Disable LaTeX style dashes. + + + +hrefTargetBlank +false +HTML_HREF_TARGET_BLANK + + +Purpose: +Open external links in a new window/tab. + + plainIdAnchors false @@ -220,6 +232,8 @@ but only these three. If true, then header and footnote IDs are generated without the document ID (e.g. #my-header instead of #my-header:bec3ed8ba720b9073ab75abcf3ba5d97) + + extensions [] diff --git a/helpers/content.go b/helpers/content.go index 86c3f8c5a..8e3fda505 100644 --- a/helpers/content.go +++ b/helpers/content.go @@ -40,6 +40,7 @@ var SummaryDivider = []byte("") // Blackfriday holds configuration values for Blackfriday rendering. type Blackfriday struct { + Smartypants bool AngledQuotes bool Fractions bool HrefTargetBlank bool @@ -52,6 +53,7 @@ type Blackfriday struct { // NewBlackfriday creates a new Blackfriday with some sane defaults. func NewBlackfriday() *Blackfriday { return &Blackfriday{ + Smartypants: true, AngledQuotes: false, Fractions: true, HrefTargetBlank: false, @@ -148,9 +150,12 @@ func GetHTMLRenderer(defaultFlags int, ctx *RenderingContext) blackfriday.Render htmlFlags := defaultFlags htmlFlags |= blackfriday.HTML_USE_XHTML - htmlFlags |= blackfriday.HTML_USE_SMARTYPANTS htmlFlags |= blackfriday.HTML_FOOTNOTE_RETURN_LINKS + if ctx.getConfig().Smartypants { + htmlFlags |= blackfriday.HTML_USE_SMARTYPANTS + } + if ctx.getConfig().AngledQuotes { htmlFlags |= blackfriday.HTML_SMARTYPANTS_ANGLED_QUOTES }