@@ -4,10 +4,10 @@ $(function () {
4
4
var all_lines = [ ] ;
5
5
for ( var i = 0 ; i < lines . length ; i ++ ) {
6
6
var line = lines [ i ] ;
7
- var res = line . match ( / ^ \s * ( \d + ) \s * ( - \s * ( \d + ) \s * ) ? $ / ) ;
7
+ var res = line . match ( / ^ \s * ( \d + ) \s * (?: - \s * ( \d + ) \s * ) ? $ / ) ;
8
8
if ( res ) {
9
9
var start = res [ 1 ] * 1 ;
10
- var end = ( res [ 3 ] || res [ 1 ] ) * 1 ;
10
+ var end = ( res [ 2 ] || res [ 1 ] ) * 1 ;
11
11
for ( var l = start ; l <= end ; l ++ ) {
12
12
all_lines . push ( l ) ;
13
13
}
@@ -16,6 +16,14 @@ $(function () {
16
16
return all_lines ;
17
17
}
18
18
19
+ function findLines ( el , lines ) {
20
+ var selector = $ . map (
21
+ parseLines ( lines ) ,
22
+ function ( i , line ) { return '.number' + line }
23
+ ) . join ( ', ' ) ;
24
+ return el . find ( '.syntaxhighlighter .line' ) . filter ( selector ) ;
25
+ }
26
+
19
27
var hashLines = / ^ # L ( \d + (?: - \d + ) ? (?: , \d + (?: - \d + ) ? ) * ) $ / ;
20
28
21
29
// Allow tilde in url (#1118). Orig: /\w+:\/\/[\w-.\/?%&=:@;#]*/g,
@@ -92,36 +100,27 @@ $(function () {
92
100
}
93
101
94
102
/* set perl as the default type in pod */
95
- $ ( ".pod pre > code" ) . each ( function ( index , source ) {
103
+ $ ( ".pod pre > code" ) . each ( function ( index , code ) {
96
104
var have_lang ;
97
- if ( source . className ) {
98
- var classes = source . className . split ( / \s + / ) ;
99
- for ( var i = 0 ; i < classes . length ; i ++ ) {
100
- if ( classes [ i ] . match ( / ^ l a n g u a g e - ( .* ) / ) ) {
101
- return ;
102
- }
103
- }
105
+ if ( code . className && code . className . match ( / (?: \s | ^ ) l a n g u a g e - \S + / ) ) {
106
+ return ;
104
107
}
105
- source . className = 'language-perl' ;
108
+ $ ( code ) . addClass ( 'language-perl' ) ;
106
109
} ) ;
107
110
108
- $ ( ".content pre > code" ) . each ( function ( index , source ) {
109
- var code = $ ( source ) ;
110
- var pre = code . parent ( ) ;
111
+ $ ( ".content pre > code" ) . each ( function ( index , code ) {
112
+ var pre = $ ( code ) . parent ( ) ;
111
113
112
114
var config = {
113
115
'gutter' : false ,
114
116
'toolbar' : false ,
115
117
'quick-code' : false ,
116
118
'tab-size' : 8
117
119
} ;
118
- if ( source . className ) {
119
- var classes = source . className . split ( / \s + / ) ;
120
- for ( var i = 0 ; i < classes . length ; i ++ ) {
121
- var res = classes [ i ] . match ( / ^ l a n g u a g e - ( .* ) / ) ;
122
- if ( res ) {
123
- config . brush = res [ 1 ] ;
124
- }
120
+ if ( code . className ) {
121
+ var res = code . className . match ( / (?: \s | ^ ) l a n g u a g e - ( \S + ) / ) ) {
122
+ if ( res ) {
123
+ config . brush = res [ 1 ] ;
125
124
}
126
125
}
127
126
if ( ! config . brush ) {
@@ -140,15 +139,11 @@ $(function () {
140
139
config . highlight = parseLines ( lines ) ;
141
140
}
142
141
143
- SyntaxHighlighter . highlight ( config , source ) ;
142
+ SyntaxHighlighter . highlight ( config , code ) ;
144
143
145
144
var pod_lines = pre . attr ( 'data-pod-lines' ) ;
146
145
if ( pod_lines ) {
147
- var selector = $ . map (
148
- parseLines ( pod_lines ) ,
149
- function ( e , i ) { return '.number' + e }
150
- ) . join ( ', ' ) ;
151
- pre . find ( '.syntaxhighlighter .line' ) . filter ( selector ) . addClass ( 'pod-line' ) ;
146
+ findLines ( pre , pod_lines ) . addClass ( 'pod-line' ) ;
152
147
}
153
148
} ) ;
154
149
@@ -180,12 +175,8 @@ $(function () {
180
175
var lineMatch ;
181
176
if ( lineMatch = document . location . hash . match ( hashLines ) ) {
182
177
source . attr ( 'data-line' , lineMatch [ 1 ] ) ;
183
- var selector = $ . map (
184
- parseLines ( lineMatch [ 1 ] ) ,
185
- function ( e , i ) { return '.number' + e }
186
- ) . join ( ', ' ) ;
187
178
source . find ( '.highlighted' ) . removeClass ( 'highlighted' ) ;
188
- source . find ( '.syntaxhighlighter .line' ) . filter ( selector ) . addClass ( 'highlighted' ) ;
179
+ findLines ( source , lineMatch [ 1 ] ) . addClass ( 'highlighted' ) ;
189
180
}
190
181
} ) ;
191
182
}
0 commit comments