From cb9dfc2613ae5125cafa450097fb0f62dd3770e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Sat, 29 Jul 2017 10:10:40 +0200 Subject: [PATCH] helpers: Add support for French Guillemets Fixes #3725 --- docs/content/readfiles/bfconfig.md | 5 +++++ helpers/content.go | 6 ++++++ helpers/content_test.go | 2 ++ 3 files changed, 13 insertions(+) diff --git a/docs/content/readfiles/bfconfig.md b/docs/content/readfiles/bfconfig.md index 67b349f83..98e357678 100644 --- a/docs/content/readfiles/bfconfig.md +++ b/docs/content/readfiles/bfconfig.md @@ -8,6 +8,11 @@ Blackfriday flag: **`HTML_USE_SMARTYPANTS`**
Purpose: `false` disables smart punctuation substitutions, including smart quotes, smart dashes, smart fractions, etc. If `true`, it may be fine-tuned with the `angledQuotes`, `fractions`, `smartDashes`, and `latexDashes` flags (see below). +`smartypantsQuotesNBSP` +: default: **`false`**
+ Blackfriday flag: **`HTML_SMARTYPANTS_QUOTES_NBSP`**
+ Purpose: `true` enables French style Guillemets with non-breaking space inside the quotes. + `angledQuotes` : default: **`false`**
Blackfriday flag: **`HTML_SMARTYPANTS_ANGLED_QUOTES`**
diff --git a/helpers/content.go b/helpers/content.go index 350d1a685..d84fe27a8 100644 --- a/helpers/content.go +++ b/helpers/content.go @@ -63,6 +63,7 @@ func NewContentSpec(cfg config.Provider) *ContentSpec { // Blackfriday holds configuration values for Blackfriday rendering. type Blackfriday struct { Smartypants bool + SmartypantsQuotesNBSP bool AngledQuotes bool Fractions bool HrefTargetBlank bool @@ -81,6 +82,7 @@ func (c ContentSpec) NewBlackfriday() *Blackfriday { defaultParam := map[string]interface{}{ "smartypants": true, "angledQuotes": false, + "smartypantsQuotesNBSP": false, "fractions": true, "hrefTargetBlank": false, "smartDashes": true, @@ -229,6 +231,10 @@ func (c ContentSpec) getHTMLRenderer(defaultFlags int, ctx *RenderingContext) bl htmlFlags |= blackfriday.HTML_USE_SMARTYPANTS } + if ctx.Config.SmartypantsQuotesNBSP { + htmlFlags |= blackfriday.HTML_SMARTYPANTS_QUOTES_NBSP + } + if ctx.Config.AngledQuotes { htmlFlags |= blackfriday.HTML_SMARTYPANTS_ANGLED_QUOTES } diff --git a/helpers/content_test.go b/helpers/content_test.go index 95261efdf..e1fe5cebd 100644 --- a/helpers/content_test.go +++ b/helpers/content_test.go @@ -171,6 +171,7 @@ func TestGetHTMLRendererAllFlags(t *testing.T) { {blackfriday.HTML_USE_XHTML}, {blackfriday.HTML_FOOTNOTE_RETURN_LINKS}, {blackfriday.HTML_USE_SMARTYPANTS}, + {blackfriday.HTML_SMARTYPANTS_QUOTES_NBSP}, {blackfriday.HTML_SMARTYPANTS_ANGLED_QUOTES}, {blackfriday.HTML_SMARTYPANTS_FRACTIONS}, {blackfriday.HTML_HREF_TARGET_BLANK}, @@ -186,6 +187,7 @@ func TestGetHTMLRendererAllFlags(t *testing.T) { ctx.Config.PlainIDAnchors = true ctx.Config.SmartDashes = true ctx.Config.Smartypants = true + ctx.Config.SmartypantsQuotesNBSP = true ctx.Config.SourceRelativeLinksEval = true renderer := c.getHTMLRenderer(defaultFlags, ctx) actualFlags := renderer.GetFlags()