(new): rich message support
(fix): runtime reliability (tests): regression coverage (doc): v1.1 release notes
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
package tgrich
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func escapeHTML(s string) string {
|
||||
s = strings.ReplaceAll(s, "&", "&")
|
||||
s = strings.ReplaceAll(s, "<", "<")
|
||||
s = strings.ReplaceAll(s, ">", ">")
|
||||
s = strings.ReplaceAll(s, `"`, """)
|
||||
return s
|
||||
}
|
||||
func formatAttrs(attrs map[string]string) []string {
|
||||
out := make([]string, 0, len(attrs))
|
||||
for k, v := range attrs {
|
||||
if v == "" {
|
||||
out = append(out, k)
|
||||
continue
|
||||
}
|
||||
out = append(out, fmt.Sprintf(`%s="%s"`, k, escapeHTML(v)))
|
||||
}
|
||||
sort.Strings(out)
|
||||
return out
|
||||
}
|
||||
|
||||
func openTag(name string, attrs []string) string {
|
||||
if len(attrs) == 0 {
|
||||
return "<" + name + ">"
|
||||
}
|
||||
return "<" + name + " " + strings.Join(attrs, " ") + ">"
|
||||
}
|
||||
|
||||
func selfClosingTag(name string, attrs []string) string {
|
||||
if len(attrs) == 0 {
|
||||
return "<" + name + "/>"
|
||||
}
|
||||
return "<" + name + " " + strings.Join(attrs, " ") + "/>"
|
||||
}
|
||||
Reference in New Issue
Block a user