Skip to content Search Apps Documentation Source Content Run Reset Eval Playground File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

escape.gno

1.22 Kb · 33 lines
 1package mandate
 2
 3import (
 4	"strings"
 5
 6	"gno.land/p/nt/markdown/sanitize/v0"
 7)
 8
 9// Escaping. Plan titles are the only text users choose; every title that
10// reaches a page goes through esc (headings, link text) or escCell (table
11// cells). They wrap p/nt/markdown/sanitize/v0, so a title cannot produce a
12// heading, list, table break, link, image, HTML tag or code, plus the
13// gnoweb-specific steps in gnowebSafe:
14//   - "@name" and " g1..." (an address after a space) become profile links
15//     in gnoweb: "@" becomes "\@", the space before "g1" becomes " ", and
16//     a "g1" at the very start becomes "g1" (the realm often puts a space
17//     right before a title).
18//   - "$...$" becomes math: every "$" becomes "\$".
19// Everything else on the pages is generated by the realm from validated
20// values (addresses, numbers, a bech32 key checked by the chain).
21
22func esc(s string) string     { return gnowebSafe(sanitize.InlineText(s)) }
23func escCell(s string) string { return gnowebSafe(sanitize.TableCell(s)) }
24
25func gnowebSafe(s string) string {
26	s = strings.ReplaceAll(s, "@", `\@`)
27	s = strings.ReplaceAll(s, "$", `\$`)
28	s = strings.ReplaceAll(s, " g1", " g1")
29	if strings.HasPrefix(s, "g1") {
30		s = "g1" + s[2:]
31	}
32	return s
33}