from __future__ import annotations import re HELPSCOUT_EMAIL_TEMPLATE = """\
{greeting}
" if greeting else "" signature_html = f"{signature}
" if signature else "" return HELPSCOUT_EMAIL_TEMPLATE.format( greeting=greeting_html, body=body_html, signature=signature_html, ) def wrap_ai_note(content: str) -> str: escaped = content.replace("&", "&").replace("<", "<").replace(">", ">") return HELPSCOUT_NOTE_TEMPLATE.format(content=escaped) def text_to_html_body(text: str) -> str: result = text result = re.sub(r"\*\*(.+?)\*\*", r"\1", result) result = re.sub(r"\*(.+?)\*", r"\1", result) result = re.sub(r"\[([^\]]+)\]\(([^\)]+)\)", r'\1', result) lines = result.split("\n") paragraphs = [] current = "" for line in lines: line = line.strip() if not line: if current: paragraphs.append(f"{current}
") current = "" continue if line.startswith("- ") or line.startswith("* "): if current: paragraphs.append(f"{current}
") current = "" item = line[2:] paragraphs.append(f"{current}
") return "\n".join(paragraphs)