diff --git a/AGENTS.md b/AGENTS.md
index a558a61..88cd67d 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -242,6 +242,11 @@ tests/ PHPUnit; PlenarioTestTrait erzeugt Testdaten, Fixtures
nur solange die Abstimmung offen ist. `participate:edit` → `VoteService::editText()`, gleiche Vorbedingungen wie
`submit()`, in der Folien-Sperre, legt nie eine neue Antwort an.
+- **Formatierung von Folientexten** (nur `description`, nie Eingaben von Teilnehmenden) im WhatsApp-Stil: `*fett*`,
+ `_kursiv_`, `~durchgestrichen~`, Aufzählung mit `- `/`* ` am Zeilenanfang, Zeilenumbrüche. Zwei gleiche Implementierungen:
+ `FormatHelper::text()` (PHP: Teilnehmerseite, PDF; escapt alles und erzeugt nur diese Tags) und `Format` in `plenario.js`
+ (Presenter/Embed; baut DOM-Knoten, kein `innerHTML`). Regeln in beiden gleich halten (Regex `INLINE`/`LIST_ITEM`),
+ Tests: `FormatHelperTest.php`.
- **PDF-Export** (`/admin/{token}/export.pdf`, `admin:export`, `ReportService` + `PdfView`, Dompdf): Ergebnisse aller
interaktiven Folien (Inhaltsfolien/YouTube fehlen). Standard ist die Fassung **ohne interne Inhalte**: private Folien
(`Slide::isPrivate()`) erscheinen nur mit Teilnehmerzahl. `?internal=1` = vollständige Fassung inkl.
diff --git a/src/View/AppView.php b/src/View/AppView.php
index 1bfd5dc..9e94463 100644
--- a/src/View/AppView.php
+++ b/src/View/AppView.php
@@ -37,5 +37,6 @@ class AppView extends View
*/
public function initialize(): void
{
+ $this->addHelper('Format');
}
}
diff --git a/src/View/Helper/FormatHelper.php b/src/View/Helper/FormatHelper.php
new file mode 100644
index 0000000..e0f24a4
--- /dev/null
+++ b/src/View/Helper/FormatHelper.php
@@ -0,0 +1,86 @@
+
+ */
+ protected const TAGS = ['*' => 'strong', '_' => 'em', '~' => 's'];
+
+ /**
+ * Formats a text as HTML: lines become
, consecutive list lines a
.
+ *
+ * @param string|null $text Text as entered
+ * @return string Safe HTML
+ */
+ public function text(?string $text): string
+ {
+ $lines = preg_split('/\R/u', trim((string)$text)) ?: [];
+ $html = '';
+ $paragraph = [];
+ $items = [];
+ $flushText = function () use (&$html, &$paragraph): void {
+ if ($paragraph) {
+ $html .= implode('
', array_map($this->inline(...), $paragraph));
+ $paragraph = [];
+ }
+ };
+ $flushList = function () use (&$html, &$items): void {
+ if ($items) {
+ $html .= '' . implode('', array_map(fn($item) => '- ' . $this->inline($item) . '
', $items)) . '
';
+ $items = [];
+ }
+ };
+ foreach ($lines as $line) {
+ if (preg_match(self::LIST_ITEM, $line, $match)) {
+ $flushText();
+ $items[] = $match[1];
+ } else {
+ $flushList();
+ $paragraph[] = $line;
+ }
+ }
+ $flushText();
+ $flushList();
+
+ return $html;
+ }
+
+ /**
+ * Inline markers of one line, nested by recursion (e.g. *_bold italic_*).
+ *
+ * @param string $text Line as entered
+ * @return string Safe HTML
+ */
+ public function inline(string $text): string
+ {
+ if (!preg_match(self::INLINE, $text, $match, PREG_OFFSET_CAPTURE)) {
+ return h($text);
+ }
+ $start = $match[0][1];
+ $tag = self::TAGS[$match[2][0]];
+
+ return h(substr($text, 0, $start)) . h($match[1][0])
+ . '<' . $tag . '>' . $this->inline($match[3][0]) . '' . $tag . '>'
+ . $this->inline(substr($text, $start + strlen($match[0][0])));
+ }
+}
diff --git a/templates/Admin/export.php b/templates/Admin/export.php
index 213ea9b..020e1a1 100644
--- a/templates/Admin/export.php
+++ b/templates/Admin/export.php
@@ -78,7 +78,7 @@ $bar = function (float $percent, bool $ok = false): string {
= h($slide->question) ?>
description) : ?>
- = nl2br(h($slide->description)) ?>
+ = $this->Format->text($slide->description) ?>
= __n('{0} Person hat teilgenommen', '{0} Personen haben teilgenommen', $participants, $participants) ?>
diff --git a/templates/Admin/present.php b/templates/Admin/present.php
index b4a85c5..dfc9a84 100644
--- a/templates/Admin/present.php
+++ b/templates/Admin/present.php
@@ -36,7 +36,7 @@ $host = preg_replace('#^https?://#', '', $joinBaseUrl);
= __('Lade …') ?>
-
+
diff --git a/templates/Embed/view.php b/templates/Embed/view.php
index b835756..e624f71 100644
--- a/templates/Embed/view.php
+++ b/templates/Embed/view.php
@@ -40,7 +40,7 @@ $host = preg_replace('#^https?://#', '', $joinBaseUrl);
= h($slide->question) ?>
-
+
diff --git a/templates/Participate/view.php b/templates/Participate/view.php
index 62da0d5..057bd7e 100644
--- a/templates/Participate/view.php
+++ b/templates/Participate/view.php
@@ -66,7 +66,7 @@ $countdown = function (?int $remaining): string {
= __('Video') ?>
= h($slide->question) ?>
description) : ?>
- = nl2br(h($slide->description)) ?>
+ = $this->Format->text($slide->description) ?>
@@ -87,7 +87,7 @@ $countdown = function (?int $remaining): string {
= h($slide->question) ?>
description) : ?>
- = nl2br(h($slide->description)) ?>
+ = $this->Format->text($slide->description) ?>
@@ -95,7 +95,7 @@ $countdown = function (?int $remaining): string {
= h($slide->question) ?>
description) : ?>
- = nl2br(h($slide->description)) ?>
+ = $this->Format->text($slide->description) ?>
diff --git a/templates/Slides/form.php b/templates/Slides/form.php
index 9d3bc6b..3927f82 100644
--- a/templates/Slides/form.php
+++ b/templates/Slides/form.php
@@ -111,7 +111,9 @@ $optionsError = $slide->getError('options_text');
'type' => 'textarea',
'rows' => $slide->type === 'content' ? 6 : 2,
'label' => $slide->type === 'content' ? __('Text') : __('Beschreibung (optional)'),
+ 'aria-describedby' => 'description-format',
]) ?>
+ = __('Formatierung wie bei WhatsApp: *fett*, _kursiv_, ~durchgestrichen~, Aufzählung mit „- “ am Zeilenanfang.') ?>
type === 'choice') : ?>
diff --git a/templates/layout/pdf.php b/templates/layout/pdf.php
index eef91cd..b24fd68 100644
--- a/templates/layout/pdf.php
+++ b/templates/layout/pdf.php
@@ -48,6 +48,9 @@
.stat { font-size: 12pt; font-weight: bold; }
td.stars { color: #c27c00; letter-spacing: 1pt; }
.empty { color: #5d6280; font-style: italic; }
+ /* slide texts with *bold*, _italic_, ~strike~ and lists (FormatHelper) */
+ .formatted { margin: 0 0 2mm; }
+ .formatted ul { margin: 1mm 0; padding-left: 6mm; }
diff --git a/tests/TestCase/View/Helper/FormatHelperTest.php b/tests/TestCase/View/Helper/FormatHelperTest.php
new file mode 100644
index 0000000..01c3d23
--- /dev/null
+++ b/tests/TestCase/View/Helper/FormatHelperTest.php
@@ -0,0 +1,59 @@
+Format = new FormatHelper(new View());
+ }
+
+ public function testInlineMarkers(): void
+ {
+ $this->assertSame('
fett', $this->Format->text('*fett*'));
+ $this->assertSame('ganz
kursiv hier', $this->Format->text('ganz _kursiv_ hier'));
+ $this->assertSame('
alt neu', $this->Format->text('~alt~ neu'));
+ $this->assertSame('
zwei Wörter, gut', $this->Format->text('*zwei Wörter*, gut'));
+ $this->assertSame('
beides', $this->Format->text('*_beides_*'));
+ $this->assertSame('
a und
b', $this->Format->text('*a* und *b*'));
+ }
+
+ public function testMarkersNeedWordBoundariesAndNoInnerSpaces(): void
+ {
+ $this->assertSame('2*3*4', $this->Format->text('2*3*4'));
+ $this->assertSame('snake_case_name', $this->Format->text('snake_case_name'));
+ $this->assertSame('so * nicht fett *', $this->Format->text('so * nicht fett *'));
+ $this->assertSame('5 * 3 = 15', $this->Format->text('5 * 3 = 15'));
+ $this->assertSame('*offen', $this->Format->text('*offen'));
+ }
+
+ public function testLinesAndLists(): void
+ {
+ $this->assertSame('eins
zwei', $this->Format->text("eins\r\nzwei"));
+ $this->assertSame(
+ 'Agenda:
Danke!',
+ $this->Format->text("Agenda:\n- Bericht\n* *Wahl*\nDanke!"),
+ );
+ }
+
+ public function testEverythingElseIsEscaped(): void
+ {
+ $this->assertSame(
+ '<script>x</script>
<b> &',
+ $this->Format->text(' *
* &'),
+ );
+ $this->assertSame('', $this->Format->text(null));
+ }
+}
diff --git a/webroot/css/plenario.css b/webroot/css/plenario.css
index 1377bdf..a109954 100644
--- a/webroot/css/plenario.css
+++ b/webroot/css/plenario.css
@@ -377,6 +377,11 @@ textarea { resize: vertical; }
.pulse { width: 18px; height: 18px; border-radius: 50%; background: var(--primary); margin: 0 auto 24px; animation: pulse 1.6s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(75, 63, 224, .5); } 100% { box-shadow: 0 0 0 24px rgba(75, 63, 224, 0); } }
.prose { font-size: 1.1rem; }
+/* slide texts with *bold*, _italic_, ~strike~ and lists (FormatHelper / Format in plenario.js) */
+.muted.formatted { margin: 1em 0; }
+.formatted ul { margin: .3em 0; padding-left: 1.3em; text-align: left; }
+.formatted li + li { margin-top: .15em; }
+.muted.formatted strong { color: var(--text); }
/* quiz (participant) */
.choice--quiz { border-left-width: 8px; border-left-color: var(--c0); font-size: 1.1rem; }
@@ -663,7 +668,7 @@ body.present {
.stage__status:empty { display: none; }
.stage--closed .stage__status { color: var(--muted); }
.stage__question { font-size: clamp(2rem, 4.5vw, 4rem); margin-bottom: .3em; }
-.stage__description { font-size: clamp(1.1rem, 2vw, 1.6rem); color: var(--muted); white-space: pre-line; margin-top: 0; }
+.stage__description { font-size: clamp(1.1rem, 2vw, 1.6rem); color: var(--muted); margin: 0 0 1em; }
.stage__media { width: min(100%, calc(62vh * 16 / 9)); margin: 1vh auto 0; }
.stage--video .stage__question { font-size: clamp(1.5rem, 3vw, 2.6rem); }
.stage--video .stage__description { font-size: clamp(1rem, 1.6vw, 1.3rem); }
diff --git a/webroot/js/plenario.js b/webroot/js/plenario.js
index f3eea85..97ad447 100644
--- a/webroot/js/plenario.js
+++ b/webroot/js/plenario.js
@@ -42,6 +42,52 @@
return node;
}
+ /**
+ * Light formatting of slide texts in WhatsApp style, same rules as App\View\Helper\FormatHelper:
+ * *bold*, _italic_, ~strikethrough~, lists with "- " or "* " at the start of a line.
+ * Builds DOM nodes (text via textContent), never HTML strings.
+ */
+ var Format = {
+ INLINE: /(^|[^\p{L}\p{N}])([*_~])(\S|\S[^\n]*?\S)\2(?=$|[^\p{L}\p{N}])/u,
+ LIST_ITEM: /^\s*[-*•]\s+(.*)$/u,
+ TAGS: { '*': 'strong', '_': 'em', '~': 's' },
+
+ render: function (container, text) {
+ container.textContent = '';
+ var lines = String(text || '').trim().split(/\r\n|\r|\n/);
+ var list = null;
+ var lineBefore = false;
+ lines.forEach(function (line) {
+ var item = Format.LIST_ITEM.exec(line);
+ if (item) {
+ if (!list) {
+ list = container.appendChild(el('ul'));
+ }
+ list.appendChild(el('li', {}, Format.inline(item[1])));
+ lineBefore = false;
+ return;
+ }
+ if (lineBefore) {
+ container.appendChild(el('br'));
+ }
+ list = null;
+ Format.inline(line).forEach(function (node) { container.appendChild(node); });
+ lineBefore = true;
+ });
+ },
+
+ inline: function (text) {
+ var m = Format.INLINE.exec(text);
+ if (!m) {
+ return text ? [document.createTextNode(text)] : [];
+ }
+ var before = text.slice(0, m.index) + m[1];
+ return (before ? [document.createTextNode(before)] : [])
+ .concat([el(Format.TAGS[m[2]], {}, Format.inline(m[3]))])
+ .concat(Format.inline(text.slice(m.index + m[0].length)));
+ }
+ };
+
function csrfToken() {
var meta = document.querySelector('meta[name="csrf-token"]');
return meta ? meta.getAttribute('content') : '';
@@ -1294,7 +1340,7 @@
: (qaStage ? Qa.labels[qaStage]
: (orderRevealed ? 'Auflösung' : (closed ? 'Abstimmung geschlossen' : '')));
q('[data-question]').textContent = slide.question;
- q('[data-description]').textContent = slide.description;
+ Format.render(q('[data-description]'), slide.description);
root.classList.toggle('stage--content', !slide.isInteractive);
root.classList.toggle('stage--video', slide.type === 'youtube');
renderMedia(slide);