Mercurial > urweb
diff src/monoize.sml @ 984:815afd323d86
Whitelisting tags that may be self-closed
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Sat, 26 Sep 2009 12:45:19 -0400 |
parents | 27a3412d23e4 |
children | d1dbb9a3c804 |
line wrap: on
line diff
--- a/src/monoize.sml Thu Sep 24 15:45:37 2009 -0400 +++ b/src/monoize.sml Sat Sep 26 12:45:19 2009 -0400 @@ -36,6 +36,19 @@ structure IM = IntBinaryMap structure IS = IntBinarySet +structure SS = BinarySetFn(struct + type ord_key = string + val compare = String.compare + end) + +val singletons = SS.addList (SS.empty, + ["link", + "br", + "p", + "hr", + "input", + "button"]) + val dummyTyp = (L'.TDatatype (0, ref (L'.Enum, [])), E.dummySpan) structure U = MonoUtil @@ -2603,6 +2616,16 @@ loc), fm) end + + fun isSingleton () = + let + val (bef, aft) = Substring.splitl (not o Char.isSpace) (Substring.full tag) + in + SS.member (singletons, if Substring.isEmpty aft then + tag + else + Substring.string bef) + end in case xml of (L.EApp ((L.ECApp ( @@ -2610,7 +2633,7 @@ _), _), _), _), (L.EPrim (Prim.String s), _)), _) => - if CharVector.all Char.isSpace s then + if CharVector.all Char.isSpace s andalso isSingleton () then ((L'.EStrcat (tagStart, (L'.EPrim (Prim.String " />"), loc)), loc), fm) else normal ()