sorry guys... lambda is now a snapchat client.....

This commit is contained in:
2026-08-03 19:39:57 +01:00
parent 7a822e8eaf
commit 546234eacf
6 changed files with 114 additions and 154 deletions
+41 -11
View File
@@ -1,18 +1,48 @@
package main
import (
_ "regexp"
"html"
"regexp"
"strings"
)
// This file implements XEP-0393 partially by providing a function to get a Pango string.
// https://xmpp.org/extensions/xep-0393.html
var (
urlRE = regexp.MustCompile(`https?://[^\s]+`)
boldRE = regexp.MustCompile(`\*([^*]+)\*`)
italicRE = regexp.MustCompile(`_([^_]+)_`)
strikeRE = regexp.MustCompile(`~([^~]+)~`)
codeRE = regexp.MustCompile("`([^`]+)`")
)
func convertXEPToPango(text string) string {
/* FIXME this RegEx causes certain strings to appear invisible
text = regexp.MustCompile(`\*([^*]+)\*`).ReplaceAllString(text, "<b>$1</b>")
text = regexp.MustCompile(`_([^_]+)_`).ReplaceAllString(text, "<i>$1</i>")
text = regexp.MustCompile(`~([^~]+)~`).ReplaceAllString(text, "<s>$1</s>")
text = regexp.MustCompile("`([^`]+)`").ReplaceAllString(text, "<tt>$1</tt>")
*/
return text
func XEPToPango(text string) string {
format := func(s string) string {
s = html.EscapeString(s)
s = boldRE.ReplaceAllString(s, "<b>$1</b>")
s = italicRE.ReplaceAllString(s, "<i>$1</i>")
s = strikeRE.ReplaceAllString(s, "<s>$1</s>")
s = codeRE.ReplaceAllString(s, "<tt>$1</tt>")
return s
}
var b strings.Builder
last := 0
for _, m := range urlRE.FindAllStringIndex(text, -1) {
start, end := m[0], m[1]
b.WriteString(format(text[last:start]))
url := html.EscapeString(text[start:end])
b.WriteString(`<a href="`)
b.WriteString(url)
b.WriteString(`">`)
b.WriteString(url)
b.WriteString(`</a>`)
last = end
}
b.WriteString(format(text[last:]))
return b.String()
}