diff --git a/app/Domain/Catalog/FormattedText.php b/app/Domain/Catalog/FormattedText.php index 90722f7..6412c25 100644 --- a/app/Domain/Catalog/FormattedText.php +++ b/app/Domain/Catalog/FormattedText.php @@ -2,6 +2,7 @@ namespace App\Domain\Catalog; +use App\Domain\Cms\Widgets\Support\TextMarkers; use Dom\HTMLDocument; use Dom\Node; use Symfony\Component\HtmlSanitizer\HtmlSanitizer; @@ -557,7 +558,9 @@ private static function block(Node $node): string } } - return $items === '' ? '' : '<'.$name.'>'.$items.''.$name.'>'; + // Zeichen der Liste (Nummern im Kreis, Symbol): nur Schlüssel, die TextMarkers kennt; im Profil der + // Verwaltung hat die Bereinigung sie schon entfernt. + return $items === '' ? '' : '<'.$name.TextMarkers::attributes($name, $node).'>'.$items.''.$name.'>'; } $inner = self::inner($node); @@ -571,7 +574,10 @@ private static function block(Node $node): string ? ' style="'.$node->getAttribute('style').'"' : ''; - return self::hasContent($inner) ? '<'.$name.$align.'>'.$inner.''.$name.'>' : ''; + // Symbol vor dem Absatz (nur Absätze auf der obersten Ebene, siehe TextMarkers::attributes()). + $symbol = $name === 'p' ? TextMarkers::attributes('p', $node) : ''; + + return self::hasContent($inner) ? '<'.$name.$align.$symbol.'>'.$inner.''.$name.'>' : ''; } /** @@ -779,8 +785,10 @@ private static function sanitizer(bool $site = false): HtmlSanitizer // Das Webprofil lässt zusätzlich Spans (Größe, Farbe) und den Stil an Absätzen und Überschriften zu; siteMarks() // führt beides danach auf feste Werte zurück. Verwaltung und PDF kennen weder Spans noch Stile. $text = $site ? ['style'] : []; + $paragraph = $site ? [...$text, ...TextMarkers::PARAGRAPH_ATTRIBUTES] : []; + $list = $site ? TextMarkers::LIST_ATTRIBUTES : []; $config = (new HtmlSanitizerConfig) - ->allowElement('p', $text) + ->allowElement('p', $paragraph) ->allowElement('h3', $text) ->allowElement('h4', $text) ->allowElement('h5', $text) @@ -795,8 +803,8 @@ private static function sanitizer(bool $site = false): HtmlSanitizer ->allowElement('br') ->allowElement('strong') ->allowElement('em') - ->allowElement('ul') - ->allowElement('ol') + ->allowElement('ul', $list) + ->allowElement('ol', $list) ->allowElement('li') ->allowElement('blockquote') ->allowElement('table') diff --git a/app/Domain/Cms/Widgets/Support/RichText.php b/app/Domain/Cms/Widgets/Support/RichText.php index 314a01e..2507df2 100644 --- a/app/Domain/Cms/Widgets/Support/RichText.php +++ b/app/Domain/Cms/Widgets/Support/RichText.php @@ -12,7 +12,7 @@ final class RichText { /** Werkzeugleiste des Editors; muss zur Erlaubnisliste unten passen. */ - public const TOOLBAR = [['bold', 'italic', 'link', 'interneSeite'], ['bulletList', 'orderedList'], ['undo', 'redo']]; + public const TOOLBAR = [['bold', 'italic', 'link', 'interneSeite'], ['bulletList', 'orderedList'], ['absatzSymbol', 'listenStil'], ['undo', 'redo']]; private static ?HtmlSanitizer $sanitizer = null; @@ -22,7 +22,8 @@ public static function sanitize(?string $html): string return ''; } - return trim(self::sanitizer()->sanitize($html)); + // Zeichen vor Absätzen und in Listen (ADR-69) bleiben nur mit bekannten Schlüsseln erhalten. + return TextMarkers::clean(trim(self::sanitizer()->sanitize($html))); } /** @@ -60,14 +61,14 @@ private static function sanitizer(): HtmlSanitizer { return self::$sanitizer ??= new HtmlSanitizer( (new HtmlSanitizerConfig) - ->allowElement('p') + ->allowElement('p', TextMarkers::PARAGRAPH_ATTRIBUTES) ->allowElement('br') ->allowElement('strong') ->allowElement('b') ->allowElement('em') ->allowElement('i') - ->allowElement('ul') - ->allowElement('ol') + ->allowElement('ul', TextMarkers::LIST_ATTRIBUTES) + ->allowElement('ol', TextMarkers::LIST_ATTRIBUTES) ->allowElement('li') ->allowElement('a', ['href']) ->allowLinkSchemes(['http', 'https', 'mailto']) diff --git a/app/Domain/Cms/Widgets/Support/TextMarkers.php b/app/Domain/Cms/Widgets/Support/TextMarkers.php new file mode 100644 index 0000000..3ae14e2 --- /dev/null +++ b/app/Domain/Cms/Widgets/Support/TextMarkers.php @@ -0,0 +1,221 @@ +` (nur Absätze auf der obersten Ebene des Texts), + * - `
`, `
Absatz
Eins
Punkt
A
', FormattedText::canonical('A
', true)); + $this->assertSame('A
', FormattedText::canonical('A
', true)); + // Kreise gehören zur Nummerierung, Symbole zur Aufzählung; unbekannte Farbe entfällt, die Nummerierung bleibt im Kreis. + $this->assertSame('Eins
Punkt
Punkt
Eins
A
', FormattedText::canonical('A
', true), 'Fremde Attribute entfallen.'); + } + + public function test_a_symbol_stays_only_on_a_top_level_paragraph(): void + { + $symbol = $this->symbol(); + + $this->assertSame('Punkt
Punkt
', FormattedText::canonical('Zitat
', true)); + $this->assertStringNotContainsString('data-symbol', FormattedText::canonical('Zitat
Zelle |
A
', FormattedText::canonical('A
')); + $this->assertSame('E
Nur Text
A
Mit Symbol
' + .'Eins
Zwei
A
B