fix(mail-templates): read \n as a line break in one-line inputs (1.0.2)

The playbook editor's input field is a single <input>, which drops the
newlines of a pasted text: the whole description reached the script as
one line starting with ## and rendered as a single heading. description
and callout_text without a real line break now take the two characters
\n as one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BJu1jvaug4qY1kMgz8wx41
This commit is contained in:
2026-10-19 09:10:52 +00:00
parent 046810c1f6
commit 983414f278
2 changed files with 15 additions and 5 deletions
@@ -405,6 +405,16 @@ def _when(raw, lang):
return "%d %s %d, %s UTC" % (d.day, STRINGS["en"]["months"][d.month - 1], d.year, d.strftime("%H:%M"))
def _lines(v):
"""The markdown with its line breaks. The playbook editor's input field is a
single line and drops pasted newlines, so a text without one may spell them
as the two characters \\n instead."""
v = str(v or "").strip()
if "\n" not in v and "\\n" in v:
v = v.replace("\\r\\n", "\n").replace("\\n", "\n")
return v
def _choice(inputs, key, allowed, default):
v = _s(inputs.get(key)).lower() or default
if v not in allowed:
@@ -417,7 +427,7 @@ def render(cfg, inputs):
lang = _choice(inputs, "lang", ["fr", "en"], "fr")
audience = _choice(inputs, "audience", ["soc", "client"], "soc")
subject = _s(inputs.get("subject"))
description = str(inputs.get("description") or "").strip()
description = _lines(inputs.get("description"))
if not subject:
raise Exception("subject is required")
if not description:
@@ -435,7 +445,7 @@ def render(cfg, inputs):
raise Exception("button_url must start with http:// or https://")
if button_label and not button_url:
raise Exception("button_url is required with button_label")
callout_text = str(inputs.get("callout_text") or "").strip()
callout_text = _lines(inputs.get("callout_text"))
bot = _s(cfg.get("bot_name")) or "Riposte"
t = TEMPLATES[template]