@@ -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
1819
1920import feedparser
21+ from markdownify import markdownify
2022from typing_extensions import override
2123
2224import zulip
@@ -106,6 +108,18 @@ parser.add_argument(
106108 help = "The earliest date (relative to today) you want to process entries from (in days)" ,
107109 default = 30 ,
108110 action = "store" ,
111+ body = parser .add_mutually_exclusive_group ()
112+ body .add_argument (
113+ "--strip" ,
114+ dest = "strip" ,
115+ action = "store_true" ,
116+ help = "Strip HTML tags from body" ,
117+ )
118+ body .add_argument (
119+ "--markdownify" ,
120+ dest = "strip" ,
121+ action = "store_false" ,
122+ help = "Convert body from HTML to Markdown" ,
109123)
110124
111125opts = parser .parse_args ()
@@ -198,7 +212,12 @@ def send_zulip(entry: Any, feed_name: str) -> Dict[str, Any]:
198212 body = unwrap_text (body )
199213
200214 title = f"**[{ entry .title } ]({ entry .link } )**\n " if hasattr (entry , "title" ) else ""
201- content = f"{ title } { strip_tags (body )} \n { entry .link } "
215+
216+ def md (html : str ) -> str :
217+ return markdownify (html , escape_underscores = False )
218+
219+ convert : Callable [[str ], str ] = strip_tags if opts .strip else md
220+ content = f"{ title } { convert (body )} \n { entry .link } "
202221
203222 if opts .math :
204223 content = content .replace ("$" , "$$" )
0 commit comments