Export to GitHub

syntaxhighlighter - issue #92

Adding anchors to line numbers


Posted on Jul 24, 2008 by Happy Camel

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] + '&amp;nbsp;';

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

Comment #1

Posted on Jul 24, 2008 by Happy Camel

The anchors generated by that patch are in the for , , etc.

Links to these anchors can be made like: line 0

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 instead. Consideration would have to be made when there are more than one function / method / class with the same name.

Rob

Status: New

Labels:
Type-Defect Priority-Medium