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.
97 lines
1.5 KiB
Go
97 lines
1.5 KiB
Go
package server
|
|
|
|
import (
|
|
"net/http"
|
|
"strings"
|
|
|
|
"pageswiki/internal/grammaratur"
|
|
)
|
|
|
|
func (s *Server) compileMarkdownFromPath(
|
|
r *http.Request,
|
|
path string,
|
|
) (string, error) {
|
|
return s.transpileMarkdownFromPath(r, path, markdownAuthoring)
|
|
}
|
|
|
|
type markdownTranspileMode string
|
|
|
|
const (
|
|
markdownAuthoring markdownTranspileMode = "authoring"
|
|
markdownProjection markdownTranspileMode = "projection"
|
|
)
|
|
|
|
func (s *Server) transpileMarkdownFromPath(r *http.Request, path string, mode markdownTranspileMode) (string, error) {
|
|
|
|
objectUUID, err :=
|
|
s.store.ResolvePathInDomain(
|
|
s.domainUUIDForRequest(r),
|
|
path,
|
|
)
|
|
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
latest, err :=
|
|
s.latestRevisionForRequest(
|
|
r,
|
|
objectUUID,
|
|
)
|
|
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
html := latest.Body
|
|
if mode == markdownProjection {
|
|
html = s.expandMacrosForRequest(r, html, path, s.domainUUIDForRequest(r))
|
|
} else {
|
|
return grammaratur.HTMLToMarkdownAuthoring(html)
|
|
}
|
|
|
|
return grammaratur.HTMLToMarkdown(
|
|
html,
|
|
)
|
|
}
|
|
|
|
func (s *Server) handleCompileMarkdown(
|
|
w http.ResponseWriter,
|
|
r *http.Request,
|
|
) {
|
|
|
|
path :=
|
|
strings.TrimPrefix(
|
|
r.URL.Path,
|
|
"/:/compile/markdown",
|
|
)
|
|
|
|
if path == "" {
|
|
path = "/"
|
|
}
|
|
|
|
if !strings.HasPrefix(path, "/") {
|
|
path = "/" + path
|
|
}
|
|
|
|
out, err :=
|
|
s.compileMarkdownFromPath(
|
|
r,
|
|
path,
|
|
)
|
|
|
|
if err != nil {
|
|
http.NotFound(w, r)
|
|
return
|
|
}
|
|
|
|
w.Header().Set(
|
|
"Content-Type",
|
|
"text/markdown; charset=utf-8",
|
|
)
|
|
|
|
_, _ = w.Write(
|
|
[]byte(out),
|
|
)
|
|
}
|