Issue #55 resolved

Can't pass HTML5 "data-" attributes to tag builders

Yoann Roman
created an issue

HTML5 adds custom {{{data-}}} attributes on elements to store custom, private data. However, because of that dash, these can't be passed in via the regular {{{attrs}}}. Instead, they have to be wrapped in a dictionary construct: {{{{'data-length': '2m11s'}}}}. Doing this is messier with template engines like Mako that can't handle brackets within its standard {{{${}}}} variable substitution construct (see http://www.makotemplates.org/trac/ticket/20).

What about changing {{{_attr_decode}}} to convert all inner underscores to dashes? I can't think of an HTML attribute with an underscore offhand.

Several ways to do this, but here's one: {{{

!python

def attr_decode(v): """Parse out attributes that begin with ''.""" if v.endswith(''): v = v[:-1] return v[0] + v[1:-1].replace('', '-') + v[-1] }}}

Comments (4)

  1. Log in to comment