From fee6c5a361839e7107387fb3b858d6acbdc2e131 Mon Sep 17 00:00:00 2001 From: Alex Ungur Date: Wed, 8 Sep 2021 13:28:38 +0300 Subject: [PATCH] Added ability to disable smart parens, fixes #411, You can now run the following code to disable smart parens: ``` mdOpt = blackfriday.WithRenderer(blackfriday.NewHTMLRenderer(blackfriday.HTMLRendererParameters{ Flags: blackfriday.CommonHTMLFlags ^ blackfriday.SmartypantsParens, })) blackfriday.Run([]byte(...), mdOpt) ``` --- html.go | 1 + markdown.go | 2 +- smartypants.go | 4 +++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/html.go b/html.go index cb4f26e..7396091 100644 --- a/html.go +++ b/html.go @@ -46,6 +46,7 @@ const ( SmartypantsLatexDashes // Enable LaTeX-style dashes (with Smartypants) SmartypantsAngledQuotes // Enable angled double quotes (with Smartypants) for double quotes rendering SmartypantsQuotesNBSP // Enable « French guillemets » (with Smartypants) + SmartypantsParens // Enable smart parens (with Smartypants) TOC // Generate a table of contents ) diff --git a/markdown.go b/markdown.go index 58d2e45..ceced97 100644 --- a/markdown.go +++ b/markdown.go @@ -49,7 +49,7 @@ const ( DefinitionLists // Render definition lists CommonHTMLFlags HTMLFlags = UseXHTML | Smartypants | - SmartypantsFractions | SmartypantsDashes | SmartypantsLatexDashes + SmartypantsFractions | SmartypantsDashes | SmartypantsLatexDashes | SmartypantsParens CommonExtensions Extensions = NoIntraEmphasis | Tables | FencedCode | Autolink | Strikethrough | SpaceHeadings | HeadingIDs | diff --git a/smartypants.go b/smartypants.go index 3a220e9..58d2d34 100644 --- a/smartypants.go +++ b/smartypants.go @@ -411,7 +411,9 @@ func NewSmartypantsRenderer(flags HTMLFlags) *SPRenderer { } } r.callbacks['\''] = r.smartSingleQuote - r.callbacks['('] = r.smartParens + if flags&SmartypantsParens != 0 { + r.callbacks['('] = r.smartParens + } if flags&SmartypantsDashes != 0 { if flags&SmartypantsLatexDashes == 0 { r.callbacks['-'] = r.smartDash