forked from Automattic/syntaxhighlighter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
syntaxhighlighter_mce-4.js
23 lines (20 loc) · 963 Bytes
/
syntaxhighlighter_mce-4.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/*
* SyntaxHighlighter shortcode plugin
* by Andrew Ozz of Automattic
*/
tinymce.PluginManager.add( 'syntaxhighlighter', function( editor ) {
editor.on( 'BeforeSetContent', function( event ) {
var shortcodes = window.syntaxHLcodes || 'sourcecode',
regex = new RegExp( '(?:<p>\\s*)?(?:<pre>\\s*)?(\\[(' + shortcodes + ')[^\\]]*\\][\\s\\S]*?\\[\\/\\2\\])(?:\\s*<\\/pre>)?(?:\\s*<\\/p>)?', 'gi' );
if ( event.content && event.content.indexOf( '[' ) !== -1 ) {
event.content = event.content.replace( regex, function( match, shortcode ) {
shortcode = shortcode.replace( /\r/, '' );
shortcode = shortcode.replace( /<br ?\/?>\n?/g, '\n' ).replace( /<\/?p( [^>]*)?>\n?/g, '\n' );
if ( ! event.initial || ( window.syntaxHLescape && window.syntaxHLescape[ editor.id ] ) ) {
shortcode = shortcode.replace( /&/g, '&' ).replace( /</g, '<' ).replace( />/g, '>' );
}
return '<pre>' + shortcode + '</pre>';
});
}
});
});