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
1314from .utils import *
1920from functools import partial
2021from 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
2924class 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
6264voids = set ('area base br col command embed hr img input keygen link meta param source track wbr !doctype' .split ())
0 commit comments