mirror of
https://github.com/gohugoio/hugo.git
synced 2024-07-07 09:36:03 +00:00
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.
This commit is contained in:
parent
803865f870
commit
eb686352b1
|
@ -136,7 +136,7 @@ func InitializeConfig() {
|
||||||
viper.SetDefault("FootnoteAnchorPrefix", "")
|
viper.SetDefault("FootnoteAnchorPrefix", "")
|
||||||
viper.SetDefault("FootnoteReturnLinkContents", "")
|
viper.SetDefault("FootnoteReturnLinkContents", "")
|
||||||
viper.SetDefault("NewContentEditor", "")
|
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 {
|
if hugoCmdV.PersistentFlags().Lookup("buildDrafts").Changed {
|
||||||
viper.Set("BuildDrafts", Draft)
|
viper.Set("BuildDrafts", Draft)
|
||||||
|
|
|
@ -91,6 +91,21 @@ But Hugo does expose some options---as listed in the table below, matched with t
|
||||||
<td class="purpose-description" colspan="2">Enable smart angled double quotes <small>(e.g. <code>"Hugo"</code> renders to «Hugo» instead of “Hugo”)</small></td>
|
<td class="purpose-description" colspan="2">Enable smart angled double quotes <small>(e.g. <code>"Hugo"</code> renders to «Hugo» instead of “Hugo”)</small></td>
|
||||||
</tr>
|
</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>
|
<tr>
|
||||||
<td><code>plainIdAnchors</code></td>
|
<td><code>plainIdAnchors</code></td>
|
||||||
<td><code>false</code></td>
|
<td><code>false</code></td>
|
||||||
|
@ -112,11 +127,13 @@ But Hugo does expose some options---as listed in the table below, matched with t
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td><pre><code>[blackfriday]
|
<td><pre><code>[blackfriday]
|
||||||
angledQuotes = true
|
angledQuotes = true
|
||||||
plainIdAnchors = true
|
fractions = false
|
||||||
|
plainIdAnchors = true
|
||||||
</code></pre></td>
|
</code></pre></td>
|
||||||
<td><pre><code>blackfriday:
|
<td><pre><code>blackfriday:
|
||||||
angledQuotes: true
|
angledQuotes: true
|
||||||
|
fractions: false
|
||||||
plainIdAnchors: true
|
plainIdAnchors: true
|
||||||
</code></pre></td>
|
</code></pre></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
|
@ -95,11 +95,10 @@ func GetHtmlRenderer(defaultFlags int, ctx RenderingContext) blackfriday.Rendere
|
||||||
htmlFlags := defaultFlags
|
htmlFlags := defaultFlags
|
||||||
htmlFlags |= blackfriday.HTML_USE_XHTML
|
htmlFlags |= blackfriday.HTML_USE_XHTML
|
||||||
htmlFlags |= blackfriday.HTML_USE_SMARTYPANTS
|
htmlFlags |= blackfriday.HTML_USE_SMARTYPANTS
|
||||||
htmlFlags |= blackfriday.HTML_SMARTYPANTS_FRACTIONS
|
|
||||||
htmlFlags |= blackfriday.HTML_SMARTYPANTS_LATEX_DASHES
|
htmlFlags |= blackfriday.HTML_SMARTYPANTS_LATEX_DASHES
|
||||||
htmlFlags |= blackfriday.HTML_FOOTNOTE_RETURN_LINKS
|
htmlFlags |= blackfriday.HTML_FOOTNOTE_RETURN_LINKS
|
||||||
|
|
||||||
var angledQuotes bool
|
var angledQuotes, fractions bool
|
||||||
|
|
||||||
if m, ok := ctx.ConfigFlags["angledQuotes"]; ok {
|
if m, ok := ctx.ConfigFlags["angledQuotes"]; ok {
|
||||||
angledQuotes = m
|
angledQuotes = m
|
||||||
|
@ -109,6 +108,14 @@ func GetHtmlRenderer(defaultFlags int, ctx RenderingContext) blackfriday.Rendere
|
||||||
htmlFlags |= blackfriday.HTML_SMARTYPANTS_ANGLED_QUOTES
|
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)
|
return blackfriday.HtmlRendererWithParameters(htmlFlags, "", "", renderParameters)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue