Forem Creators and Builders 🌱

Discussion on: Code blocks with line numbers

Collapse
 
link2twenty profile image
Andrew Bone

Glad to see this request back. Here's the discussion we had a couple of years back.

Feature Request: Add the option to include line numbers in code blocks #1236

I currently enjoy the benefits of having syntax-highlighted code blocks in my articles or comments. It makes the code stand out from the rest of the text. However, there may be times when it is necessary to reference a line number in a code block for a clearer explanation of a particular line.

In that case, I open this issue to request for an option to add line numbers in code blocks. I believe this is possible with Jekyll? Knowing that Hofstadter's Law exists, I hope that it wouldn't be too hard to implement.

Perhaps line numbers can be globally enabled through the front matter?

---
title: Line numbers in code blocks are cool!
tags: meta
linenos: true
---
Enter fullscreen mode Exit fullscreen mode

Or perhaps it can be enabled inline with each code block?

---
title: Individual Code Block Activation
tags: meta
---

# Example of Unactivated Code Block
```javascript
console.log('I have no line numbers... 😟');
```

# Example of Inline Activation
```javascript linenos
console.log('I have inline line numbers! Yay! 🎉');
```
Enter fullscreen mode Exit fullscreen mode

Perhaps it could even be globally enabled by default?

Anyway, that's pretty much this entire feature request. Looking forward to the day this becomes possible! Thanks for reading!

Collapse
 
luvejo profile image
Luis Velásquez

I'm glad it wasn't just me. Thanks for bring it up, Andrew!