Skip to content

HTML Live Preview for Code Blocks#2231

Open
ryoiki-tokuiten wants to merge 1 commit into
anyproto:developfrom
ryoiki-tokuiten:html-live-preview
Open

HTML Live Preview for Code Blocks#2231
ryoiki-tokuiten wants to merge 1 commit into
anyproto:developfrom
ryoiki-tokuiten:html-live-preview

Conversation

@ryoiki-tokuiten
Copy link
Copy Markdown

Adds a real-time HTML preview panel to code blocks when the language is set to HTML. The preview renders user HTML/CSS/JS in a sandboxed iframe using a CSP-bypassed embed proxy (dist/embed/iframe.html), supporting external CDN scripts (e.g. Tailwind CSS, Babel for React JSX).

Just like markdown, HTML format is becoming popular again for learning visually with the help of LLMs. I personally find myself making and storing lots of HTML in my anytype notes these days. We don't currently have preview HTML option inside the app itself so it's very frustrating to always download and open it in a separate web browser. I have integrated the preview support with this PR.

image

Clicking on "Show Preview" opens the side panel with the preview. Close and Full Screen option always visible to the user.

image

Adds a real-time HTML preview panel to code blocks when the language is
set to HTML. The preview renders user HTML/CSS/JS in a sandboxed iframe
using a CSP-bypassed embed proxy (dist/embed/iframe.html), supporting
external CDN scripts (e.g. Tailwind CSS, Babel for React JSX).

Key changes:
- src/ts/component/block/text.tsx: Added preview toggle logic with
  ReactDOM.createPortal for a fixed right-side preview panel. Uses
  postMessage to send raw HTML to embed/iframe.html. Includes fullscreen
  toggle and proper cleanup on unmount.
- dist/embed/iframe.html: Added rawHtmlPreview handler that creates a
  Blob URL iframe to render arbitrary HTML without CSP restrictions.
- electron/ts/main.ts: Excluded /embed/iframe.html from CSP header
  injection so the preview iframe can load external scripts.
- electron/json/cors.json: Added blob: and about: to frame-src for
  nested iframe support.
- src/scss/block/text.scss: Added .htmlPreviewPanel styles (fixed
  position, header bar with expand/close buttons, fullscreen mode).
- src/scss/common.scss: Added body.html-preview-split-active rule to
  resize #appContainer to 50vw for true side-by-side layout.

The preview uses Anytype's existing embed/iframe.html infrastructure
and Icon components (common/eye0, common/eye1, common/expand,
common/close) for a consistent, production-ready UI.
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 25, 2026

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@ryoiki-tokuiten
Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant