Skip to content

Commit ebebc19

Browse files
committed
rss-bot: Add option to convert body to Markdown
1 parent a2ddac7 commit ebebc19

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ module = [
6464
"gitlint.*",
6565
"googleapiclient.*",
6666
"irc.*",
67+
"markdownify.*",
6768
"mercurial.*",
6869
"nio.*",
6970
"oauth2client.*",
+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
feedparser>=6.0.10
2+
markdownify>=0.11.6

zulip/integrations/rss/rss-bot

+17-1
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ import re
1313
import sys
1414
import time
1515
import urllib.parse
16+
from functools import partial
1617
from html.parser import HTMLParser
1718
from typing import Any, Dict, List, Optional, Tuple
1819

1920
import feedparser
21+
from markdownify import markdownify
2022
from typing_extensions import override
2123

2224
import zulip
@@ -92,6 +94,19 @@ parser.add_argument(
9294
help="Convert $ to $$ (for KaTeX processing)",
9395
default=False,
9496
)
97+
body = parser.add_mutually_exclusive_group()
98+
body.add_argument(
99+
"--strip",
100+
dest="strip",
101+
action="store_true",
102+
help="Strip HTML tags from body",
103+
)
104+
body.add_argument(
105+
"--markdownify",
106+
dest="strip",
107+
action="store_false",
108+
help="Convert body from HTML to Markdown",
109+
)
95110

96111
opts = parser.parse_args()
97112

@@ -177,7 +192,8 @@ def send_zulip(entry: Any, feed_name: str) -> Dict[str, Any]:
177192
if opts.unwrap:
178193
body = unwrap_text(body)
179194

180-
content = f"**[{entry.title}]({entry.link})**\n{strip_tags(body)}\n{entry.link}"
195+
convert = strip_tags if opts.strip else partial(markdownify, escape_underscores=False)
196+
content = f"**[{entry.title}]({entry.link})**\n{convert(body)}\n{entry.link}"
181197

182198
if opts.math:
183199
content = content.replace("$", "$$")

0 commit comments

Comments
 (0)