Skip to content

Commit 354b408

Browse files
committed
fixes #595
1 parent 91acd13 commit 354b408

File tree

3 files changed

+39
-36
lines changed

3 files changed

+39
-36
lines changed

fastcore/_modidx.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,10 +571,10 @@
571571
'fastcore.xml.FT.tag': ('xml.html#ft.tag', 'fastcore/xml.py'),
572572
'fastcore.xml.Html': ('xml.html#html', 'fastcore/xml.py'),
573573
'fastcore.xml.__getattr__': ('xml.html#__getattr__', 'fastcore/xml.py'),
574-
'fastcore.xml._attrmap': ('xml.html#_attrmap', 'fastcore/xml.py'),
575574
'fastcore.xml._escape': ('xml.html#_escape', 'fastcore/xml.py'),
576575
'fastcore.xml._preproc': ('xml.html#_preproc', 'fastcore/xml.py'),
577576
'fastcore.xml._to_attr': ('xml.html#_to_attr', 'fastcore/xml.py'),
577+
'fastcore.xml.attrmap': ('xml.html#attrmap', 'fastcore/xml.py'),
578578
'fastcore.xml.ft': ('xml.html#ft', 'fastcore/xml.py'),
579579
'fastcore.xml.highlight': ('xml.html#highlight', 'fastcore/xml.py'),
580580
'fastcore.xml.showtags': ('xml.html#showtags', 'fastcore/xml.py'),

fastcore/xml.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/11_xml.ipynb.
22

33
# %% auto 0
4-
__all__ = ['voids', 'FT', 'ft', 'Html', 'to_xml', 'highlight', 'showtags', 'Head', 'Title', 'Meta', 'Link', 'Style', 'Body',
5-
'Pre', 'Code', 'Div', 'Span', 'P', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'Strong', 'Em', 'B', 'I', 'U', 'S',
6-
'Strike', 'Sub', 'Sup', 'Hr', 'Br', 'Img', 'A', 'Nav', 'Ul', 'Ol', 'Li', 'Dl', 'Dt', 'Dd', 'Table', 'Thead',
7-
'Tbody', 'Tfoot', 'Tr', 'Th', 'Td', 'Caption', 'Col', 'Colgroup', 'Form', 'Input', 'Textarea', 'Button',
8-
'Select', 'Option', 'Label', 'Fieldset', 'Legend', 'Details', 'Summary', 'Main', 'Header', 'Footer',
9-
'Section', 'Article', 'Aside', 'Figure', 'Figcaption', 'Mark', 'Small', 'Iframe', 'Object', 'Embed', 'Param',
10-
'Video', 'Audio', 'Source', 'Canvas', 'Svg', 'Math', 'Script', 'Noscript', 'Template', 'Slot']
4+
__all__ = ['voids', 'FT', 'attrmap', 'ft', 'Html', 'to_xml', 'highlight', 'showtags', 'Head', 'Title', 'Meta', 'Link', 'Style',
5+
'Body', 'Pre', 'Code', 'Div', 'Span', 'P', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'Strong', 'Em', 'B', 'I', 'U',
6+
'S', 'Strike', 'Sub', 'Sup', 'Hr', 'Br', 'Img', 'A', 'Nav', 'Ul', 'Ol', 'Li', 'Dl', 'Dt', 'Dd', 'Table',
7+
'Thead', 'Tbody', 'Tfoot', 'Tr', 'Th', 'Td', 'Caption', 'Col', 'Colgroup', 'Form', 'Input', 'Textarea',
8+
'Button', 'Select', 'Option', 'Label', 'Fieldset', 'Legend', 'Details', 'Summary', 'Main', 'Header',
9+
'Footer', 'Section', 'Article', 'Aside', 'Figure', 'Figcaption', 'Mark', 'Small', 'Iframe', 'Object',
10+
'Embed', 'Param', 'Video', 'Audio', 'Source', 'Canvas', 'Svg', 'Math', 'Script', 'Noscript', 'Template',
11+
'Slot']
1112

1213
# %% ../nbs/11_xml.ipynb
1314
from .utils import *
@@ -19,12 +20,6 @@
1920
from functools import partial
2021
from html import escape
2122

22-
# %% ../nbs/11_xml.ipynb
23-
def _attrmap(o):
24-
o = dict(htmlClass='class', cls='class', _class='class', klass='class',
25-
_for='for', fr='for', htmlFor='for').get(o, o)
26-
return o.lstrip('_').replace('_', '-')
27-
2823
# %% ../nbs/11_xml.ipynb
2924
class FT(list):
3025
"A 'Fast Tag' structure, which is a `list` of `[tag,children,attrs]`"
@@ -49,14 +44,21 @@ def __getattr__(self, k):
4944
return self.attrs[k.lstrip('_').replace('_', '-')]
5045

5146
# %% ../nbs/11_xml.ipynb
52-
def _preproc(c, kw):
47+
def attrmap(o):
48+
if o=='_': return o
49+
o = dict(htmlClass='class', cls='class', _class='class', klass='class',
50+
_for='for', fr='for', htmlFor='for').get(o, o)
51+
return o.lstrip('_').replace('_', '-')
52+
53+
# %% ../nbs/11_xml.ipynb
54+
def _preproc(c, kw, attrmap=attrmap):
5355
if len(c)==1 and isinstance(c[0], (types.GeneratorType, map, filter)): c = tuple(c[0])
54-
return c,{_attrmap(k):v for k,v in kw.items() if v is not None}
56+
return c,{attrmap(k):v for k,v in kw.items() if v is not None}
5557

5658
# %% ../nbs/11_xml.ipynb
57-
def ft(tag:str, *c, void_=False, **kw):
59+
def ft(tag:str, *c, void_=False, attrmap=attrmap, **kw):
5860
"Create an `FT` structure for `to_xml()`"
59-
return FT(tag.lower(),*_preproc(c,kw), void_=void_)
61+
return FT(tag.lower(),*_preproc(c,kw,attrmap=attrmap), void_=void_)
6062

6163
# %% ../nbs/11_xml.ipynb
6264
voids = set('area base br col command embed hr img input keygen link meta param source track wbr !doctype'.split())

nbs/11_xml.ipynb

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,6 @@
4949
"from pprint import pprint"
5050
]
5151
},
52-
{
53-
"cell_type": "code",
54-
"execution_count": null,
55-
"id": "4dbb9a59",
56-
"metadata": {},
57-
"outputs": [],
58-
"source": [
59-
"#| export\n",
60-
"def _attrmap(o):\n",
61-
" o = dict(htmlClass='class', cls='class', _class='class', klass='class',\n",
62-
" _for='for', fr='for', htmlFor='for').get(o, o)\n",
63-
" return o.lstrip('_').replace('_', '-')"
64-
]
65-
},
6652
{
6753
"cell_type": "code",
6854
"execution_count": null,
@@ -94,6 +80,21 @@
9480
" return self.attrs[k.lstrip('_').replace('_', '-')]"
9581
]
9682
},
83+
{
84+
"cell_type": "code",
85+
"execution_count": null,
86+
"id": "d6069e01",
87+
"metadata": {},
88+
"outputs": [],
89+
"source": [
90+
"#| export\n",
91+
"def attrmap(o):\n",
92+
" if o=='_': return o\n",
93+
" o = dict(htmlClass='class', cls='class', _class='class', klass='class',\n",
94+
" _for='for', fr='for', htmlFor='for').get(o, o)\n",
95+
" return o.lstrip('_').replace('_', '-')"
96+
]
97+
},
9798
{
9899
"cell_type": "code",
99100
"execution_count": null,
@@ -102,9 +103,9 @@
102103
"outputs": [],
103104
"source": [
104105
"#|export\n",
105-
"def _preproc(c, kw):\n",
106+
"def _preproc(c, kw, attrmap=attrmap):\n",
106107
" if len(c)==1 and isinstance(c[0], (types.GeneratorType, map, filter)): c = tuple(c[0])\n",
107-
" return c,{_attrmap(k):v for k,v in kw.items() if v is not None}"
108+
" return c,{attrmap(k):v for k,v in kw.items() if v is not None}"
108109
]
109110
},
110111
{
@@ -115,9 +116,9 @@
115116
"outputs": [],
116117
"source": [
117118
"#| export\n",
118-
"def ft(tag:str, *c, void_=False, **kw):\n",
119+
"def ft(tag:str, *c, void_=False, attrmap=attrmap, **kw):\n",
119120
" \"Create an `FT` structure for `to_xml()`\"\n",
120-
" return FT(tag.lower(),*_preproc(c,kw), void_=void_)"
121+
" return FT(tag.lower(),*_preproc(c,kw,attrmap=attrmap), void_=void_)"
121122
]
122123
},
123124
{

0 commit comments

Comments
 (0)