Mercurial > urweb
diff lib/js/urweb.js @ 1755:e9587120831a
Run-time CSS style validation
author | Adam Chlipala <adam@chlipala.net> |
---|---|
date | Sun, 06 May 2012 16:08:48 -0400 |
parents | acadf9d1214a |
children | 22858505bb2d |
line wrap: on
line diff
--- a/lib/js/urweb.js Sun May 06 15:46:25 2012 -0400 +++ b/lib/js/urweb.js Sun May 06 16:08:48 2012 -0400 @@ -1748,6 +1748,46 @@ } +// CSS validation + +function atom(s) { + for (var i = 0; i < s.length; ++i) { + var c = s[i]; + if (!isAlnum(c) && c != '+' && c != '-' && c != '.' && c != '%' && c != '#') + er("Disallowed character in CSS atom"); + } + + return s; +} + +function css_url(s) { + for (var i = 0; i < s.length; ++i) { + var c = s[i]; + if (!isAlnum(c) && c != ':' && c != '/' && c != '.' && c != '_' && c != '+' + && c != '-' && c != '%' && c != '?' && c != '&' && c != '=' && c != '#') + er("Disallowed character in CSS URL"); + } + + return s; +} + +function property(s) { + if (s.length <= 0) + er("Empty CSS property"); + + if (!isLower(s[0]) && s[0] != '_') + er("Bad initial character in CSS property"); + + for (var i = 0; i < s.length; ++i) { + var c = s[i]; + if (!isLower(c) && !isDigit(c) && c != '_' && c != '-') + er("Disallowed character in CSS property"); + } + + return s; +} + + // ID generation var nextId = 0;