From 7bdd08b8357d986ef2f775f62d8f0d11a605c94f Mon Sep 17 00:00:00 2001 From: Peter Kiss Date: Tue, 17 Nov 2020 16:46:55 +0100 Subject: [PATCH 1/2] Move block classes to top-level wrapper --- syntaxhighlighter.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/syntaxhighlighter.php b/syntaxhighlighter.php index 51a4952..455138a 100644 --- a/syntaxhighlighter.php +++ b/syntaxhighlighter.php @@ -507,7 +507,6 @@ public function enable_brushes_via_raw_html_parsing( $content ) { */ public function render_block( $attributes, $content ) { $remaps = array( - 'className' => 'classname', 'lineNumbers' => 'gutter', 'firstLineNumber' => 'firstline', 'highlightLines' => 'highlight', @@ -515,6 +514,7 @@ public function render_block( $attributes, $content ) { 'makeURLsClickable' => 'autolinks', 'quickCode' => 'quickcode', ); + $classNames = ! empty( $attributes['className'] ) ? [ esc_attr( $attributes['className'] ) ] : []; foreach ( $remaps as $from => $to ) { if ( isset( $attributes[ $from ] ) ) { @@ -538,7 +538,9 @@ public function render_block( $attributes, $content ) { $code = str_replace( '&', '&', $code ); $code = preg_replace( '/^(\s*https?:)//([^\s<>"]+\s*)$/m', '$1//$2', $code ); - return $this->shortcode_callback( $attributes, $code, 'code' ); + $code = $this->shortcode_callback( $attributes, $code, 'code' ); + + return '
' . $code . '
'; } // Add the custom TinyMCE plugin which wraps plugin shortcodes in
 in TinyMCE
@@ -1330,7 +1332,7 @@ function shortcode_callback( $atts, $code = '', $tag = false ) {
 
 		$params = apply_filters( 'syntaxhighlighter_cssclasses', $params ); // Use this to add additional CSS classes / SH parameters
 
-		return apply_filters( 'syntaxhighlighter_htmlresult', '
' . $code . '
' );; + return apply_filters( 'syntaxhighlighter_htmlresult', '
' . $code . '
' ); } From 25242b98420807cca73a1ab8d5bb7c5099dbbdbd Mon Sep 17 00:00:00 2001 From: Peter Kiss Date: Tue, 17 Nov 2020 16:47:06 +0100 Subject: [PATCH 2/2] Add block alignment support --- src/code-block/index.js | 1 + syntaxhighlighter.php | 3 +++ 2 files changed, 4 insertions(+) diff --git a/src/code-block/index.js b/src/code-block/index.js index 78698f6..5befe2c 100644 --- a/src/code-block/index.js +++ b/src/code-block/index.js @@ -54,6 +54,7 @@ export default { }, supports: { html: false, + align: true, }, transforms, edit, diff --git a/syntaxhighlighter.php b/syntaxhighlighter.php index 455138a..576b7f2 100644 --- a/syntaxhighlighter.php +++ b/syntaxhighlighter.php @@ -515,6 +515,9 @@ public function render_block( $attributes, $content ) { 'quickCode' => 'quickcode', ); $classNames = ! empty( $attributes['className'] ) ? [ esc_attr( $attributes['className'] ) ] : []; + if( ! empty( $attributes['align'] ) ) { + $classNames[] = 'align' . esc_attr( $attributes['align'] ); + } foreach ( $remaps as $from => $to ) { if ( isset( $attributes[ $from ] ) ) {