-
Notifications
You must be signed in to change notification settings - Fork 1
The Attribute Rendering Process
Rendering attributes does not affect the attributes or the container they are in (rendering never mutates anything). However, the names and values are processed automatically as they are rendered.
Attributes that currently have None values are not rendered at all.
Attribute values are passed through str and the result is rendered, so the value can be a number for example.
Attribute values are always wrapped in doublequotes, and are escaped automatically. The escape function escapes doublequotes, open angle brackets and ampersands.
Note: HTME does not escape anything besides attribute values:
>>> DIV({"name": "spam & eggs"}, "foo & bar")
<div name="spam & eggs">foo & bar</div>
Attributes that currently have empty string values, are rendered as boolean attributes:
>>> DIV({"contenteditable": ""})
<div contenteditable></div>
Attribute names that begin with a dollar, are shorthand data attributes. The dollar is expanded in the rendered name to the string data followed by a hyphen:
>>> DIV({"$visitors": "1000000"})
<div data-visitors="1000000"></div>
Attribute names are rendered with the names sorted (asciibetically) to make rendering deterministic. The element attributes are rendered first, with the data attributes after them:
>>> DIV({"id": "selected", "$mass": 145.34, "class": "product", "$price": 50})
<div class="product" id="selected" data-price="50" data-mass="145.34"></div>
You can provide a list or tuple (or any subclass) as an attribute value, in which case, each item in the sequence is converted according to the same rules for single values, and the results are joined with spaces (skipping any that are None) to form a string:
>>> SVG({"viewbox": (1, 1, 100, 100)})
<svg viewbox="1 1 100 100"></svg>
HTME | The Hypertext Markup Engine | Simple, Pythonic HTML Code Generation for Python 2 or 3
To learn to use HTME, read these articles (in this order):