in reply to Add line numbers to HTML

Please clarify: You want to put line numbers at the start of each line of the HTML file, or you want to put line numbers at the start of each line displayed in the browser?

If you're putting line numbers at the start of each line of the HTML file, it's a Perl 1-liner kind of thing:

perl -pi.bak -e "$_ = qq/$.: $_/;"

But that will break HTML where tags span lines. And it will look pretty confusing when rendered in the browser since logical file newlines don't equate to browser-rendered newlines.

On the other hand, if you want every line rendered in the browser to display a line number, you've got a bit of a problem, as HTML output is generally formatted into paragraphs, not lines. Unless you're using <pre> tags, how are you going to determine where new lines begin in someone's browser? Regular HTML text auto-wraps in normal browsers.


Dave

Replies are listed 'Best First'.
Re: Re: Add line numbers to HTML
by Anonymous Monk on Mar 20, 2004 at 06:38 UTC
    I should have been more clear. I would like the line numbers to appear at the begining of each line as viewed in the browser. I am starting to think that this is going to be impossible... ~Jason
      Unless you can assure that lines don't wrap, you can't do that. However, <pre> tags are able to prevent wrapping; they preformat the text to your specifications, regardless of browser window size. That has a BIG disadvantage though. Consider someone using a screen smaller than the one for which your document was designed. The benefit of line numbering will be outweighed by the pain in the rear of having to horizontally scroll to read each line.

      Nevertheless, you do see it done sometimes. See our own Craft section as an example of using <pre> tags, tables, etc., to create a formatting that is condusive to line numbering.


      Dave

        All points that I have also thought of, dang... Basically this was supposed to make reviewing these documents easier for big groups. Any other ideas or different approaches?