Convert markdown text to HTML. Falls through to escaped text on error.
(text: str)
| 5 | |
| 6 | |
| 7 | def render_markdown(text: str) -> str: |
| 8 | """Convert markdown text to HTML. Falls through to escaped text on error.""" |
| 9 | try: |
| 10 | # Escape bare <word> placeholders (e.g. <newbase>, <file>) so the |
| 11 | # markdown library doesn't swallow them as HTML tags. |
| 12 | text = re.sub(r"<([^>]+)>", r"<\1>", text) |
| 13 | return cmarkgfm.markdown_to_html(text) |
| 14 | except Exception: |
| 15 | return markupsafe.escape(text) |
no outgoing calls