diff --git a/src/generator/generator.py b/src/generator/generator.py index e41c772..51acf31 100644 --- a/src/generator/generator.py +++ b/src/generator/generator.py @@ -260,13 +260,32 @@ class GhostPublisher: tags: list[str] | None = None) -> dict: import aiohttp as _aio import markdown as _md + clean = _strip_researchowl_header(markdown_content) html = _md.markdown(clean, extensions=["extra"]) + + logger.info("Ghost publish_draft", html_length=len(html), + html_preview=html[:200]) + + if not html.strip(): + raise ValueError("Ghost: HTML vacío tras conversión markdown — contenido no enviado") + + # Ghost 5.x (Lexical editor): el campo "html" es solo de lectura en la API. + # La forma fiable de enviar HTML arbitrario es via mobiledoc con HTML card, + # que Ghost acepta en todas las versiones de v5 y renderiza sin conversión. + mobiledoc = json.dumps({ + "version": "0.3.1", + "atoms": [], + "cards": [["html", {"html": html}]], + "markups": [], + "sections": [[10, 0]], + }) + token = self._make_token() body = { "posts": [{ "title": title, - "html": html, + "mobiledoc": mobiledoc, "status": "draft", "tags": [{"name": t} for t in (tags or ["investigacion"])], }]