This document is for an in-development version of Galaxy. You can alternatively view this page in the latest release if it exists or view the top of the latest release's documentation.

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 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 = [f' {attr}="{escape_silent(value)}"' for attr, value in sorted(attrs.items()) if value is not None] return "".join(strings)