From 89658132a08d20423431843c418bd9042d45b29a Mon Sep 17 00:00:00 2001 From: hkc Date: Fri, 13 Jan 2023 11:47:40 +0300 Subject: [PATCH] We all need some space and we hate to --- mastoposter/utils.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/mastoposter/utils.py b/mastoposter/utils.py index 9b2da47..9a2ad0e 100644 --- a/mastoposter/utils.py +++ b/mastoposter/utils.py @@ -75,27 +75,30 @@ def node_to_html(el: PageElement) -> str: ), ), "br": lambda _: "\n", + # NOTE may fail on nested lists "ul": lambda tag: ( - "%s\n" - % str.join( + "\n" + + str.join( "\n", ( " \u2022 " - + node_to_html(li).replace("\n", "\n ").strip() + + node_to_html(li).replace("\n", "\n ").rstrip() for li in tag.children ), ) + + "\n" ), "ol": lambda tag: ( - "%s\n" - % str.join( + "\n" + + str.join( "\n", ( "%d. %s" - % (i, node_to_html(li).replace("\n", "\n ").strip()) + % (i, node_to_html(li).replace("\n", "\n ").rstrip()) for i, li in enumerate(tag.children, 1) ), ) + + "\n" ), } @@ -157,24 +160,25 @@ def node_to_markdown(el: PageElement) -> str: ) ), "br": lambda _: "\n", + # NOTE may fail on nested lists "ul": lambda tag: ( - "\n``%s``\n" + "\n%s\n" % str.join( "\n", ( " \u2022 " - + node_to_markdown(li).replace("\n", "\n ").strip() + + node_to_markdown(li).replace("\n", "\n ").rstrip() for li in tag.children ), ) ), "ol": lambda tag: ( - "\n``%s``\n" + "\n%s\n" % str.join( "\n", ( "%d. %s" - % (i, node_to_markdown(li).replace("\n", "\n ").strip()) + % (i, node_to_markdown(li).replace("\n", "\n ").rstrip()) for i, li in enumerate(tag.children, 1) ), ) @@ -212,7 +216,7 @@ def node_to_plaintext(el: PageElement) -> str: return "\n" elif el.name in ("ol", "ul"): children = map(node_to_plaintext, el.children) - return str.join( + return "\n%s\n" % str.join( "\n", ( " \u2022 %s" % li.replace("\n", "\n ").strip()