package notes import ( "errors" "fmt" "io/ioutil" "gitea.inhome.blapointe.com/local/notes-server/filetree" "gitea.inhome.blapointe.com/local/notes-server/notes/editor" "strings" ) func (n *Notes) Edit(urlPath string) (string, error) { p := filetree.NewPathFromURL(urlPath) if p.IsDir() { return "", errors.New("path is dir") } return editFile(p), nil } func editFile(p filetree.Path) string { href := p.HREF href = strings.TrimPrefix(href, "/") hrefs := strings.SplitN(href, "/", 2) href = hrefs[0] if len(hrefs) > 1 { href = hrefs[1] } b, _ := ioutil.ReadFile(p.Local) return fmt.Sprintf(`
`, href, b, editor.CodeMirrorJS, editor.CodeMirrorCSS, editor.CodeMirrorVIM, editor.CodeMirrorTheme) }