package server import ( "encoding/json" "net/http" "pageswiki/internal/render" ) func (s *Server) handleMarkdownRenderAPI( w http.ResponseWriter, r *http.Request, ) { var req struct { Markdown string `json:"markdown"` Path string `json:"path"` Projection bool `json:"projection"` HTML *string `json:"html"` } err := json.NewDecoder(http.MaxBytesReader(w, r.Body, 2<<20)).Decode(&req) if err != nil { http.Error(w, err.Error(), 400) return } html := "" if req.HTML != nil { if !req.Projection { http.Error(w, "HTML input requires projection mode", 400) return } html = *req.HTML } else { html = render.Markdown(req.Markdown) } if req.Projection { path := req.Path if path == "" || path[0] != '/' { path = "/" } html = s.safeHTMLProjection(r, html, path, true) } w.Header().Set("Content-Type", "application/json; charset=utf-8") w.Header().Set("Cache-Control", "private, no-store") _ = json.NewEncoder(w).Encode(map[string]any{"html": html}) }