XHTML Format

Utilities for formatting html strings and text.

exception disseminate.formats.xhtml.XHtmlFormatError

Bases: disseminate.formats.exceptions.FormattingError

Error in xhtml formatting.

disseminate.formats.xhtml.xhtml_entity(entity, level=1, method='html', pretty_print=True)

Format an html entity string.

Parameters
entitystr

an html entity string

levelOptional[str]

The level of the tag.

methodOptional[str]

The rendering method. ‘html’, ‘xhtml’ or ‘xml’

pretty_printOptional[bool]

If True, make the formatted html pretty–i.e. with newlines and spacing for nested tags.

Returns
xhtmlstr

The entity formatted in xhtml.

Raises
XHtmlFormatError

Raised if the contents of the tag aren’t a simple string. i.e. nested tags are not allowed.

Examples

>>> xhtml_entity('alpha')
Markup('α\n')
disseminate.formats.xhtml.xhtml_list(*elements, attributes=None, listtype='ol', level=1, target=None, method='html', pretty_print=True, inner=False)

A xhtml list element.

Parameters
elementsTuple[Tuple[int, lxml.builder.E]]

Each element is a tuple of the list element level and the ‘li’ lxml element.

attributesOptional[Union[Attributes, str]]

The attributes of the tag.

listtypeOptional[str]

The type of list to create. ex: ul, ol

levelOptional[int]

The level of the tag.

targetOptional[str]

If speficied, filter the attributes that match the given target.

methodOptional[str]

The rendering method. ‘html’, ‘xhtml’ or ‘xml’

pretty_printOptional[bool]

If True, make the formatted html pretty–i.e. with newlines and spacing for nested tags.

innerOptional[bool]

If True, this function is invoked as an inner html list. This is useful for adding html attributes only to the outer list.

Returns
xhtmlstr

If level=1, a string formatted in html if level>1, an html element (lxml.build.E)

Raises
XHtmlFormatErrorHtmlFormatError

A TagError is raised if a non-allowed list environment is used

disseminate.formats.xhtml.xhtml_tag(name, attributes=None, formatted_content=None, level=1, target=None, method='html', nsmap=None, pretty_print=True)

Format an xhtml tag string.

Parameters
nameOptional[str]

The name of the html tag.

attributesOptional[Union[Attributes, str]]

The attributes of the tag.

formatted_contentOptional[Union[str, list, lxml.builder.E]]

The contents of the html tag.

levelOptional[int]

The level of the tag.

targetOptional[str]

If speficied, filter the attributes that match the given target.

methodOptional[str]

The rendering method. ‘html’, ‘xhtml’ or ‘xml’

nsmapOptional[dict]

Optional namespace map to create the tag with.

pretty_printOptional[bool]

If True, make the formatted html pretty–i.e. with newlines and spacing for nested tags.

Returns
htmlstr

If level=1, a string formatted in (x)html if level>1, an html element (lxml.build.E)

Raises
XHtmlFormatErrorXHtmlFormatError

A TagError is raised if a non-allowed environment is used

Examples

>>> xhtml_tag('img', attributes="src='test.svg'")
Markup('<img src="test.svg">\n')
>>> xhtml_tag('img', attributes="src='test.svg'", method='xml')
Markup('<img src="test.svg"/>\n')