Sub topic 4
Lists and nesting
This chapter assumes you can edit a Markdown file and commit it on GitHub. You should also know how headings and paragraphs work. Lists are the most common way to present install steps, feature summaries, and requirements in a README.
Unordered and ordered lists
An unordered list starts each item with -, *, or +. An ordered list starts each item with a number followed by a period. Put a space after the marker, because -item is plain text.
- Fast startup
- No configuration needed
- Works offline
1. Clone the repository
2. Install dependencies
3. Run the testsPick one bullet character and use it throughout the file. CommonMark treats a change of bullet character as the start of a new list. That can split what you meant as one list into two.
GitHub uses only the first number of an ordered list. The later numbers are ignored when the page is rendered.
1. First step
1. Second step
1. Third stepThis renders as 1, 2, 3. Numbering every item 1. keeps diffs small when you insert a step. To start at another number, begin with that number, for example 4..
Nesting
A nested list is indented under its parent item. The child must line up with the first character of the parent's text, after the marker and its space.
| Parent marker | Indent for children |
|---|---|
| `-` | 2 spaces |
| `1.` | 3 spaces |
| `10.` | 4 spaces |
1. Install the tool
- On macOS, use Homebrew
- On Linux, use your package manager
2. Create a config file
1. Copy `config.example.yml`
2. Edit the `port` valueA common error is indenting a child by 2 spaces under 1.. The child then falls short of the parent's text and renders as a sibling instead of a child. If a nested list renders flat, check the indent first.
1. Install the tool
- This child is indented too littleParagraphs and code inside items
To attach more content to an item, separate it with a blank line and indent it to the same depth as the item's text.
1. Install the dependencies.
Use a clean environment to avoid version conflicts.
2. Start the server.
```bash
npm start
```The example above shows the indentation rule for a code block. In your own file, write the block with its normal fences at the same indent as the item text.
Tight and loose lists
If any item in a list has a blank line between it and the next, the whole list becomes loose. A loose list wraps each item in a paragraph, so it gets more vertical space. This is a common reason a list looks uneven. Remove stray blank lines between items when you want a compact list.
Exercise
A README has the step 1. Install the tool followed by a line indented 2 spaces: - macOS. The bullet renders as a separate list instead of a child. What is the fix?
Show answer
Indent the bullet by 3 spaces, so it lines up with the text after 1. . Children must reach the parent's text column.