@@ -13,10 +13,12 @@ import re
13
13
import sys
14
14
import time
15
15
import urllib .parse
16
+ from collections .abc import Callable
16
17
from html .parser import HTMLParser
17
18
from typing import Any , Dict , List , Optional , Tuple
18
19
19
20
import feedparser
21
+ from markdownify import markdownify
20
22
from typing_extensions import override
21
23
22
24
import zulip
@@ -92,6 +94,19 @@ parser.add_argument(
92
94
help = "Convert $ to $$ (for KaTeX processing)" ,
93
95
default = False ,
94
96
)
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
+ )
95
110
96
111
opts = parser .parse_args ()
97
112
@@ -177,7 +192,11 @@ def send_zulip(entry: Any, feed_name: str) -> Dict[str, Any]:
177
192
if opts .unwrap :
178
193
body = unwrap_text (body )
179
194
180
- content = f"**[{ entry .title } ]({ entry .link } )**\n { strip_tags (body )} \n { entry .link } "
195
+ def md (html : str ) -> str :
196
+ return markdownify (html , escape_underscores = False )
197
+
198
+ convert : Callable [[str ], str ] = strip_tags if opts .strip else md
199
+ content = f"**[{ entry .title } ]({ entry .link } )**\n { convert (body )} \n { entry .link } "
181
200
182
201
if opts .math :
183
202
content = content .replace ("$" , "$$" )
0 commit comments