From 3753c6a3423b13c74cf7983627affcf968983211 Mon Sep 17 00:00:00 2001 From: hkc Date: Fri, 13 Jan 2023 10:47:23 +0300 Subject: [PATCH] Forgot about plaintext --- mastoposter/utils.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/mastoposter/utils.py b/mastoposter/utils.py index 115e364..9b2da47 100644 --- a/mastoposter/utils.py +++ b/mastoposter/utils.py @@ -210,5 +210,19 @@ def node_to_plaintext(el: PageElement) -> str: return str.join("", map(node_to_plaintext, el.children)) + "\n\n" elif el.name == "br": return "\n" + elif el.name in ("ol", "ul"): + children = map(node_to_plaintext, el.children) + return str.join( + "\n", + ( + " \u2022 %s" % li.replace("\n", "\n ").strip() + for li in children + ) + if el.name == "ol" + else ( + "%d. %s" % (i, li.replace("\n", "\n ").strip()) + for i, li in enumerate(children) + ), + ) return str.join("", map(node_to_plaintext, el.children)) return str(el)