Extract Grammaratur, Dregarnuhr, Geduldh, Mestionora, Ordoschnellic, Schutzaria, Kunstzeal and Seheweit behind compatible application contracts. Include accumulated editor resilience, navigation and theme UX, remote CLI, storage/schema and DR groundwork, tests and design/operations documentation. Verified: uncached full Go suite; go vet ./...; race tests for all eight components; 11 targeted Chromium tests; Node suites; 19 Python CLI tests; reproducible editor build. No push, release tag or deployment in this checkpoint.
55 lines
1.2 KiB
Go
55 lines
1.2 KiB
Go
package server
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
|
|
"pageswiki/internal/grammaratur"
|
|
"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"`
|
|
Authoring bool `json:"authoring"`
|
|
}
|
|
|
|
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 {
|
|
if req.Authoring {
|
|
html = grammaratur.MarkdownAuthoringHTML(req.Markdown)
|
|
} 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})
|
|
}
|