I want my code blocks on the blog to sometimes have line numbers.
Looking at the Hugo docs here and here led me to the linenos argument.

While we’d start our code blocks like (```python)1, all I need more is to add the line number argument like so.

Vanilla code block …

print(f"""
	“It’s silly to try to escape other people’s faults. 
	They are inescapable. Just try to escape your own.”
	— Marcus Aurelius
	""")

print(f"""
	“Just that you do the right thing. 
	The rest doesn’t matter.” 
	– Marcus Aurelius
	""")

Now, using the linenos option, I can be all fancy to show …

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
print(f"""
	“It’s silly to try to escape other people’s faults. 
	They are inescapable. Just try to escape your own.”
	— Marcus Aurelius
	""")

print(f"""
	“Just that you do the right thing. 
	The rest doesn’t matter.” 
	– Marcus Aurelius
	""")

All I did was, start my code block with a ( ```python {linenos=true} )2

Hurrah!

P.S. Subscribe to my mailing list!
Forward these posts and letters to your friends and get them to subscribe!
P.P.S. Feed my insatiable reading habit.


  1. don’t type the round brackets, they’re just there, so I can see/show what I am doing. ↩︎

  2. once again, ignore the round brackets ↩︎