From 36591e30ccd4fafe324e17c29ba47b99cb635877 Mon Sep 17 00:00:00 2001 From: i-ky Date: Wed, 8 Nov 2023 15:09:46 +0000 Subject: [PATCH] rss-bot: Add option to convert body to Markdown --- zulip/integrations/rss/requirements.txt | 1 + zulip/integrations/rss/rss-bot | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/zulip/integrations/rss/requirements.txt b/zulip/integrations/rss/requirements.txt index 7bbec3415..96e1b4d72 100644 --- a/zulip/integrations/rss/requirements.txt +++ b/zulip/integrations/rss/requirements.txt @@ -1 +1,2 @@ feedparser>=6.0.10 +markdownify>=0.11.6 diff --git a/zulip/integrations/rss/rss-bot b/zulip/integrations/rss/rss-bot index f49342687..016ba2979 100755 --- a/zulip/integrations/rss/rss-bot +++ b/zulip/integrations/rss/rss-bot @@ -17,6 +17,7 @@ from html.parser import HTMLParser from typing import Any, Dict, List, Optional, Tuple import feedparser +from markdownify import markdownify from typing_extensions import override import zulip @@ -92,6 +93,19 @@ parser.add_argument( help="Convert $ to $$ (for KaTeX processing)", default=False, ) +body = parser.add_mutually_exclusive_group() +body.add_argument( + "--strip", + dest="strip", + action="store_true", + help="Strip HTML tags from body", +) +body.add_argument( + "--markdownify", + dest="strip", + action="store_false", + help="Convert body from HTML to Markdown", +) opts = parser.parse_args() @@ -177,7 +191,8 @@ def send_zulip(entry: Any, feed_name: str) -> Dict[str, Any]: if opts.unwrap: body = unwrap_text(body) - content = f"**[{entry.title}]({entry.link})**\n{strip_tags(body)}\n{entry.link}" + convert = strip_tags if opts.strip else markdownify + content = f"**[{entry.title}]({entry.link})**\n{convert(body)}\n{entry.link}" if opts.math: content = content.replace("$", "$$")