forked from Automattic/syntaxhighlighter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsyntaxhighlighter.js
31 lines (27 loc) · 1.02 KB
/
syntaxhighlighter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
( function($) {
var shortcodes = window.syntaxHLcodes || 'sourcecode',
regex = new RegExp( '(?:<pre>\\s*)?(\\[(' + shortcodes + ')[^\\]]*\\][\\s\\S]*?\\[\\/\\2\\])(?:\\s*<\\/pre>)?', 'gi' );
window.syntaxHLescape = {};
if ( typeof $ === 'undefined' ) {
return;
}
$( document ).on( 'afterPreWpautop.syntaxhighlighter', function( event, obj ) {
if ( obj.data && obj.data.indexOf( '[' ) !== -1 ) {
obj.data = obj.data.replace( regex, function( match, shortcode ) {
return '\n' + shortcode.replace( /</g, '<' ).replace( />/g, '>' ).replace( /&/g, '&' ) + '\n';
}
);
}
}).on( 'beforeWpautop.syntaxhighlighter', function( event, obj ) {
if ( obj.data && obj.data.indexOf( '[' ) !== -1 ) {
obj.data = obj.data.replace( regex, '<pre>$1</pre>' );
}
}).ready( function() {
$( '.wp-editor-wrap.html-active' ).each( function( i, element ) {
var id = $( element ).find( 'textarea.wp-editor-area' ).attr( 'id' );
if ( id ) {
window.syntaxHLescape[id] = true;
}
});
});
}( window.jQuery ));