Skip to content

Commit

Permalink
rss-bot: Add option to convert body to Markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
i-ky committed Nov 8, 2023
1 parent a2ddac7 commit 367fe10
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions zulip/integrations/rss/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
feedparser>=6.0.10
markdownify>=0.11.6
17 changes: 16 additions & 1 deletion zulip/integrations/rss/rss-bot
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import calendar
import errno
import hashlib
import logging
from markdownify import markdownify
import os
import re
import sys
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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("$", "$$")
Expand Down

0 comments on commit 367fe10

Please sign in to comment.