From c89c59e7fc098ffcd1db83264a2d5a0d2e899227 Mon Sep 17 00:00:00 2001 From: Andrew Ferrazzutti Date: Sun, 6 Jun 2021 18:18:57 -0400 Subject: [PATCH] Handle incoming line breaks --- matrix_puppeteer_line/portal.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/matrix_puppeteer_line/portal.py b/matrix_puppeteer_line/portal.py index b577dee..b46f0c7 100644 --- a/matrix_puppeteer_line/portal.py +++ b/matrix_puppeteer_line/portal.py @@ -269,12 +269,11 @@ class Portal(DBPortal, BasePortal): chunks.append({"type": "data", "data": data}) def handle_starttag(tag, attrs): - if tag == "img": - obj = {"type": tag} - for attr in attrs: - obj[attr[0]] = attr[1] - nonlocal chunks - chunks.append(obj) + obj = {"type": tag} + for attr in attrs: + obj[attr[0]] = attr[1] + nonlocal chunks + chunks.append(obj) parser = HTMLParser() parser.handle_data = handle_data @@ -286,7 +285,12 @@ class Portal(DBPortal, BasePortal): for chunk in chunks: ctype = chunk["type"] - if ctype == "data": + if ctype == "br": + msg_text += "\n" + if not msg_html: + msg_html = msg_text + msg_html += "
" + elif ctype == "data": msg_text += chunk["data"] if msg_html: msg_html += chunk["data"]