Step 1 of 5 · Reading · ~3 min
Read
Lists & Code
Lists
- unordered 1. ordered
* unordered 2. ordered
+ unordered 3) also ordered
Three bullet characters, two ordered delimiters, and one rule that surprises almost everyone the first time they hit it.
Do the three bullet characters mix?
No. Two items belong to the same list only if they use the same marker character, so changing the bullet silently ends one list and starts another.
Four items, three lists. The same applies to . versus ) on ordered items.
Writers who "vary the bullets for readability" are unknowingly producing three
adjacent lists, and the extra vertical margin they see in the rendered page is
the reason.
What happens to the numbers you type?
Only the first one counts. The start value comes from the opening item; every later number is discarded and the browser counts for you.
| Source | Rendered as |
|---|---|
1. 2. 3. | 1, 2, 3 |
1. 1. 1. | 1, 2, 3 |
3. 9. 4. | 3, 4, 5 — via <ol start="3"> |
This is why the all-ones style is safe: reordering the source never leaves you renumbering by hand.
Where does a nested list have to start?
Not "two spaces" — at the content column of the item it nests inside. The content column is wherever the parent's text begins, which depends on how wide the marker plus its trailing spaces were:
- top level item
^ content column 2, a nested list starts here
1. ordered item
^ content column 3
- padded item
^ content column 4
Under-indent and the line becomes a sibling of the parent instead of a child; over-indent by four past the content column and it becomes an indented code block inside the item. Getting this right is what separates parsers that handle real README files from ones that only handle their own test fixtures.
One more thing the spec allows
A list can interrupt a paragraph: no blank line is required between prose and the bullets that follow it. Your paragraph accumulator therefore cannot simply run until the next blank line — it has to stop the moment a line looks like a list marker.
Your exercise
Convert flat unordered and ordered lists, and wrap everything else in paragraphs.
The mistake the grader catches is a paragraph that swallows the list below
it. A hidden test feeds Intro paragraph. then a blank line, two - item
lines, another blank, then Closing. If your paragraph loop only stops at blank
lines you will produce the right output here but fail the moment items follow
prose directly, and the visible list tests will show <p>- apple - banana</p>
instead of a <ul>.
Make the paragraph collector break on three conditions — blank line, bullet
marker, ordered marker — and emit the opening and closing <ul> or <ol> tags
on their own output lines, exactly as the expected output shows.
Discussion
Ask a question, share an insight, or help someone who’s stuck.
Sign in to post a comment or reply.
Loading…