Gib dem Fließtext den Editor der Dokumente und lass Überschrift und Fließtext die volle Breite nutzen
Fließtext Version 2: formatierter Text (bereinigtes HTML) im gemeinsamen Editor mit Zwischenüberschriften, fett, kursiv, Links, Listen, Zitat und Tabellen. Links auf eigene Seiten (/seite, #anker) bleiben im CMS erhalten (FormattedText mit internalLinks), in Verwaltung und PDF weiterhin nicht. Version 1 (Klartext) wird beim Lesen zu Absätzen. Tabellen stehen in einem scrollbaren, tastaturerreichbaren Rahmen. Das Maß für gespeichertes HTML steigt von 20000 auf 100000 Zeichen. Neue Einstellung "Breite des Texts" für Überschrift und Fließtext: Vorgabe volle Breite des Platzes, wahlweise Lesebreite wie bisher (Überschrift 22 Zeichen, Text 70 Zeichen). Bestehende Seiten nutzen dadurch ohne Eingriff die ganze Breite. Der Test zu "Altes Eingabeformat" erwartet bewusst das gespeicherte HTML der Version 2. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5233b96c42
commit
79b58903ac
17 files changed
+424
-37
No files matched your search
@@ -34,7 +34,8 @@ final class FormattedText
|
||||
/** Angaben der Redaktion, die formatiert gespeichert werden. Suchbegriffe, Titel und Teaser bleiben Klartext. */
|
||||
public const FIELDS = ['summary', 'description'];
|
||||
|
||||
private static ?HtmlSanitizer $sanitizer = null;
|
||||
/** @var array<string, HtmlSanitizer> je Linkregel eine Bereinigung (siehe sanitizer()) */
|
||||
private static array $sanitizers = [];
|
||||
|
||||
/** Symbolleiste der Editoren; muss zur Auswahl oben passen. */
|
||||
public const TOOLBAR = [
|
||||
@@ -53,8 +54,12 @@ public static function isHtml(?string $value): bool
|
||||
|
||||
/**
|
||||
* Kanonische Form eines gespeicherten oder eingegebenen Werts (HTML oder Klartext). Leer, wenn kein Text übrig ist.
|
||||
*
|
||||
* `$internalLinks`: Links auf Seiten der eigenen Website (`/materialien`, `#anker`) bleiben erhalten. Das gilt für
|
||||
* Texte der Website (CMS); Verwaltung und PDF kennen nur ausdrückliche Adressen (http, https, mailto). Die Form
|
||||
* gehört zum Text: Wer mit `true` speichert, liest auch mit `true`.
|
||||
*/
|
||||
public static function canonical(?string $value): string
|
||||
public static function canonical(?string $value, bool $internalLinks = false): string
|
||||
{
|
||||
$value = trim((string) $value);
|
||||
|
||||
@@ -62,18 +67,18 @@ public static function canonical(?string $value): string
|
||||
return '';
|
||||
}
|
||||
|
||||
return self::normalize(self::isHtml($value) ? $value : self::legacyToHtml($value));
|
||||
return self::normalize(self::isHtml($value) ? $value : self::legacyToHtml($value), $internalLinks);
|
||||
}
|
||||
|
||||
/**
|
||||
* Kanonische Form eines Werts, der sicher HTML ist (zum Beispiel aus der Quelle Shinkan), auch wenn er nicht mit
|
||||
* einem Blockelement beginnt.
|
||||
*/
|
||||
public static function canonicalHtml(?string $html): string
|
||||
public static function canonicalHtml(?string $html, bool $internalLinks = false): string
|
||||
{
|
||||
$html = trim((string) $html);
|
||||
|
||||
return $html === '' ? '' : self::normalize($html);
|
||||
return $html === '' ? '' : self::normalize($html, $internalLinks);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -85,9 +90,9 @@ public static function canonicalHtml(?string $html): string
|
||||
*
|
||||
* @param (callable(int): ?array{src?: string, alt?: string, note?: string})|null $images
|
||||
*/
|
||||
public static function html(?string $value, ?callable $images = null): string
|
||||
public static function html(?string $value, ?callable $images = null, bool $internalLinks = false): string
|
||||
{
|
||||
return self::renderImages(self::canonical($value), $images);
|
||||
return self::renderImages(self::canonical($value, $internalLinks), $images);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -454,10 +459,10 @@ public static function legacyToHtml(?string $text): string
|
||||
return $html;
|
||||
}
|
||||
|
||||
private static function normalize(string $html): string
|
||||
private static function normalize(string $html, bool $internalLinks = false): string
|
||||
{
|
||||
$html = self::mapLegacyTags($html);
|
||||
$html = trim(self::sanitizer()->sanitize($html));
|
||||
$html = trim(self::sanitizer($internalLinks)->sanitize($html));
|
||||
|
||||
if ($html === '') {
|
||||
return '';
|
||||
@@ -694,9 +699,9 @@ private static function runsText(array $runs): string
|
||||
return trim(implode('', array_map(fn (array $run): string => $run['text'], $runs)));
|
||||
}
|
||||
|
||||
private static function sanitizer(): HtmlSanitizer
|
||||
private static function sanitizer(bool $internalLinks = false): HtmlSanitizer
|
||||
{
|
||||
return self::$sanitizer ??= new HtmlSanitizer(
|
||||
return self::$sanitizers[$internalLinks ? 'site' : 'catalog'] ??= new HtmlSanitizer(
|
||||
(new HtmlSanitizerConfig)
|
||||
->allowElement('p')
|
||||
->allowElement('br')
|
||||
@@ -720,7 +725,7 @@ private static function sanitizer(): HtmlSanitizer
|
||||
->allowElement('img', ['data-id', 'alt'])
|
||||
->allowElement('a', ['href'])
|
||||
->allowLinkSchemes(['http', 'https', 'mailto'])
|
||||
->allowRelativeLinks(false)
|
||||
->allowRelativeLinks($internalLinks)
|
||||
->forceAttribute('a', 'rel', 'noopener noreferrer')
|
||||
->withMaxInputLength(100000),
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user