Fixed #48, partial merge of #49

This commit manually merges the test from #49, with slightly simpler fixes that in the PR, as well
as additional tests and fixes for case-insensitivity issues (i.e. case-sensitivity is good) and
better handling of masses of weird whitespace in class attributes, as is sometimes produced by
templating engines.
:x

]