diff options
author | Tulir Asokan <tulir@maunium.net> | 2019-03-26 19:57:44 +0200 |
---|---|---|
committer | Tulir Asokan <tulir@maunium.net> | 2019-03-26 19:57:44 +0200 |
commit | c3c7cc9b3503417afe11a8067095534a751dfd04 (patch) | |
tree | 90445b9c7e2db4d1895a4b83c134d97753b24177 /matrix | |
parent | ded4767729cedb8457b343b584d40302d518eba2 (diff) |
Change things
Diffstat (limited to 'matrix')
-rw-r--r-- | matrix/matrix.go | 33 |
1 files changed, 11 insertions, 22 deletions
diff --git a/matrix/matrix.go b/matrix/matrix.go index cb986ee..6d94e2e 100644 --- a/matrix/matrix.go +++ b/matrix/matrix.go @@ -40,7 +40,6 @@ import ( "maunium.net/go/gomuks/config" "maunium.net/go/gomuks/debug" "maunium.net/go/gomuks/interface" - "maunium.net/go/gomuks/lib/bfhtml" "maunium.net/go/gomuks/matrix/pushrules" "maunium.net/go/gomuks/matrix/rooms" ) @@ -474,28 +473,18 @@ func (c *Container) SendMessage(roomID string, msgtype mautrix.MessageType, text } func (c *Container) renderMarkdown(text string) string { - parser := blackfriday.New( - blackfriday.WithExtensions(blackfriday.NoIntraEmphasis | - blackfriday.Tables | - blackfriday.FencedCode | - blackfriday.Strikethrough | - blackfriday.SpaceHeadings | - blackfriday.DefinitionLists)) - ast := parser.Parse([]byte(text)) - - renderer := bfhtml.HTMLRenderer{ - HTMLRenderer: blackfriday.NewHTMLRenderer(blackfriday.HTMLRendererParameters{ - Flags: blackfriday.UseXHTML, - }), - } - - var buf strings.Builder - renderer.RenderHeader(&buf, ast) - ast.Walk(func(node *blackfriday.Node, entering bool) blackfriday.WalkStatus { - return renderer.RenderNode(&buf, node, entering) + renderer := blackfriday.NewHTMLRenderer(blackfriday.HTMLRendererParameters{ + Flags: blackfriday.UseXHTML, }) - renderer.RenderFooter(&buf, ast) - return buf.String() + + return strings.ReplaceAll(string(blackfriday.Run([]byte(text), + blackfriday.WithExtensions(blackfriday.NoIntraEmphasis| + blackfriday.Tables| + blackfriday.FencedCode| + blackfriday.Strikethrough| + blackfriday.SpaceHeadings| + blackfriday.DefinitionLists), + blackfriday.WithRenderer(renderer))), "\n", "") } var mentionRegex = regexp.MustCompile("\\[(.+?)]\\(https://matrix.to/#/@.+?:.+?\\)") |