File tree Expand file tree Collapse file tree 1 file changed +12
-19
lines changed Expand file tree Collapse file tree 1 file changed +12
-19
lines changed Original file line number Diff line number Diff line change 1
- ( function ( ) {
2
- var i , text , code , codes = document . getElementsByTagName ( 'code' ) ;
3
- for ( i = 0 ; i < codes . length ; ) {
4
- code = codes [ i ] ;
5
- if ( code . parentNode . tagName !== 'PRE' && code . childElementCount === 0 ) {
6
- text = code . textContent ;
7
- if ( / ^ \$ [ ^ $ ] / . test ( text ) && / [ ^ $ ] \$ $ / . test ( text ) ) {
8
- text = text . replace ( / ^ \$ / , '\\(' ) . replace ( / \$ $ / , '\\)' ) ;
9
- code . textContent = text ;
10
- }
11
- if ( / ^ \\ \( ( .| \s ) + \\ \) $ / . test ( text ) || / ^ \\ \[ ( .| \s ) + \\ \] $ / . test ( text ) ||
12
- / ^ \$ ( .| \s ) + \$ $ / . test ( text ) ||
13
- / ^ \\ b e g i n \{ ( [ ^ } ] + ) \} ( .| \s ) + \\ e n d \{ [ ^ } ] + \} $ / . test ( text ) ) {
14
- code . outerHTML = code . innerHTML ; // remove <code></code>
15
- continue ;
16
- }
17
- }
18
- i ++ ;
1
+ [ ...document . getElementsByTagName ( 'code' ) ] . forEach ( code => {
2
+ if ( code . parentNode . tagName === 'PRE' || code . childElementCount > 0 ) return ;
3
+ const text = code . textContent ;
4
+ if ( / ^ \$ [ ^ $ ] / . test ( text ) && / [ ^ $ ] \$ $ / . test ( text ) ) {
5
+ text = text . replace ( / ^ \$ / , '\\(' ) . replace ( / \$ $ / , '\\)' ) ;
6
+ code . textContent = text ;
19
7
}
20
- } ) ( ) ;
8
+ if ( / ^ \\ \( ( .| \s ) + \\ \) $ / . test ( text ) || / ^ \\ \[ ( .| \s ) + \\ \] $ / . test ( text ) ||
9
+ / ^ \$ ( .| \s ) + \$ $ / . test ( text ) ||
10
+ / ^ \\ b e g i n \{ ( [ ^ } ] + ) \} ( .| \s ) + \\ e n d \{ [ ^ } ] + \} $ / . test ( text ) ) {
11
+ code . outerHTML = code . innerHTML ; // remove <code></code>
12
+ }
13
+ } ) ;
You can’t perform that action at this time.
0 commit comments