The Art of Nested Code Fencing in Markdown
susam.net·3d·
Code Formatters
Preview
Report Post

By Susam Pal on 19 Jan 2026

In case you didn’t know, it is easy to nest code block delimiters in CommonMark. Since GitHub Flavoured Markdown (GFM) is a strict superset of CommonMark, whatever we discuss in this post applies equally well to both CommonMark and GFM.

Why would we ever need to nest code block delimiters within a pair of code block delimiters? Let us start with a simple example.

Contents

Basic Code Fences

Say we are writing a README.md where we want to teach how to write Markdown. Naturally, we would write the Markdown examples within fenced code blocks so that…

Similar Posts

Loading similar posts...

Keyboard Shortcuts

Navigation
Next / previous item
j/k
Open post
oorEnter
Preview post
v
Post Actions
Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Recommendations
Add interest / feed
Enter
Not interested
x
Go to
Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Browse
gb
Search
/
General
Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help