Add support for tags in Discord -> Matrix formatter
This commit is contained in:
25
formatter.go
25
formatter.go
@@ -1,3 +1,19 @@
|
||||
// mautrix-discord - A Matrix-Discord puppeting bridge.
|
||||
// Copyright (C) 2022 Tulir Asokan
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -13,14 +29,17 @@ import (
|
||||
"maunium.net/go/mautrix/format/mdext"
|
||||
)
|
||||
|
||||
var mdRenderer = goldmark.New(format.Extensions, format.HTMLOptions,
|
||||
goldmark.WithExtensions(mdext.EscapeHTML, mdext.SimpleSpoiler, mdext.DiscordUnderline))
|
||||
var discordExtensions = goldmark.WithExtensions(mdext.EscapeHTML, mdext.SimpleSpoiler, mdext.DiscordUnderline)
|
||||
var escapeFixer = regexp.MustCompile(`\\(__[^_]|\*\*[^*])`)
|
||||
|
||||
func renderDiscordMarkdown(text string) event.MessageEventContent {
|
||||
func (portal *Portal) renderDiscordMarkdown(text string) event.MessageEventContent {
|
||||
text = escapeFixer.ReplaceAllStringFunc(text, func(s string) string {
|
||||
return s[:2] + `\` + s[2:]
|
||||
})
|
||||
mdRenderer := goldmark.New(
|
||||
format.Extensions, format.HTMLOptions, discordExtensions,
|
||||
goldmark.WithExtensions(&DiscordTag{portal}),
|
||||
)
|
||||
return format.RenderMarkdownCustom(text, mdRenderer)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user