from IPython.display import Markdown
from pprint import pprint
XML
Concise generation of XML.
XT
XT (tag, cs, attrs=None, void_=False, **kwargs)
*Built-in mutable sequence.
If no argument is given, the constructor creates a new empty list. The argument must be an iterable if specified.*
xt
xt (tag:str, *c, void_=False, **kw)
Create an XML tag structure [tag,children,attrs]
for toxml()
The main HTML tags are exported as xt
partials.
Attributes are passed as keywords. Use ‘klass’ and ‘fr’ instead of ‘class’ and ‘for’, to avoid Python reserved word clashes.
Html
Html (*c, doctype=True, **kwargs)
An HTML tag, optionally preceeded by !DOCTYPE HTML
= Html(
samp 'Some page')),
Head(Title('Some text', Input(name='me'), Img(src="filename", data=1), klass='myclass'))
Body(Div(
) pprint(samp)
(['!doctype', (), {'html': True}],
['html',
(['head', (['title', ('Some page',), {}],), {}],
['body',
(['div',
('Some text',
['input', (), {'name': 'me'}],
['img', (), {'data': 1, 'src': 'filename'}]),
{'class': 'myclass'}],),
{}]),
{}])
The three elements of the list can also be accessed with property names, so you don’t have to remember their order.
= P('Some text', id="myid")
elem print(elem.tag)
print(elem.children)
print(elem.attrs)
p
('Some text',)
{'id': 'myid'}
You can also get and set attrs directly:
id = 'newid'
elem.print(elem.id)
elem
newid
['p', ('Some text',), {'id': 'newid'}]
to_xml
to_xml (elm, lvl=0)
Convert xt
element tree into an XML string
= to_xml(samp)
h print(h)
<!doctype html>
<html>
<head>
<title>Some page</title>
</head>
<body>
<div class="myclass">
Some text
<input name="me"></input>
<img src="filename" data="1"></img>
</div>
</body>
</html>
highlight
highlight (s, lang='xml')
Markdown to syntax-highlight s
in language lang
getattr
__getattr__ (tag)