Nested Code Fences in Markdown

https://news.ycombinator.com/rss Hits: 2
Summary

Nested Code Fences in Markdown By Susam Pal on 19 Jan 2026 Today, we will meet a spiky-haired nerd named Corey Dumm, who normally lives within Markdown code fences. We will get to know him a bit, smile with him when his fences hold and weep quietly when misfortune strikes. One of the caveats of the Markdown universe is the wide variety of Markdown implementations available. In these parallel universes, the rules of Markdown rendering differ subtly. In this post, we will focus only on the CommonMark specification. Since GitHub Flavoured Markdown (GFM) is a strict superset of CommonMark, whatever we discuss here applies equally well to both CommonMark and GFM. Contents Basic Code Fences Corey had a knack for working with computers ever since he was a kid. Corey at his computer: ``` (o_o)--.|[_]| ``` Everything was perfect in Corey's world. The CommonMark renderer would convert the Markdown above to the following HTML: Corey at his computer: (o_o)--.|[_]| View HTML <p>Corey at his computer:</p> <pre><code>(o_o)--.|[_]| </code></pre> At this point, all was well. Corey grew quickly. Before long, he had a head full of spiky hair. Then the fences began to matter. Corey, all grown up: ``` ``` (o_o)--.|[_]| ``` Let us see how this renders. I must warn you that during the Markdown-to-HTML translation, Corey loses his hair. Some viewers may find the following scene disturbing. Viewer discretion is advised. Here is the rendered HTML: Corey, all grown up: (o_o)--.|[_]| View HTML <p>Corey, all grown up:</p> <pre><code></code></pre> <p>(o_o)--.|[_]|</p> <pre><code></code></pre> Corey's hair is gone! What a catastrophic accident! Corey is alright, though. He is still quite afraid of Markdown fences, but otherwise well and bouncing back. Why did this happen? The second set of triple backticks immediately ends the fenced code block started by the first set of triple backticks. As a result, Corey's smiley face ends up outside the fenced code block. The triple backticks that were once ...

First seen: 2026-01-21 14:40

Last seen: 2026-01-21 15:40