@@ -13,10 +13,12 @@ import re
1313import sys
1414import time
1515import urllib .parse
16+ from collections .abc import Callable
1617from html .parser import HTMLParser
1718from typing import Any , Dict , List , Optional , Tuple
1819
1920import feedparser
21+ from markdownify import markdownify
2022from typing_extensions import override
2123
2224import 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
96111opts = parser .parse_args ()
97112
@@ -177,7 +192,11 @@ 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+ 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 } "
181200
182201 if opts .math :
183202 content = content .replace ("$" , "$$" )
0 commit comments