#!/usr/bin/env python3 """ restore-chat-js-with-preview.py - Re-inline the chat-widget JS into styles.el's page_close() so that extract-js.py picks up the freshly modified source on the next build (instead of carrying the obfuscated old asset forward forever). What this writes: - The original chat-widget IIFE (from commit 640813e^), modified to capture bubble.innerHTML on Share-click and open a preview modal instead of POSTing to /api/share immediately. - Modal HTML (#neuron-share-preview-modal) inserted right before the chat-widget script. - The /api/share POST in publishSharePreview() sends both answer (legacy plaintext), answer_html (rendered, sanitized server-side), and answer_plaintext (og:desc). Idempotent. Re-run is a no-op once the inline block is present. """ from __future__ import annotations import re from pathlib import Path REPO_ROOT = Path(__file__).resolve().parent.parent STYLES_EL = REPO_ROOT / "src" / "styles.el" MARKER = "neuron-share-preview-modal" # El strings use \" for embedded ". Newlines stay literal. Backticks fine. # We assemble the inline JS as a single literal: opening . # Every double-quote inside must become \\" in the El source. We write it as a # raw string and use string substitution at the end. CHAT_HTML_AND_JS = r"""
Preview
This is what you are about to publish
""" # Replace the line `` # with our new inline content + script. extract-js will then re-extract this # fresh inline block to a content-hashed asset on the next build. OLD_LINE = '' def main(): src = STYLES_EL.read_text(encoding="utf-8") # If the anchor `