diff --git a/fastcore/xml.py b/fastcore/xml.py index fb6bc8c8..fdce0ce7 100644 --- a/fastcore/xml.py +++ b/fastcore/xml.py @@ -46,8 +46,10 @@ def __getattr__(self, k): def get(self, k, default=None): return self[2].get(k.lstrip('_').replace('_', '-'), default) # %% ../nbs/11_xml.ipynb +_specials = set('@.-!~:[](){}$%^&*+=|/?<>,`') + def attrmap(o): - if o=='_': return o + if o=='_' or (_specials & set(o)): return o o = dict(htmlClass='class', cls='class', _class='class', klass='class', _for='for', fr='for', htmlFor='for').get(o, o) return o.lstrip('_').replace('_', '-') diff --git a/nbs/11_xml.ipynb b/nbs/11_xml.ipynb index abf192d8..52a7acda 100644 --- a/nbs/11_xml.ipynb +++ b/nbs/11_xml.ipynb @@ -90,8 +90,10 @@ "outputs": [], "source": [ "#| export\n", + "_specials = set('@.-!~:[](){}$%^&*+=|/?<>,`')\n", + "\n", "def attrmap(o):\n", - " if o=='_': return o\n", + " if o=='_' or (_specials & set(o)): return o\n", " o = dict(htmlClass='class', cls='class', _class='class', klass='class',\n", " _for='for', fr='for', htmlFor='for').get(o, o)\n", " return o.lstrip('_').replace('_', '-')"