You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

21 lines
591 B

  1. package utils
  2. import (
  3. "html"
  4. "regexp"
  5. mevt "maunium.net/go/mautrix/event"
  6. )
  7. var htmlRegex = regexp.MustCompile("<[^<]+?>")
  8. // StrippedHTMLMessage returns a MessageEventContent with the body set to a stripped version of the provided HTML,
  9. // in addition to the provided HTML.
  10. func StrippedHTMLMessage(msgtype mevt.MessageType, htmlText string) mevt.MessageEventContent {
  11. return mevt.MessageEventContent{
  12. Body: html.UnescapeString(htmlRegex.ReplaceAllLiteralString(htmlText, "")),
  13. MsgType: msgtype,
  14. Format: mevt.FormatHTML,
  15. FormattedBody: htmlText,
  16. }
  17. }