Skip to content

Step 1 of 5 · Reading · ~3 min

Read

Lists & Code

Blockquotes & HR

> Ship the release notes
> before Friday.

---

A blockquote is the first container block in this course: unlike a heading or a paragraph, it holds other blocks rather than text. That changes how you parse it — you strip the marker off each line and then run the block parser again on what is left.

How much of the line is the marker?

Up to three spaces of indentation, a >, and then one optional space that belongs to the marker rather than to the content. Only one. A second space is real content, and four of them would make indented code inside the quote.

Because the contents are blocks, everything nests naturally: > > quoted twice is a blockquote inside a blockquote, and > # Title is a heading inside a blockquote. You do not need special cases for any of it if you recurse.

What is lazy continuation?

A paragraph inside a blockquote keeps going even on lines that forgot the >. The spec allows it because hard-wrapped email quoting has worked that way since before Markdown existed.

python

Output:

<blockquote>
<p>ship it today</p>
</blockquote>
<blockquote>
<p>ship it today</p>
</blockquote>
<blockquote>
<p>ship it</p>
</blockquote>

The first two are identical — that is laziness working. The third is the limit: a lazy line may only continue a paragraph. The moment the unprefixed line would start a block of its own, the quote ends and the new block belongs to the document, not to the quote. Drop the NEW_BLOCK guard and --- gets swallowed as quoted text.

A blank line always ends the quote. Two quotes separated by a blank line are two <blockquote> elements, never one.

Thematic breaks

Three or more matching -, _, or * on a line of their own, with any amount of space between and after them.

LineResult
--- *** ___<hr />
- - - * * *<hr />, spaces are allowed between
-- **only two — plain paragraph text
+++ ===wrong characters entirely
--- under a paragraphsetext H2, not a break

That last row is why * * * exists as a house style: asterisks can never be a setext underline, so they mean "thematic break" no matter what sits above them.

Your exercise

Convert blockquotes, thematic breaks and paragraphs in one pass.

The mistake the grader catches is emitting one blockquote per line. A hidden test feeds > q1 then > q2, a blank line, then > q3, and expects two <blockquote> elements — the first containing a single paragraph reading q1 q2. If you open and close the tags inside your per-line loop you produce three blockquotes and the diff shows six extra tags.

Collect the consecutive quote lines first, strip each marker, join them with a single space, and only then emit the three output lines <blockquote>, <p>...</p>, </blockquote> — each on its own line, exactly as the expected output shows.

Up nextTight vs Loose ListsLists & Code

Discussion

Ask a question, share an insight, or help someone who’s stuck.

Sign in to post a comment or reply.

Loading…