SyntaxHighlighter Evolved - Version 3.5.5

Version Description

Download this release

Release Info

Developer renathoc
Plugin Icon wp plugin SyntaxHighlighter Evolved
Version 3.5.5
Comparing to
See all releases

Code changes from version 3.5.4 to 3.5.5

readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://alex.blog/2019/03/13/in-memory-of-alex-donation-link-update
4
  Tags: code, sourcecode, block, php, xhtml, html, css, WordPress.com
5
  Requires at least: 4.2.3
6
  Tested up to: 5.4
7
- Stable tag: 3.5.4
8
 
9
  Easily post syntax-highlighted code to your site without having to modify the code at all. As seen on WordPress.com.
10
 
@@ -40,6 +40,13 @@ Try excluding this plugin's Javascript from any performance optimizations your s
40
 
41
  == ChangeLog ==
42
 
 
 
 
 
 
 
 
43
  = Version 3.5.4 =
44
 
45
  * Add missing shBrushYaml file.
4
  Tags: code, sourcecode, block, php, xhtml, html, css, WordPress.com
5
  Requires at least: 4.2.3
6
  Tested up to: 5.4
7
+ Stable tag: 3.5.5
8
 
9
  Easily post syntax-highlighted code to your site without having to modify the code at all. As seen on WordPress.com.
10
 
40
 
41
  == ChangeLog ==
42
 
43
+ = Version 3.5.5 =
44
+
45
+ * Allow setting text to include br and code tags. #144
46
+ * Add Arduino Brush. #136
47
+ * Fix tags issue while alternating visual and text mode in the classic editor. #139
48
+ * Fix adding classname when using SyntaxHighlighter block. #138
49
+
50
  = Version 3.5.4 =
51
 
52
  * Add missing shBrushYaml file.
syntaxhighlighter.js CHANGED
@@ -1,5 +1,5 @@
1
- ( function($) {
2
- var shortcodes = window.syntaxHLcodes || 'sourcecode',
3
  regex = new RegExp( '(?:<pre>\\s*)?(\\[(' + shortcodes + ')[^\\]]*\\][\\s\\S]*?\\[\\/\\2\\])(?:\\s*<\\/pre>)?', 'gi' );
4
 
5
  window.syntaxHLescape = {};
@@ -8,24 +8,82 @@
8
  return;
9
  }
10
 
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
- }
18
- }).on( 'beforeWpautop.syntaxhighlighter', function( event, obj ) {
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;
28
  }
29
- });
30
- });
31
- }( window.jQuery ));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ( function( $ ) {
2
+ const shortcodes = window.syntaxHLcodes || 'sourcecode',
3
  regex = new RegExp( '(?:<pre>\\s*)?(\\[(' + shortcodes + ')[^\\]]*\\][\\s\\S]*?\\[\\/\\2\\])(?:\\s*<\\/pre>)?', 'gi' );
4
 
5
  window.syntaxHLescape = {};
8
  return;
9
  }
10
 
11
+ // Constants.
12
+ const $DOC = $( document );
13
+ const PRESERVE = 'PRESERVE';
14
+ const RESTORE = 'RESTORE';
15
+
16
+ // Tags that are removed by the core and their replacement to prevent being removed.
17
+ const tagsToPreserve = [
18
+ [ 'p', 'wp-p' ],
19
+ [ 'br', 'wp-br' ],
20
+ ];
21
+
22
+ function replaceTag( code, from, to ) {
23
+ const tagRegex = new RegExp( `<(\/?)${ from }([>\\s\/]+)`, 'gi' );
24
+ return code.replace( tagRegex, `<$1${ to }$2` );
25
+ }
26
+
27
+ function replaceTagsToPreserve( code, action ) {
28
+ const indexReplaced = action === PRESERVE ? 0 : 1;
29
+ const indexReplacement = action === PRESERVE ? 1 : 0;
30
+ let newCode = code;
31
+
32
+ tagsToPreserve.forEach( function( tags ) {
33
+ newCode = replaceTag( newCode, tags[ indexReplaced ], tags[ indexReplacement ] );
34
+ } );
35
+
36
+ return newCode;
37
+ }
38
+
39
+ function preserveTags( code ) {
40
+ return replaceTagsToPreserve( code, PRESERVE );
41
+ }
42
+
43
+ function restoreTags( code ) {
44
+ return replaceTagsToPreserve( code, RESTORE );
45
+ }
46
+
47
+ function unescapeTags( code ) {
48
+ return code.replace( /&lt;/g, '<' ).replace( /&gt;/g, '>' ).replace( /&amp;/g, '&' );
49
+ }
50
+
51
+ const events = {
52
+ afterPreWpautop: function( event, obj ) {
53
+ if ( obj.data && obj.data.indexOf( '[' ) === -1 ) {
54
+ return;
55
+ }
56
+
57
  obj.data = obj.data.replace( regex, function( match, shortcode ) {
58
+ return '\n' + restoreTags( unescapeTags( shortcode ) ) + '\n';
59
+ } );
60
+ },
61
+ afterWpautop: function( event, obj ) {
62
+ if ( obj.data && obj.data.indexOf( '[' ) === -1 ) {
63
+ return;
 
 
 
 
 
 
 
 
64
  }
65
+
66
+ const unfilteredCodes = obj.unfiltered.match( regex );
67
+ let i = 0;
68
+
69
+ obj.data = obj.data.replace( regex, function() {
70
+ // Replace by the unfiltered code piece.
71
+ const unfilteredCode = unfilteredCodes[ i++ ];
72
+ return `<pre>${ preserveTags( unfilteredCode ) }</pre>`;
73
+ } );
74
+ },
75
+ documentReady: function() {
76
+ $( '.wp-editor-wrap.html-active' ).each( function( i, element ) {
77
+ const id = $( element ).find( 'textarea.wp-editor-area' ).attr( 'id' );
78
+
79
+ if ( id ) {
80
+ window.syntaxHLescape[ id ] = true;
81
+ }
82
+ } );
83
+ },
84
+ };
85
+
86
+ $DOC.on( 'afterPreWpautop.syntaxhighlighter', events.afterPreWpautop );
87
+ $DOC.on( 'afterWpautop.syntaxhighlighter', events.afterWpautop );
88
+ $DOC.ready( events.documentReady );
89
+ }( window.jQuery ) );
syntaxhighlighter.php CHANGED
@@ -4,7 +4,7 @@
4
 
5
  Plugin Name: SyntaxHighlighter Evolved
6
  Plugin URI: https://alex.blog/wordpress-plugins/syntaxhighlighter/
7
- Version: 3.5.4
8
  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/SyntaxHighlighter/">SyntaxHighlighter</a>. Includes a new editor block.
9
  Author: Alex Mills (Viper007Bond)
10
  Author URI: https://alex.blog/
@@ -16,7 +16,7 @@ License URI: https://www.gnu.org/licenses/gpl-2.0.html
16
 
17
  class SyntaxHighlighter {
18
  // All of these variables are private. Filters are provided for things that can be modified.
19
- var $pluginver = '3.5.4'; // Plugin version
20
  var $agshver = false; // Alex Gorbatchev's SyntaxHighlighter version (dynamically set below due to v2 vs v3)
21
  var $shfolder = false; // Controls what subfolder to load SyntaxHighlighter from (v2 or v3)
22
  var $settings = array(); // Contains the user's settings
@@ -123,6 +123,7 @@ class SyntaxHighlighter {
123
  // Register brush scripts
124
  wp_register_script( 'syntaxhighlighter-core', plugins_url( $this->shfolder . '/scripts/shCore.js', __FILE__ ), array(), $this->agshver );
125
  wp_register_script( 'syntaxhighlighter-brush-as3', plugins_url( $this->shfolder . '/scripts/shBrushAS3.js', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
 
126
  wp_register_script( 'syntaxhighlighter-brush-bash', plugins_url( $this->shfolder . '/scripts/shBrushBash.js', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
127
  wp_register_script( 'syntaxhighlighter-brush-coldfusion', plugins_url( $this->shfolder . '/scripts/shBrushColdFusion.js', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
128
  wp_register_script( 'syntaxhighlighter-brush-cpp', plugins_url( $this->shfolder . '/scripts/shBrushCpp.js', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
@@ -172,6 +173,7 @@ class SyntaxHighlighter {
172
  $this->brushes = (array) apply_filters( 'syntaxhighlighter_brushes', array(
173
  'as3' => 'as3',
174
  'actionscript3' => 'as3',
 
175
  'bash' => 'bash',
176
  'shell' => 'bash',
177
  'coldfusion' => 'coldfusion',
@@ -232,6 +234,7 @@ class SyntaxHighlighter {
232
 
233
  $this->brush_names = (array) apply_filters( 'syntaxhighlighter_brush_names', array(
234
  'as3' => __( 'ActionScript', 'syntaxhighlighter' ),
 
235
  'bash' => __( 'BASH / Shell', 'syntaxhighlighter' ),
236
  'coldfusion' => __( 'ColdFusion', 'syntaxhighlighter' ),
237
  'clojure' => __( 'Clojure', 'syntaxhighlighter' ),
@@ -500,6 +503,7 @@ class SyntaxHighlighter {
500
  */
501
  public function render_block( $attributes, $content ) {
502
  $remaps = array(
 
503
  'lineNumbers' => 'gutter',
504
  'firstLineNumber' => 'firstline',
505
  'highlightLines' => 'highlight',
@@ -1243,7 +1247,7 @@ class SyntaxHighlighter {
1243
 
1244
  // Sanitize the "classname" parameter
1245
  if ( 'class-name' == $key )
1246
- $value = trim( preg_replace( '/[^a-zA-Z0-9 _-]/i', '', $value ) );
1247
 
1248
  // Special sanitization for "pad-line-numbers"
1249
  if ( 'pad-line-numbers' == $key ) {
@@ -1384,7 +1388,7 @@ class SyntaxHighlighter {
1384
  <td>
1385
  <fieldset>
1386
  <legend class="hidden"><?php esc_html_e( 'Load All Brushes', 'syntaxhighlighter' ); ?></legend>
1387
- <label for="syntaxhighlighter-loadallbrushes"><input name="syntaxhighlighter_settings[loadallbrushes]" type="checkbox" id="syntaxhighlighter-loadallbrushes" value="1" <?php checked( $this->settings['loadallbrushes'], 1 ); ?> /> <?php esc_html_e( 'Always load all language files (for directly using <code>&lt;pre&gt;</code> tags rather than shortcodes)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If left unchecked (default), then language files will only be loaded when needed<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If unsure, leave this box unchecked', 'syntaxhighlighter' ); ?></label>
1388
  </fieldset>
1389
  </td>
1390
  </tr>
4
 
5
  Plugin Name: SyntaxHighlighter Evolved
6
  Plugin URI: https://alex.blog/wordpress-plugins/syntaxhighlighter/
7
+ Version: 3.5.5
8
  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/SyntaxHighlighter/">SyntaxHighlighter</a>. Includes a new editor block.
9
  Author: Alex Mills (Viper007Bond)
10
  Author URI: https://alex.blog/
16
 
17
  class SyntaxHighlighter {
18
  // All of these variables are private. Filters are provided for things that can be modified.
19
+ var $pluginver = '3.5.5'; // Plugin version
20
  var $agshver = false; // Alex Gorbatchev's SyntaxHighlighter version (dynamically set below due to v2 vs v3)
21
  var $shfolder = false; // Controls what subfolder to load SyntaxHighlighter from (v2 or v3)
22
  var $settings = array(); // Contains the user's settings
123
  // Register brush scripts
124
  wp_register_script( 'syntaxhighlighter-core', plugins_url( $this->shfolder . '/scripts/shCore.js', __FILE__ ), array(), $this->agshver );
125
  wp_register_script( 'syntaxhighlighter-brush-as3', plugins_url( $this->shfolder . '/scripts/shBrushAS3.js', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
126
+ wp_register_script( 'syntaxhighlighter-brush-arduino', plugins_url( $this->shfolder . '/scripts/shBrushArduino.js', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
127
  wp_register_script( 'syntaxhighlighter-brush-bash', plugins_url( $this->shfolder . '/scripts/shBrushBash.js', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
128
  wp_register_script( 'syntaxhighlighter-brush-coldfusion', plugins_url( $this->shfolder . '/scripts/shBrushColdFusion.js', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
129
  wp_register_script( 'syntaxhighlighter-brush-cpp', plugins_url( $this->shfolder . '/scripts/shBrushCpp.js', __FILE__ ), array('syntaxhighlighter-core'), $this->agshver );
173
  $this->brushes = (array) apply_filters( 'syntaxhighlighter_brushes', array(
174
  'as3' => 'as3',
175
  'actionscript3' => 'as3',
176
+ 'arduino' => 'arduino',
177
  'bash' => 'bash',
178
  'shell' => 'bash',
179
  'coldfusion' => 'coldfusion',
234
 
235
  $this->brush_names = (array) apply_filters( 'syntaxhighlighter_brush_names', array(
236
  'as3' => __( 'ActionScript', 'syntaxhighlighter' ),
237
+ 'arduino' => __( 'Arduino', 'syntaxhighlighter' ),
238
  'bash' => __( 'BASH / Shell', 'syntaxhighlighter' ),
239
  'coldfusion' => __( 'ColdFusion', 'syntaxhighlighter' ),
240
  'clojure' => __( 'Clojure', 'syntaxhighlighter' ),
503
  */
504
  public function render_block( $attributes, $content ) {
505
  $remaps = array(
506
+ 'className' => 'classname',
507
  'lineNumbers' => 'gutter',
508
  'firstLineNumber' => 'firstline',
509
  'highlightLines' => 'highlight',
1247
 
1248
  // Sanitize the "classname" parameter
1249
  if ( 'class-name' == $key )
1250
+ $value = "'" . trim( preg_replace( '/[^a-zA-Z0-9 _-]/i', '', $value ) ) . "'";
1251
 
1252
  // Special sanitization for "pad-line-numbers"
1253
  if ( 'pad-line-numbers' == $key ) {
1388
  <td>
1389
  <fieldset>
1390
  <legend class="hidden"><?php esc_html_e( 'Load All Brushes', 'syntaxhighlighter' ); ?></legend>
1391
+ <label for="syntaxhighlighter-loadallbrushes"><input name="syntaxhighlighter_settings[loadallbrushes]" type="checkbox" id="syntaxhighlighter-loadallbrushes" value="1" <?php checked( $this->settings['loadallbrushes'], 1 ); ?> /> <?php wp_kses( _e( 'Always load all language files (for directly using <code>&lt;pre&gt;</code> tags rather than shortcodes). If left unchecked (default), then language files will only be loaded when needed. If unsure, leave this box unchecked.', 'syntaxhighlighter' ), array( 'code' => array(), 'br' => array() ) ); ?></label>
1392
  </fieldset>
1393
  </td>
1394
  </tr>
syntaxhighlighter3/scripts/shBrushArduino.js ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * SyntaxHighlighter
3
+ * http://alexgorbatchev.com/SyntaxHighlighter
4
+ *
5
+ * SyntaxHighlighter is donationware. If you are using it, please donate.
6
+ * http://alexgorbatchev.com/SyntaxHighlighter/donate.html
7
+ *
8
+ * @version
9
+ * 3.0.83 (Wed, 16 Apr 2014 03:56:09 GMT)
10
+ *
11
+ * @copyright
12
+ * Copyright (C) 2004-2013 Alex Gorbatchev.
13
+ *
14
+ * @license
15
+ * Dual licensed under the MIT and GPL licenses.
16
+ *
17
+ * Original brush carlynorama/wp-syntaxhighlighter-arduino updated April 2020 by https://siytek.com
18
+ */
19
+ ;(function()
20
+ {
21
+ // CommonJS
22
+ SyntaxHighlighter = SyntaxHighlighter || (typeof require !== 'undefined'? require('shCore').SyntaxHighlighter : null);
23
+
24
+ function Brush()
25
+ {
26
+
27
+ var datatypes = 'boolean char byte int long float double void unsigned volatile word string static const';
28
+
29
+ var keywords = 'setup loop if else for switch case default while do break continue return';
30
+
31
+ var functions = 'pinMode digitalWrite digitalRead analogRead analogWrite shiftOut pulseIn ' +
32
+ 'millis micros delay delayMicroseconds min max abs constrain ' +
33
+ 'map pow sq sqrt sin cos tan randomSeed random ' +
34
+ 'sizeof lowByte highByte bitRead bitWrite bitSet bitClear bit tone noTone' +
35
+ 'attachInterrupt detachInterrupt interrupts noInterrupts ' +
36
+ 'Serial\\.begin Serial\\.available Serial\\.read Serial\\.flush ' +
37
+ 'Serial\\.print Serial\\.println Serial\\.write ';
38
+
39
+ var constants = 'HIGH LOW INPUT OUTPUT true false CHANGE RISING FALLING';
40
+
41
+
42
+ this.regexList = [
43
+ { regex: SyntaxHighlighter.regexLib.singleLineCComments, css: 'comments' } // one line comments
44
+ ,{ regex: SyntaxHighlighter.regexLib.multiLineCComments, css: 'comments' } // multiline comments
45
+ ,{ regex: SyntaxHighlighter.regexLib.doubleQuotedString, css: 'string' } // strings
46
+ ,{ regex: SyntaxHighlighter.regexLib.singleQuotedString, css: 'string' } // strings
47
+ ,{ regex: /^ *#(.)+?\b/gm, css: 'preprocessor' } // preprocessor directives
48
+ ,{ regex: new RegExp(this.getKeywords(datatypes), 'gm'), css: 'color1 bold' } // datatypes
49
+ ,{ regex: new RegExp(this.getKeywords(functions), 'gm'), css: 'functions' } // functions
50
+ ,{ regex: new RegExp(this.getKeywords(keywords), 'gm'), css: 'keyword bold' } // control flow
51
+ ,{ regex: new RegExp(this.getKeywords(constants), 'gm'), css: 'constants bold' } // predefined constants
52
+ ,{ regex: /\b(\d*\.\d+([Ee]-?\d{1,3})?)|(\d+[Ee]-?\d{1,3})\b/gm, css: 'constants'} // numeric constants (floating point)
53
+ ,{ regex: /\b\d+[uU]?[lL]?\b/gm, css: 'constants'} // numeric constants (decimal)
54
+ ,{ regex: /\b0x[0-9A-Fa-f]+[uU]?[lL]?\b/gm, css: 'constants'} // numeric constants (hexidecimal)
55
+ ,{ regex: /\bB[01]{1,8}\b/gm, css: 'constants'} // numeric constants (binary)
56
+ ,{ regex: /\+|\-|\*|\/|\%|!|\||\&amp;|=|\?|\^|~/gm, css: 'plain bold' } // operators
57
+ ];
58
+ };
59
+
60
+ Brush.prototype = new SyntaxHighlighter.Highlighter();
61
+ Brush.aliases = ['arduino', 'arduinolite'];
62
+
63
+ SyntaxHighlighter.brushes.Arduino = Brush;
64
+
65
+ // CommonJS
66
+ typeof(exports) != 'undefined' ? exports.Brush = Brush : null;
67
+ })();