how do you add numbered lines to code examples and also giving a printing and view plain text options like in the code examples in the following link below:
http://www.sitepoint.com/blogs/2009/06/02/css-sizing-absolute-position/
how do you add numbered lines to code examples and also giving a printing and view plain text options like in the code examples in the following link below:
http://www.sitepoint.com/blogs/2009/06/02/css-sizing-absolute-position/
the sitepoint article you give as an example uses javascript to create tables and then styles them with css.
this is imho a poor choice. it's putting non-tabular information into tables.
You could accomplish the same thing though using divs and spans
I looked at the source of the site you linked to. They are using Wordpress as their blogging software. There's a Wordpress plug-in that lets you do that. I use it at Dreaming In JavaScript. Looks like they're using the same one I am.
If you want to simply apply line-numbers to code, you can roll out a simple script like:
#!/usr/bin/perl
use strict;
use warnings;
my $file = $ARGV[0];
unless ( -f $file ) {
print "File name has to be provided.\n";
exit;
}
open my $fh, '+<', $file or die $!;
my @lines = <$fh>;
seek $fh, 0, 0;
my $line_number = 0;
for (@lines) {
print $fh $line_number++, ": ", $_;
}
Just pass the file to be line-numbered as the first argument. Always keep a backup of the original file.
Personally, I'd prefer that you didn't add line numbers. They usually add nothing useful, and they make it more difficult to copy and paste the code.
If you're posting a really long snippet and referring to line numbers in your text, it might be better to break it up into chunks.
Something to consider, anyway.