package mandate import ( "strings" "gno.land/p/nt/markdown/sanitize/v0" ) // Escaping. Plan titles are the only text users choose; every title that // reaches a page goes through esc (headings, link text) or escCell (table // cells). They wrap p/nt/markdown/sanitize/v0, so a title cannot produce a // heading, list, table break, link, image, HTML tag or code, plus the // gnoweb-specific steps in gnowebSafe: // - "@name" and " g1..." (an address after a space) become profile links // in gnoweb: "@" becomes "\@", the space before "g1" becomes " ", and // a "g1" at the very start becomes "g1" (the realm often puts a space // right before a title). // - "$...$" becomes math: every "$" becomes "\$". // Everything else on the pages is generated by the realm from validated // values (addresses, numbers, a bech32 key checked by the chain). func esc(s string) string { return gnowebSafe(sanitize.InlineText(s)) } func escCell(s string) string { return gnowebSafe(sanitize.TableCell(s)) } func gnowebSafe(s string) string { s = strings.ReplaceAll(s, "@", `\@`) s = strings.ReplaceAll(s, "$", `\$`) s = strings.ReplaceAll(s, " g1", " g1") if strings.HasPrefix(s, "g1") { s = "g1" + s[2:] } return s }