Improved robustness of _html_class_str_from_tag function