Sub topic 8
Task lists
This chapter assumes you can write bulleted lists in Markdown, which the Lists chapter covered. It also assumes you can read a rendered README on GitHub.
What a task list is
A task list is a list whose items start with a checkbox. GitHub Flavored Markdown (GFM) adds task lists to standard CommonMark. A checked box means the item is done, and an empty box means it is still open. In a README, they are a compact way to show a roadmap, a release checklist, or a list of supported features.
Syntax
Write a normal list item, then put [ ] or [x] before the text.
- [x] Write the install section
- [ ] Add usage examples
- [ ] ~~Document the legacy API~~Each part has a job:
-makes the line a list item.*,+, and1.also work.[ ]is an unchecked box. It contains exactly one space.[x]is a checked box. A capitalXalso works.- The checkbox must be followed by a space and then the item text.
~~text~~is strikethrough. It marks an item that is dropped rather than done.
You can nest task lists by indenting the child items. Mixing task items and plain items in one list is allowed.
- [x] Release 1.0
- [x] Write tests
- [x] Tag the commit
- [ ] Release 1.1
- [ ] Add a config file
- Decide on a name for the flagWhere checkboxes are clickable
The same syntax behaves differently depending on where it appears.
| Location | Rendered as | Can you click the box? |
|---|---|---|
| `README.md` in a repository | Checkboxes | No, they are read-only |
| Issue or pull request description | Checkboxes | Yes, if you can edit the text |
| Issue or pull request description | A progress count such as "2 of 5 tasks" | Shown in lists and cross-references |
In a README, ticking a box means editing the file and committing the change. Clicking a checkbox in an issue edits the issue text for you.
Common errors
Most broken task lists have a spacing problem.
| You wrote | Result |
|---|---|
| `- [] item` | Plain text. The brackets need a space between them. |
| `- [ ]item` | Plain text. A space must follow the closing bracket. |
| `[ ] item` | Plain text. The line is not a list item. |
| `- [x ] item` | Plain text. Only one character may sit inside the brackets. |
Showing the brackets literally
To show [ ] as text, put a backslash before each bracket, or place it in inline code.
Type `[ ]` for an open item, or \[x\] for a done one.Exercise
A contributor writes - [] Add tests in a README, and it renders as plain text instead of a checkbox. What is wrong, and how do you fix it?
Show answer
The brackets contain no space. GFM requires exactly one space or one x between them. Change the line to - [ ] Add tests.