fix(MAT-64): Convert --- to proper <hr/> in markdown-to-HTML

The _md_to_html method was missing horizontal rule conversion, so ---
rendered as literal dashes. Now converts to <hr/> and strips adjacent
<br/> tags for clean spacing.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Christian Gick
2026-02-28 13:54:24 +02:00
parent 7915d11463
commit 18607e39b5

5
bot.py
View File

@@ -97,7 +97,7 @@ IMPORTANT RULES — FOLLOW THESE STRICTLY:
- You can generate images when asked — use the generate_image tool for any image creation, drawing, or illustration requests. - You can generate images when asked — use the generate_image tool for any image creation, drawing, or illustration requests.
- You can search the web using the web_search tool. Use it when users ask about current events, facts, or anything that needs up-to-date information. - You can search the web using the web_search tool. Use it when users ask about current events, facts, or anything that needs up-to-date information.
- When you use web_search, embed source links INLINE in the text where the information appears, e.g. "Laut [Cyprus Mail](url) hat..." or "([Quelle](url))". Do NOT collect links in a separate section at the bottom. Every claim from a search result must have its source linked right there in the sentence. - When you use web_search, embed source links INLINE in the text where the information appears, e.g. "Laut [Cyprus Mail](url) hat..." or "([Quelle](url))". Do NOT collect links in a separate section at the bottom. Every claim from a search result must have its source linked right there in the sentence.
- Keep formatting compact. STRICT rules: NEVER use headings (no #, ##, ###). Use **bold text** for section titles instead. NEVER use horizontal rules (---). NEVER add blank lines between list items. Put section title and its content on consecutive lines with no blank line in between. Maximum one blank line between sections. - Keep formatting compact. STRICT rules: NEVER use headings (no #, ##, ###). Use **bold text** for section titles instead. Use --- sparingly to separate major sections. NEVER add blank lines between list items or between a section title and its content. Maximum one blank line between sections.
- You can search Confluence and Jira using tools. When users ask about documentation, wiki pages, tickets, or tasks, use the appropriate tool. Use confluence_recent_pages FIRST to show recently edited pages before searching. - You can search Confluence and Jira using tools. When users ask about documentation, wiki pages, tickets, or tasks, use the appropriate tool. Use confluence_recent_pages FIRST to show recently edited pages before searching.
- When creating Jira issues, always confirm the project key and summary with the user before creating. - When creating Jira issues, always confirm the project key and summary with the user before creating.
- If a user's Atlassian account is not connected, tell them to connect it at matrixhost.eu/settings and provide the link. - If a user's Atlassian account is not connected, tell them to connect it at matrixhost.eu/settings and provide the link.
@@ -2261,11 +2261,14 @@ class Bot:
safe = re.sub(r"^### (.+)$", r"<h3>\1</h3>", safe, flags=re.MULTILINE) 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"<h2>\1</h2>", safe, flags=re.MULTILINE)
safe = re.sub(r"^# (.+)$", r"<h1>\1</h1>", safe, flags=re.MULTILINE) safe = re.sub(r"^# (.+)$", r"<h1>\1</h1>", safe, flags=re.MULTILINE)
# Horizontal rules (--- on its own line)
safe = re.sub(r"^-{3,}$", r"<hr/>", safe, flags=re.MULTILINE)
# Line breaks # Line breaks
safe = safe.replace("\n", "<br/>") safe = safe.replace("\n", "<br/>")
# Remove redundant <br/> after block elements # Remove redundant <br/> after block elements
safe = re.sub(r"(</h[1-6]>)(<br/>)+", r"\1", safe) safe = re.sub(r"(</h[1-6]>)(<br/>)+", r"\1", safe)
safe = re.sub(r"(</pre>)(<br/>)+", r"\1", safe) safe = re.sub(r"(</pre>)(<br/>)+", r"\1", safe)
safe = re.sub(r"(<br/>)*(<hr/>)(<br/>)*", r"\2", safe)
return safe return safe
async def _generate_and_send_image(self, room_id: str, prompt: str): async def _generate_and_send_image(self, room_id: str, prompt: str):