diff --git a/backend/app/sanitize.py b/backend/app/sanitize.py index c631772..bd86fb3 100644 --- a/backend/app/sanitize.py +++ b/backend/app/sanitize.py @@ -29,6 +29,21 @@ def _clean_url(value: Any) -> str | None: return stripped +def _is_junk_paragraph(node: Any) -> bool: + """پاراگراف خالی یا فقط نویسهٔ خنثی (nbsp/فاصله) — داخل نقل‌قول حذف می‌شود.""" + if not isinstance(node, dict) or node.get("type") != "paragraph": + return False + content = node.get("content") or [] + if not content: + return True + return all( + isinstance(item, dict) + and item.get("type") == "text" + and not str(item.get("text", "")).replace("\xa0", " ").strip() + for item in content + ) + + def _walk(node: Any) -> Any: if isinstance(node, list): return [_walk(item) for item in node] @@ -48,6 +63,9 @@ def _walk(node: Any) -> Any: cleaned[key] = attrs else: cleaned[key] = _walk(value) + # داخل نقل‌قول: پاراگراف‌های خالی/نویسهٔ خنثی حذف — وگرنه خط خالی اضافه رندر می‌شود + if cleaned.get("type") == "blockquote" and isinstance(cleaned.get("content"), list): + cleaned["content"] = [c for c in cleaned["content"] if not _is_junk_paragraph(c)] return cleaned