Skip to content

Commit e5ecc36

Browse files
committed
Updated editor JavaScript for WordPress 4.3. Props Andrew Ozz (@azaozz). Bump version to 3.1.12.
1 parent 01a19a9 commit e5ecc36

File tree

4 files changed

+45
-28
lines changed

4 files changed

+45
-28
lines changed

readme.txt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Contributors: Viper007Bond, automattic
33
Donate link: http://www.viper007bond.com/wordpress-plugins/syntaxhighlighter/donate/
44
Tags: code, sourcecode, php, xhtml, html, css, WordPress.com
55
Requires at least: 2.7
6-
Tested up to: 4.2
6+
Tested up to: 4.3
77
Stable tag: trunk
88

99
Easily post syntax-highlighted code to your site without having to modify the code at all. As seen on WordPress.com.
@@ -55,6 +55,10 @@ Make sure your theme's `footer.php` file has `<?php wp_footer(); ?>` somewhere i
5555

5656
== ChangeLog ==
5757

58+
= Version 3.1.12 =
59+
60+
* Updated editor JavaScript for WordPress 4.3. Props Andrew Ozz (@azaozz).
61+
5862
= Version 3.1.11 =
5963

6064
* SyntaxHighlighter 3.x: Fix table layout issue. Props jeherve.
@@ -242,9 +246,4 @@ Localizations:
242246

243247
= Version 1.0.0 =
244248

245-
* Initial release!
246-
247-
== Upgrade Notice ==
248-
249-
= 3.1.10 =
250-
Important security update.
249+
* Initial release!

syntaxhighlighter.js

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,31 @@
11
( function($) {
2-
var shortcodes = window.syntaxHLcodes || 'sourcecode';
2+
var shortcodes = window.syntaxHLcodes || 'sourcecode',
3+
regex = new RegExp( '(?:<pre>\\s*)?(\\[(' + shortcodes + ')[^\\]]*\\][\\s\\S]*?\\[\\/\\2\\])(?:\\s*<\\/pre>)?', 'gi' );
4+
5+
window.syntaxHLescape = {};
36

47
if ( typeof $ === 'undefined' ) {
58
return;
69
}
710

8-
$(document).on( 'afterPreWpautop.syntaxhighlighter', function( event, obj ) {
9-
obj.data = obj.data.replace( new RegExp( '(?:<pre>\\s*)?(\\[(' + shortcodes + ')[^\\]]*\\][\\s\\S]*?\\[\\/\\2\\])(?:\\s*<\\/pre>)?', 'gi' ),
10-
function( match, shortcode ) {
11-
return '\n' + shortcode.replace( /&lt;/g, '<' ).replace( /&gt;/g, '>' ).replace( /&amp;/g, '&' ) + '\n';
12-
}
13-
);
11+
$( document ).on( 'afterPreWpautop.syntaxhighlighter', function( event, obj ) {
12+
if ( obj.data && obj.data.indexOf( '[' ) !== -1 ) {
13+
obj.data = obj.data.replace( regex, function( match, shortcode ) {
14+
return '\n' + shortcode.replace( /&lt;/g, '<' ).replace( /&gt;/g, '>' ).replace( /&amp;/g, '&' ) + '\n';
15+
}
16+
);
17+
}
1418
}).on( 'beforeWpautop.syntaxhighlighter', function( event, obj ) {
15-
obj.data = obj.data.replace( new RegExp( '\\[(' + shortcodes + ')[^\\]]*\\][\\s\\S]+?\\[\\/\\1\\]', 'gi' ),
16-
function( match ) {
17-
return '<pre>' + match.replace( /&/g, '&amp;' ).replace( /</g, '&lt;' ).replace( />/g, '&gt;' ) + '</pre>';
19+
if ( obj.data && obj.data.indexOf( '[' ) !== -1 ) {
20+
obj.data = obj.data.replace( regex, '<pre>$1</pre>' );
21+
}
22+
}).ready( function() {
23+
$( '.wp-editor-wrap.html-active' ).each( function( i, element ) {
24+
var id = $( element ).find( 'textarea.wp-editor-area' ).attr( 'id' );
25+
26+
if ( id ) {
27+
window.syntaxHLescape[id] = true;
1828
}
19-
);
29+
});
2030
});
21-
}( window.jQuery ));
31+
}( window.jQuery ));

syntaxhighlighter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
Plugin Name: SyntaxHighlighter Evolved
66
Plugin URI: http://www.viper007bond.com/wordpress-plugins/syntaxhighlighter/
7-
Version: 3.1.11
7+
Version: 3.1.12
88
Description: Easily post syntax-highlighted code to your site without having to modify the code at all. Uses Alex Gorbatchev's <a href="http://alexgorbatchev.com/wiki/SyntaxHighlighter">SyntaxHighlighter</a>. <strong>TIP:</strong> Don't use the Visual editor if you don't want your code mangled. TinyMCE will "clean up" your HTML.
99
Author: Alex Mills (Viper007Bond)
1010
Author URI: http://www.viper007bond.com/
@@ -21,7 +21,7 @@
2121

2222
class SyntaxHighlighter {
2323
// All of these variables are private. Filters are provided for things that can be modified.
24-
var $pluginver = '3.1.11'; // Plugin version
24+
var $pluginver = '3.1.12'; // Plugin version
2525
var $agshver = false; // Alex Gorbatchev's SyntaxHighlighter version (dynamically set below due to v2 vs v3)
2626
var $shfolder = false; // Controls what subfolder to load SyntaxHighlighter from (v2 or v3)
2727
var $settings = array(); // Contains the user's settings

syntaxhighlighter_mce-4.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,20 @@
44
*/
55
tinymce.PluginManager.add( 'syntaxhighlighter', function( editor ) {
66
editor.on( 'BeforeSetContent', function( event ) {
7-
var shortcodes = window.syntaxHLcodes || 'sourcecode';
7+
var shortcodes = window.syntaxHLcodes || 'sourcecode',
8+
regex = new RegExp( '(?:<p>\\s*)?(?:<pre>\\s*)?(\\[(' + shortcodes + ')[^\\]]*\\][\\s\\S]*?\\[\\/\\2\\])(?:\\s*<\\/pre>)?(?:\\s*<\\/p>)?', 'gi' );
89

9-
event.content = event.content.replace( new RegExp( '(?:<p>\\s*)?(?:<pre>\\s*)?(\\[(' + shortcodes + ')[^\\]]*\\][\\s\\S]*?\\[\\/\\2\\])(?:\\s*<\\/pre>)?(?:\\s*<\\/p>)?', 'gi'),
10-
function( match, shortcode ) {
11-
return '<pre>' + shortcode.replace( /<br ?\/?>[\r\n]*/g, '<br />' ).replace( /<\/?p( [^>]*)?>[\r\n]*/g, '<br />' ) + '</pre>';
12-
}
13-
);
10+
if ( event.content && event.content.indexOf( '[' ) !== -1 ) {
11+
event.content = event.content.replace( regex, function( match, shortcode ) {
12+
shortcode = shortcode.replace( /\r/, '' );
13+
shortcode = shortcode.replace( /<br ?\/?>\n?/g, '\n' ).replace( /<\/?p( [^>]*)?>\n?/g, '\n' );
14+
15+
if ( ! event.initial || ( window.syntaxHLescape && window.syntaxHLescape[ editor.id ] ) ) {
16+
shortcode = shortcode.replace( /&/g, '&amp;' ).replace( /</g, '&lt;' ).replace( />/g, '&gt;' );
17+
}
18+
19+
return '<pre>' + shortcode + '</pre>';
20+
});
21+
}
1422
});
15-
});
23+
});

0 commit comments

Comments
 (0)