diff options
author | bep <bjorn.erik.pedersen@gmail.com> | 2014-11-28 23:16:57 +0300 |
---|---|---|
committer | bep <bjorn.erik.pedersen@gmail.com> | 2014-12-26 16:31:55 +0300 |
commit | fbf8bcacc464e9bfbc816fa6d097e6371662ce02 (patch) | |
tree | d193dfa7322d553bc6753cb7e130e2cbd2ea7c6e /helpers | |
parent | bb3769822635963c35900fb307520e6bed7ff931 (diff) |
Add configurable support for angled quotes
The flag `HTML_SMARTYPANTS_ANGLED_QUOTES` was added to Blackfriday on Black Friday. This configures rendering of double quotes as angled left and right quotes («
»).
Typical use cases would be either or, or combined, but never in the same
document. As an example would be a person from Norway; he has a blog in both
English and Norwegian (his native tongue); he would then configure Blackfriday
to use angled quotes for the Norwegian section, but keep them as reqular
double quotes for the English.
This commit adds configuration support for this new flag, configuration that can be set in the site configuration, but overridden in page front matter.
Fixes #605
Diffstat (limited to 'helpers')
-rw-r--r-- | helpers/content.go | 55 |
1 files changed, 36 insertions, 19 deletions
diff --git a/helpers/content.go b/helpers/content.go index d5e507dae..a32245ae3 100644 --- a/helpers/content.go +++ b/helpers/content.go @@ -77,15 +77,15 @@ func BytesToHTML(b []byte) template.HTML { return template.HTML(string(b)) } -func GetHtmlRenderer(defaultFlags int, documentId string) blackfriday.Renderer { +func GetHtmlRenderer(defaultFlags int, ctx RenderingContext) blackfriday.Renderer { renderParameters := blackfriday.HtmlRendererParameters{ FootnoteAnchorPrefix: viper.GetString("FootnoteAnchorPrefix"), FootnoteReturnLinkContents: viper.GetString("FootnoteReturnLinkContents"), } - if len(documentId) != 0 { - renderParameters.FootnoteAnchorPrefix = documentId + ":" + renderParameters.FootnoteAnchorPrefix - renderParameters.HeaderIDSuffix = ":" + documentId + if len(ctx.DocumentId) != 0 { + renderParameters.FootnoteAnchorPrefix = ctx.DocumentId + ":" + renderParameters.FootnoteAnchorPrefix + renderParameters.HeaderIDSuffix = ":" + ctx.DocumentId } htmlFlags := defaultFlags @@ -95,6 +95,16 @@ func GetHtmlRenderer(defaultFlags int, documentId string) blackfriday.Renderer { htmlFlags |= blackfriday.HTML_SMARTYPANTS_LATEX_DASHES htmlFlags |= blackfriday.HTML_FOOTNOTE_RETURN_LINKS + var angledQuotes bool + + if m, ok := ctx.ConfigFlags["angledQuotes"]; ok { + angledQuotes = m + } + + if angledQuotes { + htmlFlags |= blackfriday.HTML_SMARTYPANTS_ANGLED_QUOTES + } + return blackfriday.HtmlRendererWithParameters(htmlFlags, "", "", renderParameters) } @@ -106,14 +116,14 @@ func GetMarkdownExtensions() int { blackfriday.EXTENSION_HEADER_IDS | blackfriday.EXTENSION_AUTO_HEADER_IDS } -func MarkdownRender(content []byte, documentId string) []byte { - return blackfriday.Markdown(content, GetHtmlRenderer(0, documentId), +func MarkdownRender(ctx RenderingContext) []byte { + return blackfriday.Markdown(ctx.Content, GetHtmlRenderer(0, ctx), GetMarkdownExtensions()) } -func MarkdownRenderWithTOC(content []byte, documentId string) []byte { - return blackfriday.Markdown(content, - GetHtmlRenderer(blackfriday.HTML_TOC, documentId), +func MarkdownRenderWithTOC(ctx RenderingContext) []byte { + return blackfriday.Markdown(ctx.Content, + GetHtmlRenderer(blackfriday.HTML_TOC, ctx), GetMarkdownExtensions()) } @@ -153,25 +163,32 @@ func ExtractTOC(content []byte) (newcontent []byte, toc []byte) { return } -func RenderBytesWithTOC(content []byte, pagefmt string, documentId string) []byte { - switch pagefmt { +type RenderingContext struct { + Content []byte + PageFmt string + DocumentId string + ConfigFlags map[string]bool +} + +func RenderBytesWithTOC(ctx RenderingContext) []byte { + switch ctx.PageFmt { default: - return MarkdownRenderWithTOC(content, documentId) + return MarkdownRenderWithTOC(ctx) case "markdown": - return MarkdownRenderWithTOC(content, documentId) + return MarkdownRenderWithTOC(ctx) case "rst": - return []byte(GetRstContent(content)) + return []byte(GetRstContent(ctx.Content)) } } -func RenderBytes(content []byte, pagefmt string, documentId string) []byte { - switch pagefmt { +func RenderBytes(ctx RenderingContext) []byte { + switch ctx.PageFmt { default: - return MarkdownRender(content, documentId) + return MarkdownRender(ctx) case "markdown": - return MarkdownRender(content, documentId) + return MarkdownRender(ctx) case "rst": - return []byte(GetRstContent(content)) + return []byte(GetRstContent(ctx.Content)) } } |