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, then run the block parser again on what is left. Your program will convert quotes, thematic breaks and paragraphs, with quote contents handled as their own little document.

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). What remains is the quote's own line: > # Title leaves # Title, > alone leaves an empty line.

Because the contents are blocks, a blank quote line (a bare >) separates paragraphs inside the quote, just as a blank line does outside:

SourceOutput
> one, > two<blockquote>, <p>one two</p>, </blockquote>
> one, >, > two<blockquote>, <p>one</p>, <p>two</p>, </blockquote>
> one, blank line, > twotwo separate blockquotes

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

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.

LinesResult
> ship it, todayone quote holding ship it today
> ship it, ---a quote, then <hr /> (a break is not a continuation)
> first, >, latelate is not lazy: the quote's last paragraph was already closed by the blank > line, so it starts a paragraph outside

The rule to remember: a lazy line may only continue a paragraph that is still open. The moment the unprefixed line is blank, or would start a block of its own, the quote ends and the new block belongs to the document. Track one boolean while you collect the quote: "did the last quote line leave a paragraph open?"

A quote can also interrupt a paragraph: intro followed directly by > quote is a paragraph and then a quote, with no blank line needed.

Thematic breaks

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

LineResult
--- *** ___<hr />
- - - * * *<hr />, spaces are allowed between
-- **only two: plain paragraph text
+++ ===wrong characters entirely
--- directly under paragraph texta setext H2, not a break (see the setext lesson)

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. This exercise never puts --- right under paragraph text.

Common mistakes

  • One blockquote per line. Collect consecutive quote lines first; open and close the tags once.
  • Swallowing a break. > a then --- must give a quote and an <hr />, so a lazy line must not be a thematic break.
  • Unlimited laziness. An unprefixed line after a blank > line is not part of the quote.
  • Stripping more than one space after the >.

Your exercise

Write convert. The starter provides thematic, quote_content (the marker rule above) and paragraphs (the blank-line grouping from the paragraphs lesson), so you can concentrate on collecting the quote and deciding where it stops.

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…