formatter
- class mautrix.util.formatter.AbstractEntity
Bases:
ABC
- __init__(type, offset, length, extra_info)
- abstractmethod adjust_offset(offset, max_length=-1)
- Parameters:
- Return type:
AbstractEntity | None
- abstractmethod copy()
- Return type:
- class mautrix.util.formatter.EntityString
Bases:
Generic
[TEntity
,TEntityType
],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 (str | FormattedString) – The strings to append.
- Returns:
A FormattedString that is a concatenation of this string and the given strings.
- Return type:
- entity_class
alias of
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 | 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 (str | FormattedString) – The strings to prepend.
- 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:
AbstractEntity
,ABC
- adjust_offset(offset, max_length=-1)
- Parameters:
- Return type:
SemiAbstractEntity | None
- class mautrix.util.formatter.SimpleEntity
Bases:
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
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
FormattedString is an abstract HTML parsing target.
- abstractmethod 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 (str | FormattedString) – The strings to append.
- Returns:
A FormattedString that is a concatenation of this string and the given strings.
- Return type:
- classmethod concat(*args)
Concatenate many FormattedStrings.
- Parameters:
*args (str | FormattedString) – The strings to concatenate.
- Returns:
A FormattedString that is a concatenation of the given strings.
- Return type:
- abstractmethod 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 (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:
- abstractmethod classmethod join(items, separator=' ')
Join a list of FormattedStrings with the given separator.
- Parameters:
items (Sequence[str | 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:
- abstractmethod 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 (str | FormattedString) – The strings to prepend.
- Returns:
A FormattedString that is a concatenation of the given strings and this string.
- Return type:
- abstractmethod 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:
- abstractmethod 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:
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 (str | FormattedString) – The strings to append.
- 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 (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 | 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 (str | FormattedString) – The strings to prepend.
- 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
[T
]- async basic_format_to_fstring(node, ctx)
- Parameters:
node (HTMLNode)
ctx (RecursionContext)
- Return type:
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 (HTMLNode)
ctx (RecursionContext)
- Return type:
T
- async custom_node_to_fstring(node, ctx)
- Parameters:
node (HTMLNode)
ctx (RecursionContext)
- Return type:
T | None
- e
alias of
EntityType
- async event_link_to_fstring(msg, room, event_id)
- fs
alias of
MarkdownString
- async header_to_fstring(node, ctx)
- Parameters:
node (HTMLNode)
ctx (RecursionContext)
- Return type:
T
- async hr_to_fstring(node, ctx)
- Parameters:
node (HTMLNode)
ctx (RecursionContext)
- Return type:
T
- async img_to_fstring(node, ctx)
- Parameters:
node (HTMLNode)
ctx (RecursionContext)
- Return type:
T
- async link_to_fstring(node, ctx)
- Parameters:
node (HTMLNode)
ctx (RecursionContext)
- Return type:
T
- async list_to_fstring(node, ctx)
- Parameters:
node (HTMLNode)
ctx (RecursionContext)
- Return type:
T
- async node_to_fstring(node, ctx)
- Parameters:
node (HTMLNode)
ctx (RecursionContext)
- Return type:
T
- async node_to_fstrings(node, ctx)
- Parameters:
node (HTMLNode)
ctx (RecursionContext)
- Return type:
list[T]
- async node_to_tagged_fstrings(node, ctx)
- Parameters:
node (HTMLNode)
ctx (RecursionContext)
- Return type:
- async parse_node(node, ctx)
- Parameters:
node (HTMLNode)
ctx (RecursionContext)
- Return type:
T
- async room_id_link_to_fstring(msg, room_id)
- Parameters:
msg (T)
room_id (RoomID)
- Return type:
T | None
- async room_pill_to_fstring(msg, room_alias)
- Parameters:
msg (T)
room_alias (RoomAlias)
- Return type:
T | None
- async tag_aware_parse_node(node, ctx)
- Parameters:
node (HTMLNode)
ctx (RecursionContext)
- Return type:
T
- async text_to_fstring(text, ctx, strip_leading_whitespace=False)
- Parameters:
text (str)
ctx (RecursionContext)
strip_leading_whitespace (bool)
- Return type:
T