livebs / syntaxhighlighter

Automatically exported from code.google.com/p/syntaxhighlighter
GNU General Public License v3.0
0 stars 0 forks source link

Adding anchors to line numbers #92

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What will this patch solve?
1. I wanted to be able to create links to line numbers so that I could have
a list of method names and clicking on them would take you to the line
number where it is defined.

What version of the product are you using? On what operating system?
1.5.1 FF3

Please provide any additional information below.
add the lines prefixed by ++ to the function
dp.sh.Highlighter.prototype.SwitchToList (around line 422)

for(var i = 0, lineIndex = this.firstLine; i < lines.length - 1; i++,
lineIndex++)
    {
        var li = this.CreateElement('LI');
              ++var a = this.CreateElement('A');
          ++a.setAttribute('name', 'line'+(i+1));
        var span = this.CreateElement('SPAN');

        // uses .line1 and .line2 css styles for alternating lines
        li.className = (i % 2 == 0) ? 'alt' : '';
        span.innerHTML = lines[i] + '&nbsp;';

          ++li.appendChild(a);
        li.appendChild(span);
        this.ol.appendChild(li);
    }

Original issue reported on code.google.com by rni...@gmail.com on 24 Jul 2008 at 2:51

GoogleCodeExporter commented 8 years ago
The anchors generated by that patch are in the for <a name="line0" />, <a
name="line1" />, <a name="line2" /> etc. 

Links to these anchors can be made like: <a href="#line0"> line 0 </a>

I would be cool however if this could be modified so that anchors are generated 
for
class, function, method names and are in the form of <a name="foo" /> instead.
Consideration would have to be made when there are more than one function / 
method /
class with the same name.

Rob

Original comment by rni...@gmail.com on 24 Jul 2008 at 2:59