"""Default HTML skeletons for ESPD rich-text editors (visible outlines).""" from __future__ import annotations from app.services.espd.models import DocumentType # Placeholder paragraph shown under each heading so the outline is obvious in TipTap. _HINT = "
Заполните раздел…
" def _h2(title: str) -> str: return f"Краткое описание состава текста программы.
", _h2("2. Текст программы"), "// Вставьте листинг или фрагменты исходного кода…\n",
_h2("3. Примечания"),
]
),
DocumentType.IMP.value: "\n".join(
[
_h2("1. Перечень исполняемых модулей"),
"Таблица файлов формируется из загруженного ZIP при генерации DOCX. " "Здесь можно указать пояснения к составу поставки.
", _h2("2. Инструкция по установке / размещению"), _h2("3. Проверка контрольных сумм"), "Контрольная сумма ZIP подставляется автоматически при генерации.
", ] ), } def get_skeleton(doc_type: str | DocumentType) -> str: key = doc_type.value if isinstance(doc_type, DocumentType) else str(doc_type) return SKELETONS.get(key, "") def all_skeletons() -> dict[str, str]: return dict(SKELETONS) def is_blank_html(html: str | None) -> bool: """True if editor content is empty / only whitespace or empty tags.""" if not html or not str(html).strip(): return True import re from html import unescape text = re.sub(r"<[^>]+>", " ", str(html)) text = unescape(text) text = re.sub(r"\s+", " ", text).strip() return text == ""