From 2556bbfa1bd2dba769dc617bc8b45f9c797df4c1 Mon Sep 17 00:00:00 2001 From: aramesh-site deploy Date: Tue, 6 Oct 2026 11:51:22 +0000 Subject: [PATCH] =?UTF-8?q?fix(blog):=20=D9=BE=D8=A7=DA=A9=E2=80=8C=D8=B3?= =?UTF-8?q?=D8=A7=D8=B2=20=D8=B3=D9=85=D8=AA=20=D8=B3=D8=B1=D9=88=D8=B1=20?= =?UTF-8?q?=E2=80=94=20=D9=BE=D8=A7=D8=B1=D8=A7=DA=AF=D8=B1=D8=A7=D9=81?= =?UTF-8?q?=E2=80=8C=D9=87=D8=A7=DB=8C=20=D8=AE=D8=A7=D9=84=DB=8C/nbsp=20?= =?UTF-8?q?=D8=AF=D8=A7=D8=AE=D9=84=20=D9=86=D9=82=D9=84=E2=80=8C=D9=82?= =?UTF-8?q?=D9=88=D9=84=20=D8=AF=D8=B1=20=D9=87=D8=B1=20=D8=B0=D8=AE=DB=8C?= =?UTF-8?q?=D8=B1=D9=87=20=D8=AD=D8=B0=D9=81=20=D9=85=DB=8C=E2=80=8C=D8=B4?= =?UTF-8?q?=D9=88=D9=86=D8=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/sanitize.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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