Perl isn't... FORTRAN. Still, it's often handy to be able to see (and talk about) line numbers in code listings. Editors and pastebins do this; why not PerlMonks?
It turns out that a slightly obscure feature lets us do just that. Follow these instructions and you will see line numbers alongside every block of code here. (This will not affect inline code.)
First navigate to Display Settings. We will make a few changes here.
In the Code Listing Section, be sure Code Wrapping Off is not checked.
For Code Prefix, enter: <span class="line-number">&1;</span>
Line numbers will mess you up if you like to copy code right out of node text; instead, use the several [download] links provided. Be sure Don't show embedded d/l links is not checked and Show download link on code N lines long or more is set to a very small number, or left blank.
To style the new line-number class, we need to fix the stylesheet. We can paste the following into On-Site CSS Markup:
.codeblock { margin-left: 1em; background-color: #ddf; } .line-number { color: #779; background-color: #fdd; }
That's it; we're done. You may want to experiment with the color balance but that's... up to you.
roboticus took pity on me whining in CB and pointed me to New code wrap options.
Corion made a good notice which unfortunately did not pan out.
Honorable mention goes to other six a.m. CBers who put up with the fumbling.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Line Numbering in Code Listings
by cavac (Prior) on Dec 10, 2011 at 17:33 UTC | |
|
Re: Line Numbering in Code Listings
by Khen1950fx (Canon) on Dec 10, 2011 at 21:48 UTC |