Files
pages/internal/server/render_api.go
T
Anya Tokugawa c1175d389f Implement Knowledge City platform, organizer and DAV integration
Capture accumulated application, UI, CLI, regression tests and design documentation changes, including task project mapping and default CalDAV list naming.

Keep deployment data, backups, local credentials and build artifacts out of Git. Move the Compose enrollment token to an ignored local environment file.
2026-09-27 14:44:43 +09:00

49 lines
1023 B
Go

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})
}