enable Smartypants for md rendering
This commit is contained in:
@@ -34,6 +34,10 @@ func TestComment_Sanitize(t *testing.T) {
|
||||
User: User{ID: "id", Name: "xyz"},
|
||||
},
|
||||
},
|
||||
{
|
||||
inp: Comment{Text: "blah & & 123 — —"},
|
||||
out: Comment{Text: `blah & & 123 — —`},
|
||||
},
|
||||
}
|
||||
|
||||
for n, tt := range tbl {
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
blackfriday "gopkg.in/russross/blackfriday.v2"
|
||||
bf "gopkg.in/russross/blackfriday.v2"
|
||||
)
|
||||
|
||||
// CommentFormatter implements all generic formatting ops on comment
|
||||
@@ -40,10 +40,15 @@ func (f *CommentFormatter) Format(c Comment) Comment {
|
||||
|
||||
// FormatText converts text with markdown processor, applies external converters and shortens links
|
||||
func (f *CommentFormatter) FormatText(txt string) (res string) {
|
||||
mdExt := blackfriday.NoIntraEmphasis | blackfriday.Tables | blackfriday.FencedCode |
|
||||
blackfriday.Strikethrough | blackfriday.SpaceHeadings | blackfriday.HardLineBreak |
|
||||
blackfriday.BackslashLineBreak | blackfriday.Autolink
|
||||
res = string(blackfriday.Run([]byte(txt), blackfriday.WithExtensions(mdExt)))
|
||||
mdExt := bf.NoIntraEmphasis | bf.Tables | bf.FencedCode |
|
||||
bf.Strikethrough | bf.SpaceHeadings | bf.HardLineBreak |
|
||||
bf.BackslashLineBreak | bf.Autolink
|
||||
|
||||
rend := bf.NewHTMLRenderer(bf.HTMLRendererParameters{
|
||||
Flags: bf.Smartypants | bf.SmartypantsFractions | bf.SmartypantsDashes | bf.SmartypantsAngledQuotes,
|
||||
})
|
||||
|
||||
res = string(bf.Run([]byte(txt), bf.WithExtensions(mdExt), bf.WithRenderer(rend)))
|
||||
|
||||
for _, conv := range f.converters {
|
||||
res = conv.Convert(res)
|
||||
|
||||
@@ -17,7 +17,7 @@ func TestFormatter_FormatText(t *testing.T) {
|
||||
}{
|
||||
{"", "!converted"},
|
||||
{"12345 abc", "<p>12345 abc</p>\n!converted"},
|
||||
{"**xyz** _aaa_", "<p><strong>xyz</strong> <em>aaa</em></p>\n!converted"},
|
||||
{"**xyz** _aaa_ - \"sfs\"", "<p><strong>xyz</strong> <em>aaa</em> – «sfs»</p>\n!converted"},
|
||||
{
|
||||
"http://127.0.0.1/some-long-link/12345/678901234567890", "<p><a href=\"http://127.0.0.1/some-long-link/12345/678901234567890\">http://127.0.0.1/some-long-link/12345/6789012...</a></p>\n!converted",
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user