11# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/11_xml.ipynb.
22
33# %% auto 0
4- __all__ = ['xt' , 'to_xml' , 'Html' , 'Head' , 'Title' , 'Meta' , 'Link' , 'Style' , 'Body' , 'Pre' , 'Code' , 'Div' , 'Span' , 'P' , 'H1 ' ,
5- 'H2' , 'H3' , 'H4' , 'H5' , 'H6' , 'Strong' , 'Em' , 'B' , 'I' , 'U' , 'S' , 'Strike' , 'Sub' , 'Sup' , 'Hr' , 'Br' , 'Img ' ,
6- 'A' , 'Nav' , 'Ul' , 'Ol' , 'Li' , 'Dl' , 'Dt' , 'Dd' , 'Table' , 'Thead' , 'Tbody' , 'Tfoot' , 'Tr' , 'Th' , 'Td' ,
4+ __all__ = ['voids' , ' xt' , 'to_xml' , 'Html' , 'Head' , 'Title' , 'Meta' , 'Link' , 'Style' , 'Body' , 'Pre' , 'Code' , 'Div' , 'Span' , 'P' ,
5+ 'H1' , ' H2' , 'H3' , 'H4' , 'H5' , 'H6' , 'Strong' , 'Em' , 'B' , 'I' , 'U' , 'S' , 'Strike' , 'Sub' , 'Sup' , 'Hr' , 'Br' ,
6+ 'Img' , ' A' , 'Nav' , 'Ul' , 'Ol' , 'Li' , 'Dl' , 'Dt' , 'Dd' , 'Table' , 'Thead' , 'Tbody' , 'Tfoot' , 'Tr' , 'Th' , 'Td' ,
77 'Caption' , 'Col' , 'Colgroup' , 'Form' , 'Input' , 'Textarea' , 'Button' , 'Select' , 'Option' , 'Label' , 'Fieldset' ,
88 'Legend' , 'Details' , 'Summary' , 'Main' , 'Header' , 'Footer' , 'Section' , 'Article' , 'Aside' , 'Figure' ,
99 'Figcaption' , 'Mark' , 'Small' , 'Iframe' , 'Object' , 'Embed' , 'Param' , 'Video' , 'Audio' , 'Source' , 'Canvas' ,
@@ -43,6 +43,9 @@ def xt(tag:str, *c, **kw):
4343for o in _all_ : _g [o ] = partial (xt , o .lower ())
4444
4545# %% ../nbs/11_xml.ipynb 9
46+ voids = set ('area base br col command embed hr img input keygen link meta param source track wbr' .split ())
47+
48+ # %% ../nbs/11_xml.ipynb 10
4649def to_xml (elm , lvl = 0 ):
4750 "Convert `xt` element tree into an XML string"
4851 if isinstance (elm , tuple ): return '\n ' .join (to_xml (o ) for o in elm )
@@ -58,8 +61,9 @@ def to_xml(elm, lvl=0):
5861 sattrs = (f'{ k } ="{ escape (str (v ), quote = False )} "' for k ,v in attrs .items ())
5962 stag += ' ' + ' ' .join (sattrs )
6063
61- if not cs : return f'{ sp } <{ stag } ></{ tag } >\n '
64+ cltag = '' if tag in voids else f'</{ tag } >'
65+ if not cs : return f'{ sp } <{ stag } >{ cltag } \n '
6266 res = f'{ sp } <{ stag } >\n '
6367 res += '' .join (to_xml (c , lvl = lvl + 2 ) for c in cs )
64- res += f'{ sp } </ { tag } > \n '
68+ if tag not in voids : res += f'{ sp } { cltag } \n '
6569 return res
0 commit comments