Skip to content

Commit fcc401d

Browse files
authored
Merge pull request #90 from Viper007Bond/add/gutenberg-plugin-support-back
Add Gutenberg plugin support back
2 parents 1aff9c8 + d9f9a96 commit fcc401d

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

readme.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
=== SyntaxHighlighter Evolved ===
22
Contributors: Viper007Bond, automattic
33
Donate link: http://www.viper007bond.com/wordpress-plugins/syntaxhighlighter/donate/
4-
Tags: code, sourcecode, php, xhtml, html, css, WordPress.com
4+
Tags: code, sourcecode, block, php, xhtml, html, css, WordPress.com
55
Requires at least: 4.2.3
66
Tested up to: 5.0
77
Stable tag: trunk
@@ -10,6 +10,8 @@ Easily post syntax-highlighted code to your site without having to modify the co
1010

1111
== Description ==
1212

13+
*Now with support for the new block editor in WordPress 5.0!*
14+
1315
SyntaxHighlighter Evolved allows you to easily post syntax-highlighted code to your site without losing its formatting or making any manual changes. It uses the [SyntaxHighlighter JavaScript package by Alex Gorbatchev](http://alexgorbatchev.com/wiki/SyntaxHighlighter).
1416

1517
For a live demo, see [this plugin's homepage](http://www.viper007bond.com/wordpress-plugins/syntaxhighlighter/).
@@ -35,6 +37,10 @@ Try excluding this plugin's Javascript from any performance optimizations your s
3537

3638
== ChangeLog ==
3739

40+
= Version 3.4.1 =
41+
42+
* Bring back support for the Gutenberg plugin for the people that are still on older versions of WordPress (pre-5.0) and are using the new block editor via the Gutenberg plugin.
43+
3844
= Version 3.4.0 =
3945

4046
* Drop support for the Gutenberg plugin in favor of WordPress 5.0's native functionality (different function names).

syntaxhighlighter.php

Lines changed: 17 additions & 5 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.4.0
7+
Version: 3.4.1
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.4.0'; // Plugin version
24+
var $pluginver = '3.4.1'; // 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
@@ -73,7 +73,10 @@ function __construct() {
7373
add_filter( 'plugin_action_links', array( $this, 'settings_link' ), 10, 2 );
7474

7575
// Editor Blocks
76-
if ( function_exists( 'parse_blocks' ) ) {
76+
if (
77+
function_exists( 'parse_blocks' ) // WordPress 5.0+
78+
|| function_exists( 'the_gutenberg_project' ) // Gutenberg plugin for older WordPress
79+
) {
7780
add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_block_editor_assets' ) );
7881
add_action( 'the_content', array( $this, 'enable_brushes_used_in_blocks' ), 0 );
7982
}
@@ -317,7 +320,10 @@ function enqueue_block_editor_assets() {
317320
: $this->pluginver
318321
);
319322

320-
wp_set_script_translations( 'syntaxhighlighter-blocks', 'syntaxhighlighter' );
323+
// WordPress 5.0+ only, no Gutenberg plugin support
324+
if ( function_exists( 'wp_set_script_translations' ) ) {
325+
wp_set_script_translations( 'syntaxhighlighter-blocks', 'syntaxhighlighter' );
326+
}
321327

322328
natsort( $this->brush_names );
323329

@@ -353,7 +359,13 @@ function enable_brushes_used_in_blocks( $content ) {
353359
return $content;
354360
}
355361

356-
$blocks = parse_blocks( $content );
362+
if ( function_exists( 'parse_blocks' ) ) { // WP 5.0+
363+
$blocks = parse_blocks( $content );
364+
} elseif ( Function_exists( 'gutenberg_parse_blocks' ) ) { // Gutenberg plugin
365+
$blocks = gutenberg_parse_blocks( $content );
366+
} else {
367+
return $content;
368+
}
357369

358370
foreach ( $blocks as $block ) {
359371
if ( empty( $block['blockName'] ) || 'syntaxhighlighter/code' !== $block['blockName'] ) {

0 commit comments

Comments
 (0)