From 5c1b1508a253cae138dc6ab8c30597e37ff55615 Mon Sep 17 00:00:00 2001 From: Nimit Bhardwaj Date: Thu, 7 May 2026 00:24:36 +0530 Subject: [PATCH] Fix Latex Rendering in Openfang Web --- crates/openfang-api/src/webchat.rs | 9 ++++---- crates/openfang-api/static/js/pages/chat.js | 23 +++++++++++++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/crates/openfang-api/src/webchat.rs b/crates/openfang-api/src/webchat.rs index e0f6926f9f..14f44c62e1 100644 --- a/crates/openfang-api/src/webchat.rs +++ b/crates/openfang-api/src/webchat.rs @@ -90,11 +90,11 @@ pub async fn webchat_page() -> impl IntoResponse { let html = WEBCHAT_HTML.replace(NONCE_PLACEHOLDER, &nonce); let csp = format!( "default-src 'self'; \ - script-src 'self' 'nonce-{nonce}' 'unsafe-eval'; \ - style-src 'self' 'unsafe-inline' https://fonts.googleapis.com https://fonts.gstatic.com; \ + script-src 'self' 'nonce-{nonce}' 'unsafe-eval' https://cdn.jsdelivr.net; \ + style-src 'self' 'unsafe-inline' https://fonts.googleapis.com https://fonts.gstatic.com https://cdn.jsdelivr.net; \ img-src 'self' data: blob:; \ - connect-src 'self' ws://localhost:* ws://127.0.0.1:* wss://localhost:* wss://127.0.0.1:*; \ - font-src 'self' https://fonts.gstatic.com; \ + connect-src 'self' ws://localhost:* ws://127.0.0.1:* wss://localhost:* wss://127.0.0.1:* https://cdn.jsdelivr.net; \ + font-src 'self' https://fonts.gstatic.com https://cdn.jsdelivr.net; \ media-src 'self' blob:; \ frame-src 'self' blob:; \ object-src 'none'; \ @@ -120,6 +120,7 @@ pub async fn webchat_page() -> impl IntoResponse { /// All vendor libraries (Alpine.js, marked.js, highlight.js) are bundled /// locally — no CDN dependency. Alpine.js is included LAST because it /// immediately processes x-data directives and fires alpine:init on load. +/// KaTeX is loaded dynamically from jsdelivr CDN when needed for LaTeX rendering. const WEBCHAT_HTML: &str = concat!( include_str!("../static/index_head.html"), "