formatter
- class mautrix.util.formatter.AbstractEntity
Bases:
abc.ABC
- __init__(type, offset, length, extra_info)
- abstract adjust_offset(offset, max_length=- 1)
- Parameters
- Return type
- abstract copy()
- Return type
- class mautrix.util.formatter.EntityString
Bases:
Generic
[mautrix.util.formatter.entity_string.TEntity
,mautrix.util.formatter.entity_string.TEntityType
],mautrix.util.formatter.FormattedString
- __init__(text='', entities=None)
- append(*args)
Append strings to this FormattedString.
This method may mutate the source object, but it is not required to do so. Make sure to always use the return value when mutating and to duplicate strings if you don’t want the original to change.
- Parameters
*args – The strings to append.
args (str | mautrix.util.formatter.FormattedString) –
- Returns
A FormattedString that is a concatenation of this string and the given strings.
- Return type
- property entities: list[~TEntity]
- entity_class
alias of
mautrix.util.formatter.SimpleEntity
- format(entity_type, offset=None, length=None, **kwargs)
Apply formatting to this FormattedString.
This method may mutate the source object, but it is not required to do so. Make sure to always use the return value when mutating and to duplicate strings if you don’t want the original to change.
- Parameters
- Returns
A FormattedString with the given formatting applied.
- Return type
- classmethod join(items, separator=' ')
Join a list of FormattedStrings with the given separator.
- Parameters
items (Sequence[str | mautrix.util.formatter.EntityString]) – The strings to join.
separator (str) – The separator to join them with.
- Returns
A FormattedString that is a combination of the given strings with the given separator between each one.
- Return type
- prepend(*args)
Prepend strings to this FormattedString.
This method may mutate the source object, but it is not required to do so. Make sure to always use the return value when mutating and to duplicate strings if you don’t want the original to change.
- Parameters
*args – The strings to prepend.
args (str | mautrix.util.formatter.FormattedString) –
- Returns
A FormattedString that is a concatenation of the given strings and this string.
- Return type
- split(separator, max_items=- 1)
Split this FormattedString by the given separator.
- Parameters
separator – The separator to split by.
max_items (int) – The maximum number of items to return. If the limit is reached, the remaining string will be returned as one even if it contains the separator.
- Returns
The split strings.
- Return type
- trim()
Trim surrounding whitespace from this FormattedString.
This method may mutate the source object, but it is not required to do so. Make sure to always use the return value when mutating and to duplicate strings if you don’t want the original to change.
- Returns
A FormattedString without surrounding whitespace.
- Return type
- class mautrix.util.formatter.SemiAbstractEntity
Bases:
mautrix.util.formatter.AbstractEntity
,abc.ABC
- adjust_offset(offset, max_length=- 1)
- Parameters
- Return type
- class mautrix.util.formatter.SimpleEntity
Bases:
mautrix.util.formatter.SemiAbstractEntity
- __init__(type, offset, length, extra_info=NOTHING)
Method generated by attrs for class SimpleEntity.
- copy()
- Return type
- type: EntityType
- class mautrix.util.formatter.EntityType
Bases:
enum.Enum
EntityType is a Matrix formatting entity type.
- BOLD = 1
- ITALIC = 2
- STRIKETHROUGH = 3
- UNDERLINE = 4
- URL = 5
- EMAIL = 6
- USER_MENTION = 7
- ROOM_MENTION = 8
- PREFORMATTED = 9
- INLINE_CODE = 10
- BLOCKQUOTE = 11
- HEADER = 12
- COLOR = 13
- SPOILER = 14
- class mautrix.util.formatter.FormattedString
Bases:
abc.ABC
FormattedString is an abstract HTML parsing target.
- abstract append(*args)
Append strings to this FormattedString.
This method may mutate the source object, but it is not required to do so. Make sure to always use the return value when mutating and to duplicate strings if you don’t want the original to change.
- Parameters
*args – The strings to append.
args (str | mautrix.util.formatter.FormattedString) –
- Returns
A FormattedString that is a concatenation of this string and the given strings.
- Return type
- classmethod concat(*args)
Concatenate many FormattedStrings.
- Parameters
*args – The strings to concatenate.
args (str | mautrix.util.formatter.FormattedString) –
- Returns
A FormattedString that is a concatenation of the given strings.
- Return type
- abstract format(entity_type, **kwargs)
Apply formatting to this FormattedString.
This method may mutate the source object, but it is not required to do so. Make sure to always use the return value when mutating and to duplicate strings if you don’t want the original to change.
- Parameters
entity_type (mautrix.util.formatter.EntityType) – The type of formatting to apply to this string.
**kwargs – Additional metadata required by the formatting type.
- Returns
A FormattedString with the given formatting applied.
- Return type
- abstract classmethod join(items, separator=' ')
Join a list of FormattedStrings with the given separator.
- Parameters
items (Sequence[str | mautrix.util.formatter.FormattedString]) – The strings to join.
separator (str) – The separator to join them with.
- Returns
A FormattedString that is a combination of the given strings with the given separator between each one.
- Return type
- abstract prepend(*args)
Prepend strings to this FormattedString.
This method may mutate the source object, but it is not required to do so. Make sure to always use the return value when mutating and to duplicate strings if you don’t want the original to change.
- Parameters
*args – The strings to prepend.
args (str | mautrix.util.formatter.FormattedString) –
- Returns
A FormattedString that is a concatenation of the given strings and this string.
- Return type
- abstract split(separator, max_items=- 1)
Split this FormattedString by the given separator.
- Parameters
separator – The separator to split by.
max_items (int) – The maximum number of items to return. If the limit is reached, the remaining string will be returned as one even if it contains the separator.
- Returns
The split strings.
- Return type
- abstract trim()
Trim surrounding whitespace from this FormattedString.
This method may mutate the source object, but it is not required to do so. Make sure to always use the return value when mutating and to duplicate strings if you don’t want the original to change.
- Returns
A FormattedString without surrounding whitespace.
- Return type
- class mautrix.util.formatter.MarkdownString
Bases:
mautrix.util.formatter.FormattedString
- append(*args)
Append strings to this FormattedString.
This method may mutate the source object, but it is not required to do so. Make sure to always use the return value when mutating and to duplicate strings if you don’t want the original to change.
- Parameters
*args – The strings to append.
args (Union[str, mautrix.util.formatter.FormattedString]) –
- Returns
A FormattedString that is a concatenation of this string and the given strings.
- Return type
- format(entity_type, **kwargs)
Apply formatting to this FormattedString.
This method may mutate the source object, but it is not required to do so. Make sure to always use the return value when mutating and to duplicate strings if you don’t want the original to change.
- Parameters
entity_type (mautrix.util.formatter.EntityType) – The type of formatting to apply to this string.
**kwargs – Additional metadata required by the formatting type.
- Returns
A FormattedString with the given formatting applied.
- Return type
- classmethod join(items, separator=' ')
Join a list of FormattedStrings with the given separator.
- Parameters
items (Sequence[str | mautrix.util.formatter.FormattedString]) – The strings to join.
separator (str) – The separator to join them with.
- Returns
A FormattedString that is a combination of the given strings with the given separator between each one.
- Return type
- prepend(*args)
Prepend strings to this FormattedString.
This method may mutate the source object, but it is not required to do so. Make sure to always use the return value when mutating and to duplicate strings if you don’t want the original to change.
- Parameters
*args – The strings to prepend.
args (Union[str, mautrix.util.formatter.FormattedString]) –
- Returns
A FormattedString that is a concatenation of the given strings and this string.
- Return type
- split(separator, max_items=- 1)
Split this FormattedString by the given separator.
- Parameters
separator – The separator to split by.
max_items (int) – The maximum number of items to return. If the limit is reached, the remaining string will be returned as one even if it contains the separator.
- Returns
The split strings.
- Return type
- trim()
Trim surrounding whitespace from this FormattedString.
This method may mutate the source object, but it is not required to do so. Make sure to always use the return value when mutating and to duplicate strings if you don’t want the original to change.
- Returns
A FormattedString without surrounding whitespace.
- Return type
- class mautrix.util.formatter.MatrixParser
Bases:
Generic
[mautrix.util.formatter.parser.T
]- async basic_format_to_fstring(node, ctx)
- Parameters
node (mautrix.util.formatter.HTMLNode) –
- Return type
mautrix.util.formatter.parser.T
- block_tags: tuple[str, ...] = ('p', 'pre', 'blockquote', 'ol', 'ul', 'li', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'div', 'hr', 'table')
- async blockquote_to_fstring(node, ctx)
- Parameters
node (mautrix.util.formatter.HTMLNode) –
- Return type
mautrix.util.formatter.parser.T
- async color_to_fstring(msg, color)
- Parameters
msg (mautrix.util.formatter.parser.T) –
color (str) –
- Return type
mautrix.util.formatter.parser.T
- async custom_node_to_fstring(node, ctx)
- Parameters
node (mautrix.util.formatter.HTMLNode) –
- Return type
Optional[mautrix.util.formatter.parser.T]
- e
alias of
mautrix.util.formatter.EntityType
- async event_link_to_fstring(msg, room, event_id)
- Parameters
msg (mautrix.util.formatter.parser.T) –
room (Union[mautrix.types.RoomID, mautrix.types.RoomAlias]) –
event_id (mautrix.types.EventID) –
- Return type
Optional[mautrix.util.formatter.parser.T]
- fs
- async header_to_fstring(node, ctx)
- Parameters
node (mautrix.util.formatter.HTMLNode) –
- Return type
mautrix.util.formatter.parser.T
- async hr_to_fstring(node, ctx)
- Parameters
node (mautrix.util.formatter.HTMLNode) –
- Return type
mautrix.util.formatter.parser.T
- async img_to_fstring(node, ctx)
- Parameters
node (mautrix.util.formatter.HTMLNode) –
- Return type
mautrix.util.formatter.parser.T
- async link_to_fstring(node, ctx)
- Parameters
node (mautrix.util.formatter.HTMLNode) –
- Return type
mautrix.util.formatter.parser.T
- async list_to_fstring(node, ctx)
- Parameters
node (mautrix.util.formatter.HTMLNode) –
- Return type
mautrix.util.formatter.parser.T
- async node_to_fstring(node, ctx)
- Parameters
node (mautrix.util.formatter.HTMLNode) –
- Return type
mautrix.util.formatter.parser.T
- async node_to_fstrings(node, ctx)
- Parameters
node (mautrix.util.formatter.HTMLNode) –
- Return type
list[~T]
- async node_to_tagged_fstrings(node, ctx)
- Parameters
node (mautrix.util.formatter.HTMLNode) –
- Return type
- async parse_node(node, ctx)
- Parameters
node (mautrix.util.formatter.HTMLNode) –
- Return type
mautrix.util.formatter.parser.T
- async room_id_link_to_fstring(msg, room_id)
- Parameters
msg (mautrix.util.formatter.parser.T) –
room_id (mautrix.types.RoomID) –
- Return type
Optional[mautrix.util.formatter.parser.T]
- async room_pill_to_fstring(msg, room_alias)
- Parameters
msg (mautrix.util.formatter.parser.T) –
room_alias (mautrix.types.RoomAlias) –
- Return type
Optional[mautrix.util.formatter.parser.T]
- async spoiler_to_fstring(msg, reason)
- Parameters
msg (mautrix.util.formatter.parser.T) –
reason (str) –
- Return type
mautrix.util.formatter.parser.T
- async tag_aware_parse_node(node, ctx)
- Parameters
node (mautrix.util.formatter.HTMLNode) –
- Return type
mautrix.util.formatter.parser.T
- async text_to_fstring(text, ctx, strip_leading_whitespace=False)
- async url_to_fstring(msg, url)
- Parameters
msg (mautrix.util.formatter.parser.T) –
url (str) –
- Return type
Optional[mautrix.util.formatter.parser.T]
- async user_pill_to_fstring(msg, user_id)
- Parameters
msg (mautrix.util.formatter.parser.T) –
user_id (mautrix.types.UserID) –
- Return type
Optional[mautrix.util.formatter.parser.T]