diff --git a/notes/comment.go b/notes/comment.go index 5e6d88a..3f2838b 100755 --- a/notes/comment.go +++ b/notes/comment.go @@ -34,6 +34,9 @@ func (n *Notes) Comment(urlPath string, lineno int, comment string) error { writer := io.Writer(f2) for i := 0; i < lineno+1; i++ { line, _, err := reader.ReadLine() + if err == io.EOF { + break + } if err != nil { return err } @@ -46,14 +49,13 @@ func (n *Notes) Comment(urlPath string, lineno int, comment string) error { return err } } - formatted := "\n" - formatted += fmt.Sprintf("> *%s*\n", comment) + formatted := fmt.Sprintf("> *%s*\n\n", comment) _, err = io.Copy(writer, strings.NewReader(formatted)) if err != nil { return err } _, err = io.Copy(writer, reader) - if err != nil { + if err != nil && err != io.EOF { return err } f2.Close() diff --git a/notes/file.go b/notes/file.go index a8fcde9..3d3d89f 100755 --- a/notes/file.go +++ b/notes/file.go @@ -41,18 +41,21 @@ func (n *Notes) commentFormer(urlPath string, md []byte) html.RenderNodeFunc { nextHeader := func() { cur++ for cur < len(lines) { - if bytes.Contains(lines[cur], []byte("```")) { - cur++ - for cur < len(lines) && !bytes.Contains(lines[cur], []byte("```")) { + for _, opener_closer := range [][]string{{"```", "```"}, {``, ``}} { + if bytes.Contains(lines[cur], []byte(opener_closer[0])) { + cur++ + for cur < len(lines) && !bytes.Contains(lines[cur], []byte(opener_closer[1])) { + cur++ + } cur++ } - cur++ } if cur >= len(lines) { break } line := lines[cur] - if ok, err := regexp.Match(`^\s*#+\s*[^\s]+\s*$`, line); err != nil { + ok, err := regexp.Match(`^\s*#+\s*.+$`, line) + if err != nil { panic(err) } else if ok { return