A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.
fix(markdown): Replace markdown parser.
LinkinStar5a348fd66d9e
diff --git a/go.mod b/go.modindex fd809329..7e4559df 100644--- a/go.mod+++ b/go.mod@@ -38,6 +38,7 @@ require (github.com/swaggo/files v0.0.0-20220728132757-551d4a08d97agithub.com/swaggo/gin-swagger v1.5.3github.com/swaggo/swag v1.8.7+ github.com/yuin/goldmark v1.4.13golang.org/x/crypto v0.1.0golang.org/x/net v0.1.0gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23dfdiff --git a/go.sum b/go.sumindex 4d15461e..cfb81da7 100644--- a/go.sum+++ b/go.sum@@ -693,6 +693,7 @@ github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9degithub.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=github.com/yuin/goldmark v1.4.0/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=+github.com/yuin/goldmark v1.4.13 h1:fVcFKWvrslecOb/tg+Cc05dkeYx540o0FuFt3nUVDoE=github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q=github.com/ziutek/mymysql v1.5.4/go.mod h1:LMSpPZ6DbqWFxNCHW77HeMg9I646SAhApZ/wKdgO/C0=diff --git a/pkg/converter/markdown.go b/pkg/converter/markdown.goindex a4d9e908..c69a042c 100644--- a/pkg/converter/markdown.go+++ b/pkg/converter/markdown.go@@ -1,14 +1,30 @@package converterimport (- "github.com/gomarkdown/markdown"- "github.com/gomarkdown/markdown/parser"+ "bytes"++ "github.com/segmentfault/pacman/log"+ "github.com/yuin/goldmark"+ "github.com/yuin/goldmark/extension"+ "github.com/yuin/goldmark/parser"+ "github.com/yuin/goldmark/renderer/html")// Markdown2HTML convert markdown to html-func Markdown2HTML(md string) string {- extensions := parser.HardLineBreak | parser.CommonExtensions- p := parser.NewWithExtensions(extensions)- html := markdown.ToHTML([]byte(md), p, nil)- return string(html)+func Markdown2HTML(source string) string {+ mdConverter := goldmark.New(+ goldmark.WithExtensions(extension.GFM),+ goldmark.WithParserOptions(+ parser.WithAutoHeadingID(),+ ),+ goldmark.WithRendererOptions(+ html.WithHardWraps(),+ ),+ )+ var buf bytes.Buffer+ if err := mdConverter.Convert([]byte(source), &buf); err != nil {+ log.Error(err)+ return source+ }+ return buf.String()}