Fix block tag newlines and allow <strike>. Fixes #232

This commit is contained in:
Tulir Asokan
2018-09-28 17:06:42 +03:00
parent a32bc2985a
commit 916cc3746d
@@ -101,7 +101,7 @@ class MatrixParser(MatrixParserCommon):
children = cls.node_to_tmessages(node, ctx) children = cls.node_to_tmessages(node, ctx)
length = int(node.tag[1]) length = int(node.tag[1])
prefix = "#" * length + " " prefix = "#" * length + " "
return TelegramMessage.join(children, "").prepend(prefix) return TelegramMessage.join(children, "").prepend(prefix).format(Bold)
@classmethod @classmethod
def basic_format_to_tmessage(cls, node: html.HtmlElement, ctx: RecursionContext def basic_format_to_tmessage(cls, node: html.HtmlElement, ctx: RecursionContext
@@ -113,12 +113,12 @@ class MatrixParser(MatrixParserCommon):
msg.format(Italic) msg.format(Italic)
elif node.tag == "command": elif node.tag == "command":
msg.format(Command) msg.format(Command)
elif node.tag in ("s", "del"): elif node.tag in ("s", "strike", "del"):
msg.text = html_to_unicode(msg.text, "\u0336") msg.text = html_to_unicode(msg.text, "\u0336")
elif node.tag in ("u", "ins"): elif node.tag in ("u", "ins"):
msg.text = html_to_unicode(msg.text, "\u0332") msg.text = html_to_unicode(msg.text, "\u0332")
if node.tag in ("s", "del", "u", "ins"): if node.tag in ("s", "strike", "del", "u", "ins"):
msg.entities = Entity.adjust(msg.entities, offset_length_multiply(2)) msg.entities = Entity.adjust(msg.entities, offset_length_multiply(2))
return msg return msg
@@ -218,9 +218,13 @@ class MatrixParser(MatrixParserCommon):
) -> TelegramMessage: ) -> TelegramMessage:
msgs = cls.node_to_tagged_tmessages(node, ctx) msgs = cls.node_to_tagged_tmessages(node, ctx)
output = TelegramMessage() output = TelegramMessage()
prev_was_block = False
for msg, tag in msgs: for msg, tag in msgs:
if tag in cls.block_tags: if tag in cls.block_tags:
msg = msg.append("\n").prepend("\n") msg = msg.append("\n")
if not prev_was_block:
msg = msg.prepend("\n")
prev_was_block = True
output = output.append(msg) output = output.append(msg)
return output.trim() return output.trim()