to use as its text, with brackets stripped.
return re.sub(r"\[|\]", "", label)
return get_markdown_link_for_url(label, url)
def convert_title(self, el: Tag, text: str, parent_tags: set[str]) -> str:
return ""
def convert_html_to_markdown(
html: str, *, converter_class: type[ZulipMarkdownConverter] = ZulipMarkdownConverter
) -> str:
# A bare URL is expected input here (the text/html part of an incoming
# email), but BeautifulSoup warns about it ("looks like a URL, not markup").
# Suppress the warning so that expected input doesn't spam our logs.
with warnings.catch_warnings():
warnings.simplefilter("ignore", MarkupResemblesLocatorWarning)
converter = converter_class(
# Zulip's Markdown supports only ATX headings, not Setext headings.
heading_style="ATX",
# Zulip's Markdown has no backslash escaping; it renders "\" as a
# literal character.
escape_asterisks=False,
escape_underscores=False,
# HTML treats a newline as insignificant whitespace, but Zulip
# renders it as a line break. Collapse source newlines to spaces.
#
, , and block-level elements still produce line breaks.
wrap=True,
# An effectively infinite width disables column wrapping. Don't
# use None, which also disables wrapping but skips the pass that
# strips indentation from lines following a
.
wrap_width=sys.maxsize,
)
markdown: str = converter.convert(html).strip()
return markdown