Normalize Quill's non-breaking spaces so rich-text descriptions wrap

Quill 2's getSemanticHTML() serializes every space as U+00A0, turning a
whole paragraph into one unbreakable word that stretched the survey cards
far past the viewport. Normalize to plain spaces when sanitizing (which
also heals existing records on every output) and when the editor writes
the serialized HTML back into the textarea.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-26 14:36:28 +02:00
co-authored by Claude Fable 5
parent a4ca026e82
commit 1ceb0ad28e
2 changed files with 13 additions and 1 deletions
+4
View File
@@ -15,6 +15,10 @@
function toSemanticHtml(quill) {
var html = typeof quill.getSemanticHTML === 'function' ? quill.getSemanticHTML() : quill.root.innerHTML;
// Quill 2 serialisiert Leerzeichen als &nbsp; ohne echte Leerzeichen kann
// der Browser den Text nicht umbrechen und das Layout läuft über.
html = html.replace(/&nbsp;|\u00a0/g, ' ');
// Leerer Editor: kein "<p></p>" speichern.
if (/^\s*(<p>(\s|&nbsp;|<br\s*\/?>)*<\/p>\s*)*$/i.test(html)) {
return '';
+9 -1
View File
@@ -28,6 +28,11 @@ final class SurveyHtmlSanitizer
return '';
}
// Quill 2 serialisiert Leerzeichen als geschützte Leerzeichen (&nbsp;/U+00A0).
// Ohne echte Leerzeichen kann der Browser Absätze nicht umbrechen der Text
// sprengt dann das Kartenlayout. Geschützte Leerzeichen sind hier nie gewollt.
$html = str_replace(["\u{00A0}", '&nbsp;', '&#160;', '&#xa0;', '&#xA0;'], ' ', $html);
// Klartext ohne Tags (Altdaten aus dem bisherigen Textarea): Absätze aus
// Leerzeilen bilden, einfache Umbrüche als <br> erhalten.
if (!preg_match('#<[a-z/!]#i', $html)) {
@@ -70,6 +75,7 @@ final class SurveyHtmlSanitizer
$text = (string) preg_replace('#</(p|li|ul|ol)>#i', "\n", $text);
$text = (string) preg_replace('#<br\s*/?>#i', "\n", $text);
$text = html_entity_decode(strip_tags($text), ENT_QUOTES | ENT_HTML5, 'UTF-8');
$text = str_replace("\u{00A0}", ' ', $text);
$text = (string) preg_replace("/[ \t]+\n/", "\n", $text);
$text = (string) preg_replace("/\n{3,}/", "\n\n", $text);
@@ -78,7 +84,9 @@ final class SurveyHtmlSanitizer
public function isEmpty(?string $html): bool
{
return '' === trim(strip_tags((string) $html));
$text = str_replace(["\u{00A0}", '&nbsp;', '&#160;'], ' ', strip_tags((string) $html));
return '' === trim($text);
}
private function convertPlainTextToHtml(string $text): string