Reference

class pymarkup.MarkupBuilder(element: str = 'html', text: _io.StringIO = <factory>, attrs: Dict = <factory>)[source]

Build basic XML-style markup from context managers.

Instances of this class are individual tags with their own attributes. They can be used in context managers multiple times.

element

The element name to use this tag as (default ‘html’)

Type:str
text

The cumulative text generated by this instance. It is automatically passed down to children, and is created by default, so it is not necessary to pass it in most of the time.

Type:File-like object
attrs

The attributes to put in the opening tag

Type:dict
__add__(other)[source]

Add other to current text.

If other is a MarkupBuilder just run MarkupBuilder.self_closing() on it, otherwise add str(other) to self.text.

Parameters:other (Union[str,MarkupBuilder]) – The other object to add.
__call__(**kwargs)[source]

Change this instance’s attrs to kwargs.

__enter__()[source]

Add opening tag, e.g. <html>

__exit__(exc_type, exc_val, exc_tb)[source]

Add closing tag, e.g. </html>

__getattr__(item)[source]

Return a child of this MarkupBuilder with item as the MarkupBuilder.element

__repr__()[source]

Get the final XML for this MarkupBuilder

__weakref__

list of weak references to the object (if defined)

self_closing()[source]

Add self-closing tag, e.g. <img src=”image.png”/>