Switch to edit mode.
Name(s): lmth1: "Inputs a string and parses it for any unclosed HTML tags."
2: "Eg. <A href=index.html>link => </A>"
3: victim = tostr(@args[1])
4: a = ""
5: "Strip out all comments"
6: while (start = index(victim, "<!--"))
7: close = index(victim[start + 4..$], "-->")
8: if (!close)
9: "Unclosed comment."
10: a = "-->"
11: victim[start..$] = ""
12: else
13: victim[start..close + start + 5] = ""
14: endif
15: endwhile
16: opens = {}
17: while ((c = index(victim, "<")) && c != length(victim))
18: nc = victim[c + 1]
19: st = victim[c + 1..$]
20: et = c + 1 + index(victim[c + 2..$], ">")
21: if (nc == " " || nc == "<")
22: "Ignore a lone '<'"
23: victim = st
24: elseif (!index(st, ">"))
25: "Tag doesn't end"
26: a = a + ">"
27: tag = $string_utils:explode(victim[c + 1..$])[1]
28: if (!(tag in this.single_tags))
29: opens = {@opens, tag}
30: endif
31: victim = ""
32: elseif (nc == "/")
33: "Close tag detected"
34: tag = $string_utils:explode(victim[c + 2..et - 1])[1]
35: opens = setremove(opens, tag)
36: victim = victim[et + 1..$]
37: else
38: "Open tag detected"
39: tag = $string_utils:explode(victim[c + 1..et - 1])[1]
40: if (!(tag in this.single_tags))
41: opens = {@opens, tag}
42: endif
43: victim = victim[et + 1..$]
44: endif
45: endwhile
46: b = ""
47: for x in (opens)
48: b = "</" + x + ">" + b
49: endfor
50: return a + b
51: "Last modified by Dax (#789) on Mon Aug 28 15:18:43 2000 MDT."