Knio / dominate

Dominate is a Python library for creating and manipulating HTML documents using an elegant DOM API. It allows you to write HTML pages in pure Python very concisely, which eliminate the need to learn another template language, and to take advantage of the more powerful features of Python.
GNU Lesser General Public License v3.0
1.72k stars 108 forks source link

Why it is replacing my custom tag attribute underscore with a colon? #106

Closed evandrocoan closed 6 years ago

evandrocoan commented 6 years ago

If I render a code like:

doc = dominate.tags.font( color=first_matched_color, grammar_scope=grammar_scope )

with doc:
    dominate.util.text( matched_text )

When it generates the html, the underscore _ on the name grammar_scope is replaced by a colon :

<font color="#FF0000" grammar:scope="comment.start.sma">//</font>
Knio commented 6 years ago

This is an artifact of some workarounds to make some HTML names more usable in Python, since python variable names cannot contain :. It looks like attribute namespaces are only allowed in a few specific cases however, so I've changed this behavior to only apply then and not in general. (Fixed in 6893d1d, version 2.3.5).

You can always directly set attributes to bypass this behavior, i.e.:

f = font()
f.attributes['grammar_scope'] = 'foo'