def get_html_attrs(kwargs=None):
    kwargs = kwargs or {}
    attrs = []
    props = []
    classes = kwargs.get('classes', '').strip()
    if classes:
        classes = ' '.join(re.split(r'\s+', classes))
        classes = to_unicode(quoteattr(classes))
        attrs.append('class=%s' % classes)
    try:
        del kwargs['classes']
    except KeyError:
        pass
    for key, value in iteritems(kwargs):
        key = key.replace('_', '-')
        key = to_unicode(key)
        if isinstance(value, bool):
            if value is True:
                props.append(key)
        else:
            value = quoteattr(Markup(value))
            attrs.append(u'%s=%s' % (key, value))
    attrs.sort()
    props.sort()
    attrs.extend(props)
    return u' '.join(attrs)