/
githubmirror
/
zulip
Обзор
Документация
Войти
/
githubmirror
/
zulip
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
zerver/lib/markdown/from_html.py
18 строк
723 B
Dhruv Shetty
markdown: Move convert_html_to_markdown to a new library file.
19 апр 2026, 05:07
19 апр 2026, 05:07
9e5d927
Код
Авторство
О чём код?
import os import re import subprocess import sys def convert_html_to_markdown(html: str) -> str: # html2text is GPL licensed, so run it as a subprocess. markdown = subprocess.check_output( [os.path.join(sys.prefix, "bin", "html2text"), "--unicode-snob"], input=html, text=True ).strip() # We want images to get linked and inline previewed, but html2text will turn # them into links of the form ``, which is # ugly. Run a regex over the resulting description, turning links of the # form `` into # `[image.png](http://foo.com/image.png)`. return re.sub(r"!\[\]\((\S*)/(\S*)\?(\S*)\)", "[\\2](\\1/\\2)", markdown)