pyreball.text
Text utils for creating strings with HTML elements.
a
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
|
attrs
|
AttrsParameter
|
Additional attributes to be added to the tag.
Dictionary |
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
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
|
attrs
|
AttrsParameter
|
Additional attributes to be added to the tag.
Dictionary |
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
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
|
attrs
|
AttrsParameter
|
Additional attributes to be added to the tag.
Dictionary |
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 |
'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 |
None
|
attrs
|
AttrsParameter
|
Additional attributes to be added to the |
None
|
pre_cl
|
ClParameter
|
The same as |
None
|
pre_attrs
|
AttrsParameter
|
The same as |
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 |
'python'
|
Returns:
| Type | Description |
|---|---|
str
|
HTML string representing the tag with given values. |
div
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
|
attrs
|
AttrsParameter
|
Additional attributes to be added to the tag.
Dictionary |
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
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
|
attrs
|
AttrsParameter
|
Additional attributes to be added to the tag.
Dictionary |
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
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
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 |
None
|
attrs
|
AttrsParameter
|
Additional attributes to be added to the |
None
|
li_cl
|
ClParameter
|
The same as |
None
|
li_attrs
|
AttrsParameter
|
The same as |
None
|
sep
|
str
|
Separator string to concatenate the values with. |
''
|
Returns:
| Type | Description |
|---|---|
str
|
HTML string representing the tag with given values. |
span
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
|
attrs
|
AttrsParameter
|
Additional attributes to be added to the tag.
Dictionary |
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
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
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 |
None
|
attrs
|
AttrsParameter
|
Additional attributes to be added to the |
None
|
li_cl
|
ClParameter
|
The same as |
None
|
li_attrs
|
AttrsParameter
|
The same as |
None
|
sep
|
str
|
Separator string to concatenate the values with. |
''
|
Returns:
| Type | Description |
|---|---|
str
|
HTML string representing the tag with given values. |