var/list/legal_tags = list("b", "i", "u")
proc/sanitize_html(string)
. = ""
var
previous = 1
start
end
do
start = findtext(string, "<", end + 1)
end = start && findtext(string, ">", start)
if(start && end)
var/tag = copytext(string, start + 1, end)
if(!(ckey(tag) in legal_tags))
. += copytext(string, previous, start) + "<[tag]>"
previous = end + 1
while(start && end)
. += copytext(string, previous)
[Edit]
Alright, code to help test:
mob/Login()
world << sanitize_html("<i>Test.</i>")
world << sanitize_html("<br>Test.")
world << sanitize_html("<b>Test</b>")
world << sanitize_html("<font size=200>Test</font>")
world << sanitize_html("<u>Test</u>")
world << sanitize_html("<script>Test</script>")