Sanitize CSS class names applied on Legend rows/entries

Previously, short names and numbers would be applied as CSS classes, but they would be invalid class names and it would thus be impossible to apply styles to them.

Close #1321.
Can we have a test of like "123a"?  I have a suspicion the regex is incorrect