Skip to content
This repository has been archived by the owner on Nov 10, 2020. It is now read-only.

Commit

Permalink
Add Task Lists
Browse files Browse the repository at this point in the history
Implement task lists.

Fixes #67
  • Loading branch information
miekg committed May 7, 2016
1 parent a72a0ca commit cf654ee
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -27,7 +27,7 @@ Mmark adds the following syntax elements to [black friday](https://github.com/ru

* TOML titleblock.
* Including other files.
* More enumerated lists.
* More enumerated lists and task-lists.
* Table and codeblock captions.
* Quote attribution (quote "captions").
* Table footers, header and block tables.
Expand Down
5 changes: 5 additions & 0 deletions block_test.go
Expand Up @@ -635,6 +635,11 @@ II. or2`,
* un1
* un2`,
"<ol>\n<li>or1</li>\n<li>or2</li>\n</ol>\n\n<ul>\n<li>un1</li>\n<li>un2</li>\n</ul>\n",

`- [ ] This is an incomplete task.
- [x] This is done.
`,
"<ul>\n<li><input type=\"checkbox\" disabled=\"\"> This is an incomplete task.</li>\n<li><input type=\"checkbox\" checked=\"\" disabled=\"\"> This is done.</li>\n</ul>\n",
}
doTestsBlock(t, tests, 0)
}
Expand Down
8 changes: 8 additions & 0 deletions html.go
Expand Up @@ -602,6 +602,14 @@ func (options *html) ListItem(out *bytes.Buffer, text []byte, flags int) {
out.WriteString("</dt>")
return
}
// task lists
switch {
case bytes.HasPrefix(text, []byte("[ ] ")):
text = append([]byte(`<input type="checkbox" disabled="">`), text[3:]...)
case bytes.HasPrefix(text, []byte("[x] ")) || bytes.HasPrefix(text, []byte("[X] ")):
text = append([]byte(`<input type="checkbox" checked="" disabled="">`), text[3:]...)
}

out.WriteString("<li>")
out.Write(text)
out.WriteString("</li>\n")
Expand Down

0 comments on commit cf654ee

Please sign in to comment.