diff --git a/hosts/ocaml/bin/sx_server.ml b/hosts/ocaml/bin/sx_server.ml index 93540f20..9466cff5 100644 --- a/hosts/ocaml/bin/sx_server.ml +++ b/hosts/ocaml/bin/sx_server.ml @@ -4000,7 +4000,17 @@ let http_mode port = let body_str = match Sx_ref.eval_expr aser_call (Env env) with | String s | SxExpr s -> s | v -> Sx_types.inspect v in let status = !_pending_response_status in - http_response ~status ~content_type:"text/sx; charset=utf-8" body_str) + (* HX-Request → render to HTML for htmx; otherwise SX wire format *) + let is_hx = has_substring (String.lowercase_ascii data) "hx-request" in + if is_hx then + let html = try + let exprs = Sx_parser.parse_all body_str in + let expr = match exprs with [e] -> e | [] -> Nil | _ -> List (Symbol "<>" :: exprs) in + Sx_render.sx_render_to_html env expr env + with _ -> body_str in + http_response ~status ~content_type:"text/html; charset=utf-8" html + else + http_response ~status ~content_type:"text/sx; charset=utf-8" body_str) with e -> Printf.eprintf "[handler] Error for %s: %s\n%!" path (Printexc.to_string e); http_response ~status:500 ~content_type:"text/sx; charset=utf-8"