4
0
mirror of https://github.com/cwinfo/matterbridge.git synced 2025-06-26 14:19:24 +00:00

Update markdown parsing library to github.com/gomarkdown/markdown (#944)

This commit is contained in:
Benjamin
2019-11-18 06:18:01 +10:00
committed by Wim
parent aba86855b5
commit 0917dc8766
120 changed files with 8282 additions and 47873 deletions

View File

@ -14,8 +14,9 @@ import (
"golang.org/x/image/webp"
"github.com/42wim/matterbridge/bridge/config"
"github.com/gomarkdown/markdown"
"github.com/gomarkdown/markdown/parser"
"github.com/sirupsen/logrus"
"gitlab.com/golang-commonmark/markdown"
)
// DownloadFile downloads the given non-authenticated URL.
@ -176,9 +177,12 @@ func ClipMessage(text string, length int) string {
return text
}
// ParseMarkdown takes in an input string as markdown and parses it to html
func ParseMarkdown(input string) string {
md := markdown.New(markdown.XHTMLOutput(true), markdown.Breaks(true))
res := md.RenderToString([]byte(input))
extensions := parser.HardLineBreak
markdownParser := parser.NewWithExtensions(extensions)
parsedMarkdown := markdown.ToHTML([]byte(input), markdownParser, nil)
res := string(parsedMarkdown)
res = strings.TrimPrefix(res, "<p>")
res = strings.TrimSuffix(res, "</p>\n")
return res