From 9d3e0b258b2cae650657455966d9494907d5337d Mon Sep 17 00:00:00 2001
From: Nayor <11463011+Nayor@users.noreply.github.com>
Date: Wed, 11 Nov 2026 18:42:02 +0100
Subject: [PATCH] fix: render the icons legend as a Markdown table so BBCode
markers are interpreted
---
campbot/checkers.py | 36 ++++++++++++++++++++++++++----------
tests/test_legend.py | 32 ++++++++++++++++++++++++++++++++
2 files changed, 58 insertions(+), 10 deletions(-)
create mode 100644 tests/test_legend.py
diff --git a/campbot/checkers.py b/campbot/checkers.py
index 0852b42..bcbb0cd 100644
--- a/campbot/checkers.py
+++ b/campbot/checkers.py
@@ -198,6 +198,30 @@ def get_report(self, bot, lang, with_date=False):
return "\n".join(result)
+def build_legend(tests):
+ """
+ Legend of the markers, as a Markdown table: BBCode ([color=red]) and Markdown
+ are not interpreted inside HTML blocks (
), only in Markdown tables.
+ """
+
+ def cell(text):
+ return str(text).replace("|", "|").replace("\n", " ") or " "
+
+ lines = [
+ "[details=Signification des icônes]\n",
+ "| Test | A relire | Corrigé |",
+ "|---|---|---|",
+ ]
+ for test in tests:
+ lines.append(
+ "| {} | {} | {} |".format(
+ cell(test.name), cell(test.fail_marker), cell(test.success_marker)
+ )
+ )
+ lines.append("\n[/details]")
+ return "\n".join(lines)
+
+
def report_recent_changes(bot, days, lang, thread_url):
newest_date = utils.today().replace(hour=0, minute=0, second=0, microsecond=0)
@@ -223,18 +247,10 @@ def report_recent_changes(bot, days, lang, thread_url):
if len(reports) != 0:
messages = [
"[Explications]({})\n".format(thread_url),
- "[details=Signification des icônes]\n",
- "| Test | A relire | Corrigé |
",
+ build_legend(tests),
+ "\n----\n",
]
- for test in tests:
- messages.append("")
- messages.append("| {} | ".format(test.name))
- messages.append("{} | ".format(test.fail_marker))
- messages.append("{} | ".format(test.success_marker))
- messages.append("
")
-
- messages.append("
\n[/details]\n\n----\n\n")
messages += [report.get_report(bot, lang, days > 1) for report in reports]
logging.info(f"Reporting {len(reports)} reports:\n\n" + "\n".join(messages))
diff --git a/tests/test_legend.py b/tests/test_legend.py
new file mode 100644
index 0000000..0d4e4dd
--- /dev/null
+++ b/tests/test_legend.py
@@ -0,0 +1,32 @@
+from types import SimpleNamespace
+
+from campbot.checkers import build_legend
+
+
+def _test(name, fail, success):
+ return SimpleNamespace(name=name, fail_marker=fail, success_marker=success)
+
+
+def test_legend_is_a_markdown_table_without_html():
+ legend = build_legend(
+ [
+ _test("Termes suspects", "[color=red]**?**[/color]", "."),
+ _test(
+ "Diverses erreurs",
+ "[color=red]**X**[/color]",
+ "[color=green]**X**[/color]",
+ ),
+ ]
+ )
+
+ # BBCode is not interpreted inside HTML blocks, so no HTML table
+ assert "" not in legend and "| " not in legend
+ assert legend.startswith("[details=Signification des icônes]\n\n| Test |")
+ assert "|---|---|---|" in legend
+ assert "| Termes suspects | [color=red]**?**[/color] | . |" in legend
+ assert legend.endswith("[/details]")
+
+
+def test_legend_cells_cannot_break_the_table():
+ legend = build_legend([_test("a|b", "", "x\ny")])
+ assert "| a|b | | x y |" in legend
|