Skip to content

Commit

Permalink
Add support for colors in MatrixParser
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Nov 25, 2021
1 parent b4f9dac commit 9e9c293
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions mautrix/util/formatter/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ def room_pill_to_fstring(cls, msg: T, room_alias: RoomAlias) -> Optional[T]:
def custom_node_to_fstring(cls, node: HTMLNode, ctx: RecursionContext) -> Optional[T]:
return None

@classmethod
def color_to_fstring(cls, node: HTMLNode, ctx: RecursionContext, color: str) -> T:
return cls.tag_aware_parse_node(node, ctx)

@classmethod
def node_to_fstring(cls, node: HTMLNode, ctx: RecursionContext) -> T:
custom = cls.custom_node_to_fstring(node, ctx)
Expand All @@ -181,6 +185,16 @@ def node_to_fstring(cls, node: HTMLNode, ctx: RecursionContext) -> T:
return cls.link_to_fstring(node, ctx)
elif node.tag == "p":
return cls.tag_aware_parse_node(node, ctx).append("\n")
elif node.tag in ("font", "span"):
try:
color = node.attrib["color"]
except KeyError:
try:
color = node.attrib["data-mx-color"]
except KeyError:
color = None
if color:
return cls.color_to_fstring(node, ctx, color)
elif node.tag == "pre":
lang = ""
try:
Expand Down

0 comments on commit 9e9c293

Please sign in to comment.