Format slide texts in WhatsApp style
CI / Deploy / test (push) Successful in 1m9s
CI / Deploy / deploy (push) Skipped

Slide descriptions support *bold*, _italic_, ~strikethrough~ and lists
with "- " or "* " at the start of a line. FormatHelper renders them for
the participant page and the PDF (escaping everything else), Format in
plenario.js builds the same DOM for presenter and embed. Participant
input stays plain text.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
gnilebeinandClaude Opus 5.5 committed 2026-11-11 14:23:10 +01:00
1 parent 3465f69bfc
commit 8d3d8d4341
12 files changed
+215 -8

No files matched your search

@@ -0,0 +1,59 @@
<?php
declare(strict_types=1);
namespace App\Test\TestCase\View\Helper;
use App\View\Helper\FormatHelper;
use Cake\TestSuite\TestCase;
use Cake\View\View;
/**
* WhatsApp style formatting of slide texts.
*/
class FormatHelperTest extends TestCase
{
protected FormatHelper $Format;
protected function setUp(): void
{
parent::setUp();
$this->Format = new FormatHelper(new View());
}
public function testInlineMarkers(): void
{
$this->assertSame('<strong>fett</strong>', $this->Format->text('*fett*'));
$this->assertSame('ganz <em>kursiv</em> hier', $this->Format->text('ganz _kursiv_ hier'));
$this->assertSame('<s>alt</s> neu', $this->Format->text('~alt~ neu'));
$this->assertSame('<strong>zwei Wörter</strong>, gut', $this->Format->text('*zwei Wörter*, gut'));
$this->assertSame('<strong><em>beides</em></strong>', $this->Format->text('*_beides_*'));
$this->assertSame('<strong>a</strong> und <strong>b</strong>', $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<br>zwei', $this->Format->text("eins\r\nzwei"));
$this->assertSame(
'Agenda:<ul><li>Bericht</li><li><strong>Wahl</strong></li></ul>Danke!',
$this->Format->text("Agenda:\n- Bericht\n* *Wahl*\nDanke!"),
);
}
public function testEverythingElseIsEscaped(): void
{
$this->assertSame(
'&lt;script&gt;x&lt;/script&gt; <strong>&lt;b&gt;</strong> &amp;',
$this->Format->text('<script>x</script> *<b>* &'),
);
$this->assertSame('', $this->Format->text(null));
}
}