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)
```
This commit is contained in:
Alex Ungur 2021-09-08 13:28:38 +03:00
parent 4c9bf95126
commit fee6c5a361
3 changed files with 5 additions and 2 deletions

View File

@ -46,6 +46,7 @@ const (
SmartypantsLatexDashes // Enable LaTeX-style dashes (with Smartypants) SmartypantsLatexDashes // Enable LaTeX-style dashes (with Smartypants)
SmartypantsAngledQuotes // Enable angled double quotes (with Smartypants) for double quotes rendering SmartypantsAngledQuotes // Enable angled double quotes (with Smartypants) for double quotes rendering
SmartypantsQuotesNBSP // Enable « French guillemets » (with Smartypants) SmartypantsQuotesNBSP // Enable « French guillemets » (with Smartypants)
SmartypantsParens // Enable smart parens (with Smartypants)
TOC // Generate a table of contents TOC // Generate a table of contents
) )

View File

@ -49,7 +49,7 @@ const (
DefinitionLists // Render definition lists DefinitionLists // Render definition lists
CommonHTMLFlags HTMLFlags = UseXHTML | Smartypants | CommonHTMLFlags HTMLFlags = UseXHTML | Smartypants |
SmartypantsFractions | SmartypantsDashes | SmartypantsLatexDashes SmartypantsFractions | SmartypantsDashes | SmartypantsLatexDashes | SmartypantsParens
CommonExtensions Extensions = NoIntraEmphasis | Tables | FencedCode | CommonExtensions Extensions = NoIntraEmphasis | Tables | FencedCode |
Autolink | Strikethrough | SpaceHeadings | HeadingIDs | Autolink | Strikethrough | SpaceHeadings | HeadingIDs |

View File

@ -411,7 +411,9 @@ func NewSmartypantsRenderer(flags HTMLFlags) *SPRenderer {
} }
} }
r.callbacks['\''] = r.smartSingleQuote r.callbacks['\''] = r.smartSingleQuote
r.callbacks['('] = r.smartParens if flags&SmartypantsParens != 0 {
r.callbacks['('] = r.smartParens
}
if flags&SmartypantsDashes != 0 { if flags&SmartypantsDashes != 0 {
if flags&SmartypantsLatexDashes == 0 { if flags&SmartypantsLatexDashes == 0 {
r.callbacks['-'] = r.smartDash r.callbacks['-'] = r.smartDash