diff options
author | Anthony Fok <foka@debian.org> | 2015-01-24 22:37:02 +0300 |
---|---|---|
committer | bep <bjorn.erik.pedersen@gmail.com> | 2015-01-24 22:57:40 +0300 |
commit | eb686352b1785844778e1cba8c69b85079e3044f (patch) | |
tree | 02dbeddba582ad3a61b2f6a940b065c6ef99ef88 | |
parent | 803865f870f9d0b4aa0015b6bdec15d37c2fab00 (diff) |
Add site-wide/per-page [blackfriday] `fractions` option
Make Blackfriday's `HTML_SMARTYPANTS_FRACTIONS` option
user-configurable. Defaults to `true` as before. See
discussions at:
http://discuss.gohugo.io/t/any-way-to-disable-smart-fractions/328
Thanks to @bjornerik and @spf13 for laying the groundwork
making it easy to expose Blackfriday's underlying configurable
options.
-rw-r--r-- | commands/hugo.go | 2 | ||||
-rw-r--r-- | docs/content/overview/configuration.md | 21 | ||||
-rw-r--r-- | helpers/content.go | 11 |
3 files changed, 29 insertions, 5 deletions
diff --git a/commands/hugo.go b/commands/hugo.go index 7aaa0dde6..f57a7c910 100644 --- a/commands/hugo.go +++ b/commands/hugo.go @@ -136,7 +136,7 @@ func InitializeConfig() { viper.SetDefault("FootnoteAnchorPrefix", "") viper.SetDefault("FootnoteReturnLinkContents", "") viper.SetDefault("NewContentEditor", "") - viper.SetDefault("Blackfriday", map[string]bool{"angledQuotes": false, "plainIdAnchors": false}) + viper.SetDefault("Blackfriday", map[string]bool{"angledQuotes": false, "fractions": true, "plainIdAnchors": false}) if hugoCmdV.PersistentFlags().Lookup("buildDrafts").Changed { viper.Set("BuildDrafts", Draft) diff --git a/docs/content/overview/configuration.md b/docs/content/overview/configuration.md index 4e4b750c1..a07ef5672 100644 --- a/docs/content/overview/configuration.md +++ b/docs/content/overview/configuration.md @@ -92,6 +92,21 @@ But Hugo does expose some options---as listed in the table below, matched with t </tr> <tr> +<td><code>fractions</code></td> +<td><code>true</code></td> +<td><code>HTML_SMARTYPANTS_FRACTIONS</code></td> +</tr> +<tr> +<td class="purpose-title">Purpose:</td> +<td class="purpose-description" colspan="2">Enable smart fractions +<small>(e.g. <code>5/12</code> renders to <sup>5</sup>⁄<sub>12</sub> (<code><sup>5</sup>&frasl;<sub>12</sub></code>)) +<strong>Caveat:</strong> Even with <code>fractions = false</code>, +Blackfriday would still convert 1/2, 1/4 and 3/4 to ½ (<code>&frac12;</code>), +¼ (<code>&frac14;</code>) and ¾ (<code>&frac34;</code>) respectively, +but only these three.</small></td> +</tr> + +<tr> <td><code>plainIdAnchors</code></td> <td><code>false</code></td> <td><code>FootnoteAnchorPrefix</code> and <code>HeaderIDSuffix</code></td> @@ -112,11 +127,13 @@ But Hugo does expose some options---as listed in the table below, matched with t </tr> <tr> <td><pre><code>[blackfriday] - angledQuotes = true - plainIdAnchors = true + angledQuotes = true + fractions = false + plainIdAnchors = true </code></pre></td> <td><pre><code>blackfriday: angledQuotes: true + fractions: false plainIdAnchors: true </code></pre></td> </tr> diff --git a/helpers/content.go b/helpers/content.go index 1d051801d..4f378c82b 100644 --- a/helpers/content.go +++ b/helpers/content.go @@ -95,11 +95,10 @@ func GetHtmlRenderer(defaultFlags int, ctx RenderingContext) blackfriday.Rendere htmlFlags := defaultFlags htmlFlags |= blackfriday.HTML_USE_XHTML htmlFlags |= blackfriday.HTML_USE_SMARTYPANTS - htmlFlags |= blackfriday.HTML_SMARTYPANTS_FRACTIONS htmlFlags |= blackfriday.HTML_SMARTYPANTS_LATEX_DASHES htmlFlags |= blackfriday.HTML_FOOTNOTE_RETURN_LINKS - var angledQuotes bool + var angledQuotes, fractions bool if m, ok := ctx.ConfigFlags["angledQuotes"]; ok { angledQuotes = m @@ -109,6 +108,14 @@ func GetHtmlRenderer(defaultFlags int, ctx RenderingContext) blackfriday.Rendere htmlFlags |= blackfriday.HTML_SMARTYPANTS_ANGLED_QUOTES } + if m, ok := ctx.ConfigFlags["fractions"]; ok { + fractions = m + } + + if fractions { + htmlFlags |= blackfriday.HTML_SMARTYPANTS_FRACTIONS + } + return blackfriday.HtmlRendererWithParameters(htmlFlags, "", "", renderParameters) } |