Source code for galaxy.web.framework.helpers.tags

"""
Code derived from WebHelpers: https://bitbucket.org/bbangert/webhelpers

Licensed under the MIT license: https://bitbucket.org/bbangert/webhelpers/src/tip/LICENSE
"""
from __future__ import print_function

from markupsafe import escape_silent


[docs]def format_attrs(**attrs): """Format HTML attributes into a string of ' key="value"' pairs which can be inserted into an HTML tag. The attributes are sorted alphabetically. If any value is None, the entire attribute is suppressed. Usage: >>> format_attrs(p=2, q=3) == u' p="2" q="3"' True >>> format_attrs(p=2, q=None) == u' p="2"' True >>> format_attrs(p=None) == u'' True """ strings = [u' %s="%s"' % (attr, escape_silent(value)) for attr, value in sorted(attrs.items()) if value is not None] return u''.join(strings)