fixed empty header in markdown

git-svn-id: file:///srv/svn/repo/aya/trunk@3 cec141ff-132a-4243-88a5-ce187bd62f94
This commit is contained in:
zaitsev.serge
2014-12-05 17:09:10 +00:00
parent 5b0b02034b
commit e8b697f054
2 changed files with 15 additions and 1 deletions

4
zs.go
View File

@@ -32,7 +32,9 @@ func split2(s, delim string) (string, string) {
func md(s string) (map[string]string, string) {
v := map[string]string{}
// FIXME: if no header?
if strings.Index(s, "\n\n") == -1 {
return map[string]string{}, s
}
header, body := split2(s, "\n\n")
for _, line := range strings.Split(header, "\n") {
key, value := split2(line, ":")

View File

@@ -46,6 +46,18 @@ this: is a content`)
if body != "this: is a content" {
t.Error(body)
}
// Test empty md
v, body = md("")
if len(v) != 0 || len(body) != 0 {
t.Error(v, body)
}
// Test empty header
v, body = md("Hello")
if len(v) != 0 || body != "Hello" {
t.Error(v, body)
}
}
func TestRender(t *testing.T) {