fix(markup): add heading support to _md_to_html (h1/h2/h3)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
4
bot.py
4
bot.py
@@ -1497,6 +1497,10 @@ class Bot:
|
|||||||
safe = re.sub(r"\[([^\]]+)\]\(([^)]+)\)", _link_repl, safe)
|
safe = re.sub(r"\[([^\]]+)\]\(([^)]+)\)", _link_repl, safe)
|
||||||
# Bare URLs (not already in an <a> tag)
|
# Bare URLs (not already in an <a> tag)
|
||||||
safe = re.sub(r'(?<!href=")(?<!">)(https?://[^\s<]+)', r'<a href="\1">\1</a>', safe)
|
safe = re.sub(r'(?<!href=")(?<!">)(https?://[^\s<]+)', r'<a href="\1">\1</a>', safe)
|
||||||
|
# Headings (### before ## before # to match longest first)
|
||||||
|
safe = re.sub(r"^### (.+)$", r"<h3>\1</h3>", safe, flags=re.MULTILINE)
|
||||||
|
safe = re.sub(r"^## (.+)$", r"<h2>\1</h2>", safe, flags=re.MULTILINE)
|
||||||
|
safe = re.sub(r"^# (.+)$", r"<h1>\1</h1>", safe, flags=re.MULTILINE)
|
||||||
# Line breaks
|
# Line breaks
|
||||||
safe = safe.replace("\n", "<br/>")
|
safe = safe.replace("\n", "<br/>")
|
||||||
return safe
|
return safe
|
||||||
|
|||||||
Reference in New Issue
Block a user