Support more cases in “get_mastodon_text.py”
- ID
2b65a4c- date
2023-12-10 10:39:46+00:00- author
Alex Chan <alex@alexwlchan.net>- parent
16dea51- message
Support more cases in "get_mastodon_text.py"- changed files
2 files, 13 additions, 2 deletions
Changed files
textexpander/get_mastodon_text.py (2171) → textexpander/get_mastodon_text.py (2535)
diff --git a/textexpander/get_mastodon_text.py b/textexpander/get_mastodon_text.py
index be8e69d..1255fff 100755
--- a/textexpander/get_mastodon_text.py
+++ b/textexpander/get_mastodon_text.py
@@ -40,12 +40,18 @@ def download(url):
def normalise_text(text: str) -> str:
+ text = text.replace("</p><p>", "\n\n")
text = text.replace("<p>", "").replace("</p>", "")
text = re.sub(
r'<a href="[^"]+" class="mention hashtag" rel="tag">#<span>(?P<hashtag>[^<]+)</span></a>',
r"\\#\g<hashtag>",
text,
)
+ text = re.sub(
+ r'<a href="(?P<url>[^"]+)" rel="nofollow noopener noreferrer" translate="no" target="_blank"><span class="invisible">[^<]+</span><span class="ellipsis">[^<]+</span><span class="invisible">[^<]+</span></a>',
+ r"\g<url>",
+ text,
+ )
return text
@@ -75,7 +81,8 @@ if __name__ == "__main__":
print(f'[{author}]({post_url}) ({created_at.strftime("%-d %B %Y")}):')
print("")
- print("> " + normalise_text(post_data["content"]))
+ for line in normalise_text(post_data["content"]).splitlines():
+ print(f"> {line}".strip())
if post_data["media_attachments"]:
print(">\n> ", end="")
textexpander/test_get_mastodon_text.py (576) → textexpander/test_get_mastodon_text.py (1039)
diff --git a/textexpander/test_get_mastodon_text.py b/textexpander/test_get_mastodon_text.py
index 2400611..7985bee 100644
--- a/textexpander/test_get_mastodon_text.py
+++ b/textexpander/test_get_mastodon_text.py
@@ -12,7 +12,11 @@ from get_mastodon_text import normalise_text
'hashtag" rel="tag">#<span>ArtAdventCalendar</span></a> '
"contribution</p>",
"A variation on the previous system for todays \\#ArtAdventCalendar contribution",
- )
+ ),
+ (
+ '<p>my rules for git rebase</p><p>permalink: <a href="https://wizardzines.com/comics/rules-for-rebasing/" rel="nofollow noopener noreferrer" translate="no" target="_blank"><span class="invisible">https://</span><span class="ellipsis">wizardzines.com/comics/rules-f</span><span class="invisible">or-rebasing/</span></a></p>',
+ "my rules for git rebase\n\npermalink: https://wizardzines.com/comics/rules-for-rebasing/",
+ ),
],
)
def test_normalise_text(input, output):