Forum Moderators: open

Message Too Old, No Replies

<pre> tags and line numbers

dynamically add line-numbers to <pre> tags

         

ucbones

6:25 pm on Aug 15, 2004 (gmt 0)

10+ Year Member



Hi,

Not quite sure how this would work at all, but I'm wondering if anyone knows of a way to dynamically add line-numbers to <pre> tags, a quick google revealed nothing.

Many thanks,

ucbones

bedlam

7:22 pm on Aug 15, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hiya,

This isn't a javascript solution, but would it be possible for you to use the correct tag (<ol>) for numbered lists and then use CSS to style it as preformatted text? Something like this:

CSS:

.preformatted {
white-space:pre;
}

HTML:

<ol class="preformatted">
<li>First item</li>
<li>Second item</li>
<li>Third item</li>
</ol>

You may also need to adjust margins/padding etc on the <ol>.

Alternatively, it's valid html to put <pre> tags inside list-items (<li>), so you could try this instead:

<ol>
<li><pre>Some stuff...</pre></li>
</ol>

Sorry if I've misunderstood the problem and these won't work (i.e. because you don't know the contents of the <pre> tag in advance etc)! But even if you do use a scripting solution, you may still want to make use of the <ol> tag for the numbering.

-B

[edited by: DrDoc at 6:23 pm (utc) on Aug. 16, 2004]
[edit reason] tidying up [/edit]