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