1
1
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/11_xml.ipynb.
2
2
3
3
# %% 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' ]
11
12
12
13
# %% ../nbs/11_xml.ipynb
13
14
from .utils import *
19
20
from functools import partial
20
21
from html import escape
21
22
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
-
28
23
# %% ../nbs/11_xml.ipynb
29
24
class FT (list ):
30
25
"A 'Fast Tag' structure, which is a `list` of `[tag,children,attrs]`"
@@ -49,14 +44,21 @@ def __getattr__(self, k):
49
44
return self .attrs [k .lstrip ('_' ).replace ('_' , '-' )]
50
45
51
46
# %% ../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 ):
53
55
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 }
55
57
56
58
# %% ../nbs/11_xml.ipynb
57
- def ft (tag :str , * c , void_ = False , ** kw ):
59
+ def ft (tag :str , * c , void_ = False , attrmap = attrmap , ** kw ):
58
60
"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_ )
60
62
61
63
# %% ../nbs/11_xml.ipynb
62
64
voids = set ('area base br col command embed hr img input keygen link meta param source track wbr !doctype' .split ())
0 commit comments