package server import ( "fmt" "html" "regexp" "strings" ) var childrenMacroRe = regexp.MustCompile(`\{\{children(?::([^}]+))?\}\}`) func (s *Server) expandMacros( body string, currentPath string, ) string { return childrenMacroRe.ReplaceAllStringFunc( body, func(m string) string { matches := childrenMacroRe.FindStringSubmatch(m) targetPath := currentPath if len(matches) >= 2 && strings.TrimSpace(matches[1]) != "" { targetPath = strings.TrimSpace( matches[1], ) } if !strings.HasPrefix(targetPath, "/") { targetPath = "/" + targetPath } children, err := s.store.ListChildPaths( targetPath, ) if err != nil { return "" } var b strings.Builder b.WriteString( `
`, ) b.WriteString("") b.WriteString("
") return b.String() }, ) }