Skip to content

Commit 33e22e3

Browse files
committed
move named to fasthtml
1 parent e3f96f9 commit 33e22e3

File tree

2 files changed

+41
-83
lines changed

2 files changed

+41
-83
lines changed

fastcore/xml.py

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

33
# %% auto 0
4-
__all__ = ['named', 'voids', 'XT', 'xt', 'to_xml', 'Html', 'Head', 'Title', 'Meta', 'Link', 'Style', 'Body', 'Pre', 'Code', 'Div',
5-
'Span', 'P', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'Strong', 'Em', 'B', 'I', 'U', 'S', 'Strike', 'Sub', 'Sup',
6-
'Hr', 'Br', 'Img', 'A', 'Nav', 'Ul', 'Ol', 'Li', 'Dl', 'Dt', 'Dd', 'Table', 'Thead', 'Tbody', 'Tfoot', 'Tr',
7-
'Th', 'Td', 'Caption', 'Col', 'Colgroup', 'Form', 'Input', 'Textarea', 'Button', 'Select', 'Option', 'Label',
4+
__all__ = ['voids', 'XT', 'xt', 'to_xml', 'Html', 'Head', 'Title', 'Meta', 'Link', 'Style', 'Body', 'Pre', 'Code', 'Div', 'Span',
5+
'P', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'Strong', 'Em', 'B', 'I', 'U', 'S', 'Strike', 'Sub', 'Sup', 'Hr',
6+
'Br', 'Img', 'A', 'Nav', 'Ul', 'Ol', 'Li', 'Dl', 'Dt', 'Dd', 'Table', 'Thead', 'Tbody', 'Tfoot', 'Tr', 'Th',
7+
'Td', 'Caption', 'Col', 'Colgroup', 'Form', 'Input', 'Textarea', 'Button', 'Select', 'Option', 'Label',
88
'Fieldset', 'Legend', 'Details', 'Summary', 'Main', 'Header', 'Footer', 'Section', 'Article', 'Aside',
99
'Figure', 'Figcaption', 'Mark', 'Small', 'Iframe', 'Object', 'Embed', 'Param', 'Video', 'Audio', 'Source',
1010
'Canvas', 'Svg', 'Math', 'Script', 'Noscript', 'Template', 'Slot']
@@ -23,37 +23,33 @@ def _attrmap(o):
2323
return o.lstrip('_').replace('_', '-')
2424

2525
# %% ../nbs/11_xml.ipynb 5
26-
named = set('a button form frame iframe img input map meta object param select textarea'.split())
26+
class XT(list): pass
2727

2828
# %% ../nbs/11_xml.ipynb 6
29-
class XT(list): patch
30-
31-
# %% ../nbs/11_xml.ipynb 7
3229
def xt(tag:str, *c, **kw):
3330
"Create an XML tag structure `[tag,children,attrs]` for `toxml()`"
3431
if len(c)==1 and isinstance(c[0], types.GeneratorType): c = tuple(c[0])
3532
kw = {_attrmap(k):str(v) for k,v in kw.items() if v is not None}
36-
if tag in named and 'id' in kw and 'name' not in kw: kw['name'] = kw['id']
3733
return XT([tag.lower(),c,kw])
3834

39-
# %% ../nbs/11_xml.ipynb 8
35+
# %% ../nbs/11_xml.ipynb 7
4036
_g = globals()
4137
_all_ = ['Html', 'Head', 'Title', 'Meta', 'Link', 'Style', 'Body', 'Pre', 'Code',
42-
'Div', 'Span', 'P', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'Strong', 'Em', 'B',
43-
'I', 'U', 'S', 'Strike', 'Sub', 'Sup', 'Hr', 'Br', 'Img', 'A', 'Link', 'Nav',
44-
'Ul', 'Ol', 'Li', 'Dl', 'Dt', 'Dd', 'Table', 'Thead', 'Tbody', 'Tfoot', 'Tr',
45-
'Th', 'Td', 'Caption', 'Col', 'Colgroup', 'Form', 'Input', 'Textarea',
46-
'Button', 'Select', 'Option', 'Label', 'Fieldset', 'Legend', 'Details',
47-
'Summary', 'Main', 'Header', 'Footer', 'Section', 'Article', 'Aside', 'Figure',
48-
'Figcaption', 'Mark', 'Small', 'Iframe', 'Object', 'Embed', 'Param', 'Video',
49-
'Audio', 'Source', 'Canvas', 'Svg', 'Math', 'Script', 'Noscript', 'Template', 'Slot']
38+
'Div', 'Span', 'P', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'Strong', 'Em', 'B',
39+
'I', 'U', 'S', 'Strike', 'Sub', 'Sup', 'Hr', 'Br', 'Img', 'A', 'Link', 'Nav',
40+
'Ul', 'Ol', 'Li', 'Dl', 'Dt', 'Dd', 'Table', 'Thead', 'Tbody', 'Tfoot', 'Tr',
41+
'Th', 'Td', 'Caption', 'Col', 'Colgroup', 'Form', 'Input', 'Textarea',
42+
'Button', 'Select', 'Option', 'Label', 'Fieldset', 'Legend', 'Details',
43+
'Summary', 'Main', 'Header', 'Footer', 'Section', 'Article', 'Aside', 'Figure',
44+
'Figcaption', 'Mark', 'Small', 'Iframe', 'Object', 'Embed', 'Param', 'Video',
45+
'Audio', 'Source', 'Canvas', 'Svg', 'Math', 'Script', 'Noscript', 'Template', 'Slot']
5046

5147
for o in _all_: _g[o] = partial(xt, o.lower())
5248

53-
# %% ../nbs/11_xml.ipynb 13
49+
# %% ../nbs/11_xml.ipynb 10
5450
voids = set('area base br col command embed hr img input keygen link meta param source track wbr'.split())
5551

56-
# %% ../nbs/11_xml.ipynb 14
52+
# %% ../nbs/11_xml.ipynb 11
5753
def to_xml(elm, lvl=0):
5854
"Convert `xt` element tree into an XML string"
5955
if isinstance(elm, tuple): return '\n'.join(to_xml(o) for o in elm)
@@ -76,7 +72,7 @@ def to_xml(elm, lvl=0):
7672
if tag not in voids: res += f'{sp}{cltag}\n'
7773
return res
7874

79-
# %% ../nbs/11_xml.ipynb 16
75+
# %% ../nbs/11_xml.ipynb 13
8076
@patch
8177
def _repr_markdown_(self:XT):
8278
try: from IPython import display

nbs/11_xml.ipynb

Lines changed: 24 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"cells": [
33
{
44
"cell_type": "code",
5-
"execution_count": 1,
5+
"execution_count": 37,
66
"id": "d0c84aa5",
77
"metadata": {},
88
"outputs": [],
@@ -22,7 +22,7 @@
2222
},
2323
{
2424
"cell_type": "code",
25-
"execution_count": 2,
25+
"execution_count": 38,
2626
"id": "55944805",
2727
"metadata": {},
2828
"outputs": [],
@@ -38,7 +38,7 @@
3838
},
3939
{
4040
"cell_type": "code",
41-
"execution_count": 3,
41+
"execution_count": 39,
4242
"id": "42d18e5c",
4343
"metadata": {},
4444
"outputs": [],
@@ -49,7 +49,7 @@
4949
},
5050
{
5151
"cell_type": "code",
52-
"execution_count": 4,
52+
"execution_count": 40,
5353
"id": "4dbb9a59",
5454
"metadata": {},
5555
"outputs": [],
@@ -62,29 +62,18 @@
6262
},
6363
{
6464
"cell_type": "code",
65-
"execution_count": 5,
66-
"id": "725f87d7",
67-
"metadata": {},
68-
"outputs": [],
69-
"source": [
70-
"#| export\n",
71-
"named = set('a button form frame iframe img input map meta object param select textarea'.split())"
72-
]
73-
},
74-
{
75-
"cell_type": "code",
76-
"execution_count": 6,
65+
"execution_count": 41,
7766
"id": "149067dd",
7867
"metadata": {},
7968
"outputs": [],
8069
"source": [
8170
"#|export\n",
82-
"class XT(list): patch"
71+
"class XT(list): pass"
8372
]
8473
},
8574
{
8675
"cell_type": "code",
87-
"execution_count": 7,
76+
"execution_count": 42,
8877
"id": "06718948",
8978
"metadata": {},
9079
"outputs": [],
@@ -94,28 +83,27 @@
9483
" \"Create an XML tag structure `[tag,children,attrs]` for `toxml()`\"\n",
9584
" if len(c)==1 and isinstance(c[0], types.GeneratorType): c = tuple(c[0])\n",
9685
" kw = {_attrmap(k):str(v) for k,v in kw.items() if v is not None}\n",
97-
" if tag in named and 'id' in kw and 'name' not in kw: kw['name'] = kw['id']\n",
9886
" return XT([tag.lower(),c,kw])"
9987
]
10088
},
10189
{
10290
"cell_type": "code",
103-
"execution_count": 8,
91+
"execution_count": 43,
10492
"id": "45489975",
10593
"metadata": {},
10694
"outputs": [],
10795
"source": [
10896
"#| export\n",
10997
"_g = globals()\n",
11098
"_all_ = ['Html', 'Head', 'Title', 'Meta', 'Link', 'Style', 'Body', 'Pre', 'Code',\n",
111-
"'Div', 'Span', 'P', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'Strong', 'Em', 'B',\n",
112-
"'I', 'U', 'S', 'Strike', 'Sub', 'Sup', 'Hr', 'Br', 'Img', 'A', 'Link', 'Nav',\n",
113-
"'Ul', 'Ol', 'Li', 'Dl', 'Dt', 'Dd', 'Table', 'Thead', 'Tbody', 'Tfoot', 'Tr',\n",
114-
"'Th', 'Td', 'Caption', 'Col', 'Colgroup', 'Form', 'Input', 'Textarea',\n",
115-
"'Button', 'Select', 'Option', 'Label', 'Fieldset', 'Legend', 'Details',\n",
116-
"'Summary', 'Main', 'Header', 'Footer', 'Section', 'Article', 'Aside', 'Figure',\n",
117-
"'Figcaption', 'Mark', 'Small', 'Iframe', 'Object', 'Embed', 'Param', 'Video',\n",
118-
"'Audio', 'Source', 'Canvas', 'Svg', 'Math', 'Script', 'Noscript', 'Template', 'Slot']\n",
99+
" 'Div', 'Span', 'P', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6', 'Strong', 'Em', 'B',\n",
100+
" 'I', 'U', 'S', 'Strike', 'Sub', 'Sup', 'Hr', 'Br', 'Img', 'A', 'Link', 'Nav',\n",
101+
" 'Ul', 'Ol', 'Li', 'Dl', 'Dt', 'Dd', 'Table', 'Thead', 'Tbody', 'Tfoot', 'Tr',\n",
102+
" 'Th', 'Td', 'Caption', 'Col', 'Colgroup', 'Form', 'Input', 'Textarea',\n",
103+
" 'Button', 'Select', 'Option', 'Label', 'Fieldset', 'Legend', 'Details',\n",
104+
" 'Summary', 'Main', 'Header', 'Footer', 'Section', 'Article', 'Aside', 'Figure',\n",
105+
" 'Figcaption', 'Mark', 'Small', 'Iframe', 'Object', 'Embed', 'Param', 'Video',\n",
106+
" 'Audio', 'Source', 'Canvas', 'Svg', 'Math', 'Script', 'Noscript', 'Template', 'Slot']\n",
119107
"\n",
120108
"for o in _all_: _g[o] = partial(xt, o.lower())"
121109
]
@@ -132,7 +120,7 @@
132120
},
133121
{
134122
"cell_type": "code",
135-
"execution_count": 9,
123+
"execution_count": 44,
136124
"id": "9a8b4ddb",
137125
"metadata": {},
138126
"outputs": [
@@ -161,35 +149,9 @@
161149
"pprint(samp)"
162150
]
163151
},
164-
{
165-
"cell_type": "markdown",
166-
"id": "1b030be9",
167-
"metadata": {},
168-
"source": [
169-
"For tags that have a `name` attribute, it will be set to the value of `id` if not provided explicitly:"
170-
]
171-
},
172-
{
173-
"cell_type": "code",
174-
"execution_count": 10,
175-
"id": "b781057c",
176-
"metadata": {},
177-
"outputs": [
178-
{
179-
"name": "stdout",
180-
"output_type": "stream",
181-
"text": [
182-
"['button', (), {'id': 'btn', 'name': 'btn'}]\n"
183-
]
184-
}
185-
],
186-
"source": [
187-
"pprint(Button(id='btn'))"
188-
]
189-
},
190152
{
191153
"cell_type": "code",
192-
"execution_count": 13,
154+
"execution_count": 45,
193155
"id": "c7de63a4",
194156
"metadata": {},
195157
"outputs": [],
@@ -200,7 +162,7 @@
200162
},
201163
{
202164
"cell_type": "code",
203-
"execution_count": 14,
165+
"execution_count": 46,
204166
"id": "b89d088a",
205167
"metadata": {},
206168
"outputs": [],
@@ -231,7 +193,7 @@
231193
},
232194
{
233195
"cell_type": "code",
234-
"execution_count": 15,
196+
"execution_count": 47,
235197
"id": "d3d23c48",
236198
"metadata": {},
237199
"outputs": [
@@ -265,7 +227,7 @@
265227
},
266228
{
267229
"cell_type": "code",
268-
"execution_count": 16,
230+
"execution_count": 48,
269231
"id": "798ae1d2",
270232
"metadata": {},
271233
"outputs": [],
@@ -288,7 +250,7 @@
288250
},
289251
{
290252
"cell_type": "code",
291-
"execution_count": 17,
253+
"execution_count": 49,
292254
"id": "b94a79b9",
293255
"metadata": {},
294256
"outputs": [
@@ -328,7 +290,7 @@
328290
" {}]"
329291
]
330292
},
331-
"execution_count": 17,
293+
"execution_count": 49,
332294
"metadata": {},
333295
"output_type": "execute_result"
334296
}
@@ -347,7 +309,7 @@
347309
},
348310
{
349311
"cell_type": "code",
350-
"execution_count": 1,
312+
"execution_count": 51,
351313
"id": "ad32b076",
352314
"metadata": {},
353315
"outputs": [],

0 commit comments

Comments
 (0)