Skip to content

text

Classes and functions for text markup manipulation.

MarkupText

Text with optional markup.

This class should not be instantiated directly, but only through its class method constructors. This is because the internal representation of the markup text may change at any time.

contains_markup property

contains_markup

True if this text contains markup; False if it is a plain string.

as_html

as_html(allow_url=True)

Returns:

Type Description
str

Text with markup transformed into HTML.

Parameters:

Name Type Description Default
allow_url bool

Defaults to True. If False, URLs are not wrapped in <a href="..."> tags, but in simply <span> tags.

True

as_latex

as_latex()

Returns:

Type Description
str

Text with markup transformed into LaTeX commands.

as_text

as_text()

Returns:

Type Description
str

The plain text with any markup stripped. The only transformation that will be performed is replacing TeX-math expressions with their corresponding Unicode representation, if possible.

from_string classmethod

from_string(text)

Parameters:

Name Type Description Default
text str

A simple text string without any markup.

required

Returns:

Type Description
MarkupText

Instantiated MarkupText object corresponding to the string.

from_xml classmethod

from_xml(element)

Parameters:

Name Type Description Default
element _Element

An XML element containing valid MarkupText according to the schema.

required

Returns:

Type Description
MarkupText

Instantiated MarkupText object corresponding to the element.

to_xml

to_xml(tag='span')

Parameters:

Name Type Description Default
tag str

Name of outer tag in which the text should be wrapped.

'span'

Returns:

Type Description
_Element

A serialization of this MarkupText in Anthology XML format.