Skip to content

Commit 5de36e0

Browse files
committed
move duplicate regex into variable
1 parent c1566d8 commit 5de36e0

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

root/static/js/syntaxhighlighter.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ $(function () {
1616
return all_lines;
1717
}
1818

19+
var hashLines = /^#L(\d+(?:-\d+)?(?:,\d+(?:-\d+)?)*)$/;
20+
1921
// Allow tilde in url (#1118). Orig: /\w+:\/\/[\w-.\/?%&=:@;#]*/g,
2022
SyntaxHighlighter.regexLib['url'] = /\w+:\/\/[\w-.\/?%&=:@;#~]*/g;
2123

@@ -66,7 +68,7 @@ $(function () {
6668
if (source.html().length > 500000) {
6769
source.children('code').removeClass();
6870
}
69-
else if ( lineMatch = document.location.hash.match(/^#L(\d+(-\d+)?(,\d+(-\d+)?)*)$/) ) {
71+
else if ( lineMatch = document.location.hash.match(hashLines) ) {
7072
source.attr('data-line', lineMatch[1]);
7173
}
7274
// check for 'P{encoded_package_name}' anchor, convert to
@@ -175,7 +177,7 @@ $(function () {
175177

176178
$(window).on('hashchange', function() {
177179
var lineMatch;
178-
if (lineMatch = document.location.hash.match(/^#L(\d+(-\d+)?(,\d+(-\d+)?)*)$/) ) {
180+
if (lineMatch = document.location.hash.match(hashLines) ) {
179181
source.attr('data-line', lineMatch[1]);
180182
var selector = $.map(
181183
parseLines(lineMatch[1]),

0 commit comments

Comments
 (0)