Skip to content

Commit 5ae95f7

Browse files
committed
add line numbers after highlighting rather than monkey patching
1 parent 6b1ecd6 commit 5ae95f7

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

root/static/js/syntaxhighlighter.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,6 @@ $(function () {
5757
return processPackages(html);
5858
};
5959

60-
var getLineNumbersHtml = SyntaxHighlighter.Highlighter.prototype.getLineNumbersHtml;
61-
SyntaxHighlighter.Highlighter.prototype.getLineNumbersHtml = function() {
62-
var html = getLineNumbersHtml.apply(this, arguments);
63-
html = html.replace(/(<div[^>]*>\s*)(\d+)(\s*<\/div>)/g, '$1<a href="#L$2" id="L$2">$2</a>$3');
64-
return html;
65-
};
66-
6760

6861
var source = $("#source");
6962
if (source.length) {
@@ -153,6 +146,14 @@ $(function () {
153146
).join(', ');
154147
pre.find('.syntaxhighlighter .line').filter(selector).addClass('pod-line');
155148
}
149+
150+
pre.find('.syntaxhighlighter .gutter .line').each(function(i, el) {
151+
var res;
152+
if (res = el.className.match(/(^|\s)number(\d+)(\s|$)/)) {
153+
var id = 'L' + res[2];
154+
$(el).contents().wrap('<a href="#'+id+'" id="'+id+'"></a>');
155+
}
156+
});
156157
});
157158
});
158159

0 commit comments

Comments
 (0)