Skip to content

pyreball.text

Text utils for creating strings with HTML elements.

a

a(*values, cl=None, attrs=None, sep='')

Create a <a> element string with given values.

Parameters:

Name Type Description Default
*values Any

Zero or more values to be enclosed in the tag. All values are converted to strings.

()
cl ClParameter

One or more class names to be added to the tag. If a string is provided, it is used as it is. If a list of strings is provided, the strings are joined with a space. If None, no class is added. If an empty list is provided, class attribute is added with an empty string.

None
attrs AttrsParameter

Additional attributes to be added to the tag. Dictionary {"key1": "value1", ..., "keyN": "valueN"} is converted to key1="value1" ... keyN="valueN". To construct boolean HTML attributes, set None for given key. Any quotes in values are not escaped.

None
sep str

String separator of the values. Defaults to an empty string.

''

Returns:

Type Description
str

HTML string representing the tag with given values.

bold

bold(*values, cl=None, attrs=None, sep='')

Create a <bold> element string with given values.

Parameters:

Name Type Description Default
*values Any

Zero or more values to be enclosed in the tag. All values are converted to strings.

()
cl ClParameter

One or more class names to be added to the tag. If a string is provided, it is used as it is. If a list of strings is provided, the strings are joined with a space. If None, no class is added. If an empty list is provided, class attribute is added with an empty string.

None
attrs AttrsParameter

Additional attributes to be added to the tag. Dictionary {"key1": "value1", ..., "keyN": "valueN"} is converted to key1="value1" ... keyN="valueN". To construct boolean HTML attributes, set None for given key. Any quotes in values are not escaped.

None
sep str

String separator of the values. Defaults to an empty string.

''

Returns:

Type Description
str

HTML string representing the tag with given values.

code

code(*values, cl=None, attrs=None, sep='', syntax_highlight='python')

Create a <code> element string with given values.

This element is used to display a source code inline. It is possible to highlight the code syntax by setting syntax_highlight parameter to an appropriate string.

Parameters:

Name Type Description Default
*values Any

Zero or more values to be enclosed in the tag. All values are converted to strings.

()
cl ClParameter

One or more class names to be added to the tag. If a string is provided, it is used as it is. If a list of strings is provided, the strings are joined with a space. If None, no class is added. If an empty list is provided, class attribute is added with an empty string.

None
attrs AttrsParameter

Additional attributes to be added to the tag. Dictionary {"key1": "value1", ..., "keyN": "valueN"} is converted to key1="value1" ... keyN="valueN". To construct boolean HTML attributes, set None for given key. Any quotes in values are not escaped.

None
sep str

String separator of the values. Defaults to an empty string.

''
syntax_highlight Optional[str]

Syntax highlighting language. Supported values can be obtained from highlight.js table https://github.com/highlightjs/highlight.js/blob/main/SUPPORTED_LANGUAGES.md - see column "Aliases". If None, no highlighting is applied. When highlight is turned on, language name and 'inline-highlight' are added to the element as classes.

'python'

Returns:

Type Description
str

HTML string representing the tag with given values.

code_block

code_block(*values, cl=None, attrs=None, pre_cl=None, pre_attrs=None, sep='', syntax_highlight='python')

Create a <pre><code> pair element string with given values.

This element is used to display a source code in a block. It is possible to highlight the code syntax by setting syntax_highlight parameter to an appropriate string.

Parameters:

Name Type Description Default
*values Any

Zero or more values to be enclosed in the tag. All values are converted to strings.

()
cl ClParameter

One or more class names to be added to the tag. If a string is provided, it is used as it is. If a list of strings is provided, the strings are joined with a space. If None, no class is added. If an empty list is provided, class attribute is added with an empty string. A class is also added when syntax_highlight is set.

None
attrs AttrsParameter

Additional attributes to be added to the tag. Dictionary {"key1": "value1", ..., "keyN": "valueN"} is converted to key1="value1" ... keyN="valueN". To construct boolean HTML attributes, set None for given key. Any quotes in values are not escaped.

None
pre_cl ClParameter

The same as cl parameter, but for the <pre> tag.

None
pre_attrs AttrsParameter

The same as attrs parameter, but for the <pre> tag.

None
sep str

String separator of the values. Defaults to an empty string.

''
syntax_highlight Optional[str]

Syntax highlighting language. Supported values can be obtained from highlight.js table https://github.com/highlightjs/highlight.js/blob/main/SUPPORTED_LANGUAGES.md - see column "Aliases". If None, no highlighting is applied. When highlight is turned on, language name and 'block-highlight' are added to the element as classes.

'python'

Returns:

Type Description
str

HTML string representing the tag with given values.

div

div(*values, cl=None, attrs=None, sep='')

Create a <div> element string with given values.

Parameters:

Name Type Description Default
*values Any

Zero or more values to be enclosed in the tag. All values are converted to strings.

()
cl ClParameter

One or more class names to be added to the tag. If a string is provided, it is used as it is. If a list of strings is provided, the strings are joined with a space. If None, no class is added. If an empty list is provided, class attribute is added with an empty string.

None
attrs AttrsParameter

Additional attributes to be added to the tag. Dictionary {"key1": "value1", ..., "keyN": "valueN"} is converted to key1="value1" ... keyN="valueN". To construct boolean HTML attributes, set None for given key. Any quotes in values are not escaped.

None
sep str

String separator of the values. Defaults to an empty string.

''

Returns:

Type Description
str

HTML string representing the tag with given values.

em

em(*values, cl=None, attrs=None, sep='')

Create a <em> element string with given values.

Parameters:

Name Type Description Default
*values Any

Zero or more values to be enclosed in the tag. All values are converted to strings.

()
cl ClParameter

One or more class names to be added to the tag. If a string is provided, it is used as it is. If a list of strings is provided, the strings are joined with a space. If None, no class is added. If an empty list is provided, class attribute is added with an empty string.

None
attrs AttrsParameter

Additional attributes to be added to the tag. Dictionary {"key1": "value1", ..., "keyN": "valueN"} is converted to key1="value1" ... keyN="valueN". To construct boolean HTML attributes, set None for given key. Any quotes in values are not escaped.

None
sep str

String separator of the values. Defaults to an empty string.

''

Returns:

Type Description
str

HTML string representing the tag with given values.

link(text, href)

Create a <a> element string with given href and text. This function is a shortcut for a() function.

Parameters:

Name Type Description Default
text str

Text of the link.

required
href str

URL of the link.

required

Returns:

Type Description
str

HTML string representing the tag with given values.

olist

olist(*values, cl=None, attrs=None, li_cl=None, li_attrs=None, sep='')

Create a <ol> element string with values being enclosed into <li> tags.

Parameters:

Name Type Description Default
*values Any

Zero or more values to be enclosed in the tag. All values are converted to strings.

()
cl ClParameter

One or more class names to be added to the <ol> tag. If a string is provided, it is used as it is. If a list of strings is provided, the strings are joined with a space. If None, no class is added. If an empty list is provided, class attribute is added with an empty string.

None
attrs AttrsParameter

Additional attributes to be added to the <ol> tag. Dictionary {"key1": "value1", ..., "keyN": "valueN"} is converted to key1="value1" ... keyN="valueN". To construct boolean HTML attributes, set None for given key. Any quotes in values are not escaped.

None
li_cl ClParameter

The same as cl parameter, but for the <li> tag.

None
li_attrs AttrsParameter

The same as attrs parameter, but for the <li> tag.

None
sep str

Separator string to concatenate the values with.

''

Returns:

Type Description
str

HTML string representing the tag with given values.

span

span(*values, cl=None, attrs=None, sep='')

Create a <span> element string with given values.

Parameters:

Name Type Description Default
*values Any

Zero or more values to be enclosed in the tag. All values are converted to strings.

()
cl ClParameter

One or more class names to be added to the tag. If a string is provided, it is used as it is. If a list of strings is provided, the strings are joined with a space. If None, no class is added. If an empty list is provided, class attribute is added with an empty string.

None
attrs AttrsParameter

Additional attributes to be added to the tag. Dictionary {"key1": "value1", ..., "keyN": "valueN"} is converted to key1="value1" ... keyN="valueN". To construct boolean HTML attributes, set None for given key. Any quotes in values are not escaped.

None
sep str

String separator of the values. Defaults to an empty string.

''

Returns:

Type Description
str

HTML string representing the tag with given values.

tag

tag(*values, name, cl=None, attrs=None, sep='', paired=True)

Create a tag string with given values.

Args:

*values: Zero or more values to be enclosed in the tag.
    All values are converted to strings.
name: Name of the tag.
cl: One or more class names to be added to the tag.
    If a string is provided, it is used as it is.
    If a list of strings is provided, the strings are joined with a space.
    If `None`, no class is added.
    If an empty list is provided, class attribute is added with an empty string.
attrs: Additional attributes to be added to the tag.
    Dictionary `{"key1": "value1", ..., "keyN": "valueN"}`
    is converted to `key1="value1" ... keyN="valueN"`.
    To construct boolean HTML attributes,
    set `None` for given key. Any quotes in values are not escaped.
sep: String separator of the values. Defaults to an empty string.
paired: If True, the values are enclosed in a pair of tags.
    Otherwise, unpaired tag is created.

Returns:

Type Description
str

HTML string representing the tag with given values.

ulist

ulist(*values, cl=None, attrs=None, li_cl=None, li_attrs=None, sep='')

Create a <ul> element string with values being enclosed into <li> tags.

Parameters:

Name Type Description Default
*values Any

Zero or more values to be enclosed in the tag. All values are converted to strings.

()
cl ClParameter

One or more class names to be added to the <ul> tag. If a string is provided, it is used as it is. If a list of strings is provided, the strings are joined with a space. If None, no class is added. If an empty list is provided, class attribute is added with an empty string.

None
attrs AttrsParameter

Additional attributes to be added to the <ul> tag. Dictionary {"key1": "value1", ..., "keyN": "valueN"} is converted to key1="value1" ... keyN="valueN". To construct boolean HTML attributes, set None for given key. Any quotes in values are not escaped.

None
li_cl ClParameter

The same as cl parameter, but for the <li> tag.

None
li_attrs AttrsParameter

The same as attrs parameter, but for the <li> tag.

None
sep str

Separator string to concatenate the values with.

''

Returns:

Type Description
str

HTML string representing the tag with given values.