Line numbers (for files)
Freso - February 27, 2008 - 13:10
| Project: | API |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs work |
Description
When viewing files on api.drupal.org, it would sometimes be beneficial to have the line numbers by the left margin, for comparing with diff's, error messages, or general code orientation. (If the source code of functions etc. could have line number from their parent file as well, that would be awesome, but would probably also require some more coding.)

#1
I agree. I will give a shot at implementing that if I have some free time this week.
#2
Bump...
I've strongly agree with this request. It'd be very useful (to me and presumably others) in finding the correct lines.
#3
Here's a patch.
It modifies the parser that builds the code index by sticking in a (line) number after each line break (PHP_EOL). I've wrapped the method in a function so it's less intrusion and wrapped the line number format in a function to more easily modify how we'd like to format the line number. I'm not sure if we have to go as far as registering the line number format function in the theme registry though.. =P
The drawback is that the line numbers are embedded into the code. Is that tolerable?
Most of the other online sites that post code snippets use ordered lists to put in line numbers. Their drawback is that the code is actually broken up into separate lines. Styles that span across multiple lines are closed at the end of each line and reopened at the start of the next line.
I can look at how to put a list of line numbers to the left of the code. Maybe float them in an HTML element to the left of the code element. Maybe something else. Suggestions?
#4
Copy/paste definitely needs to work. An ordered list won't work since we will rarely start at line 1. And this should not be mixed into the code in the database, it should be rendered on output.