impl. Kroki, compile path, and code-editor feature

This commit is contained in:
Anya Tokugawa committed 2026-06-18 00:06:16 +09:00
1 parent c1bc8f0c03
commit 94d56f9a8f
49 files changed
+40652 -389

No files matched your search

+109
View File
@@ -0,0 +1,109 @@
package server
import (
"net/http"
"strings"
)
type MarkdownLine struct {
Number int
Text string
}
func splitMarkdownLines(
body string,
) []MarkdownLine {
body =
strings.ReplaceAll(
body,
"\r\n",
"\n",
)
lines :=
strings.Split(
body,
"\n",
)
out :=
make(
[]MarkdownLine,
0,
len(lines),
)
for i, line := range lines {
out = append(
out,
MarkdownLine{
Number: i + 1,
Text: line,
},
)
}
return out
}
func (s *Server) handleMarkdownView(
w http.ResponseWriter,
r *http.Request,
) {
path :=
strings.TrimPrefix(
r.URL.Path,
"/v/markdown",
)
if path == "" {
path = "/"
}
if !strings.HasPrefix(path, "/") {
path = "/" + path
}
objectUUID, err :=
s.store.ResolvePath(
path,
)
if err != nil {
http.NotFound(w, r)
return
}
markdown, err :=
s.compileMarkdownFromPath(
path,
)
if err != nil {
http.Error(w, err.Error(), 500)
return
}
s.render(
w,
"markdown_view.gohtml",
map[string]any{
"NavItems": resolveNavItems(
s.getSystemNavItems(),
NavContext{
Path: path,
ObjectUUID: objectUUID,
ObjectURI: "uuid:" + objectUUID,
},
),
"Path": path,
"ObjectUUID": objectUUID,
"ObjectURI": "uuid:" + objectUUID,
"Lines": splitMarkdownLines(markdown),
"MarkdownRaw": markdown,
},
)
}