mirror of
https://github.com/mickael-menu/zk
synced 2024-11-07 15:20:21 +00:00
27 lines
454 B
Go
27 lines
454 B
Go
package note
|
|
|
|
import (
|
|
"regexp"
|
|
"strings"
|
|
)
|
|
|
|
type Content struct {
|
|
Title string
|
|
Body string
|
|
}
|
|
|
|
var contentRegex = regexp.MustCompile(`(?m)^#\s+(.+?)\s*$`)
|
|
|
|
func Parse(content string) Content {
|
|
var res Content
|
|
|
|
if match := contentRegex.FindStringSubmatchIndex(content); len(match) >= 4 {
|
|
res.Title = content[match[2]:match[3]]
|
|
res.Body = strings.TrimSpace(content[match[3]:])
|
|
} else {
|
|
res.Body = strings.TrimSpace(content)
|
|
}
|
|
|
|
return res
|
|
}
|