Skip to content

Commit 53143c6

Browse files
author
Renatho De Carli Rosa
committed
Add support to quickcode in the block editor and restrict to v3
1 parent 126ae96 commit 53143c6

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

src/blocks.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ registerBlockType( 'syntaxhighlighter/code', {
6969
type: 'boolean',
7070
default: syntaxHighlighterData.settings.makeURLsClickable.default,
7171
},
72+
73+
quickCode: {
74+
type: 'boolean',
75+
default: syntaxHighlighterData.settings.quickCode.default,
76+
},
7277
},
7378

7479
supports: {
@@ -128,7 +133,8 @@ registerBlockType( 'syntaxhighlighter/code', {
128133
firstLineNumber,
129134
highlightLines,
130135
wrapLines,
131-
makeURLsClickable
136+
makeURLsClickable,
137+
quickCode
132138
} = attributes;
133139

134140
let blockSettingRows = [];
@@ -250,6 +256,24 @@ registerBlockType( 'syntaxhighlighter/code', {
250256
);
251257
}
252258

259+
// Quick code
260+
if ( syntaxHighlighterData.settings.quickCode.supported ) {
261+
blockSettingRows.push(
262+
wp.element.createElement(
263+
PanelRow,
264+
null,
265+
wp.element.createElement(
266+
ToggleControl,
267+
{
268+
label: __( 'Quick code', 'syntaxhighlighter' ),
269+
checked: quickCode,
270+
onChange: ( quickCode ) => setAttributes( { quickCode } ),
271+
}
272+
)
273+
)
274+
);
275+
}
276+
253277
const blockSettings = (
254278
<InspectorControls key="syntaxHighlighterInspectorControls">
255279
<PanelBody title={ __( 'Settings', 'syntaxhighlighter' ) }>

syntaxhighlighter.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ function_exists( 'parse_blocks' ) // WordPress 5.0+
104104
'tabsize' => 4,
105105
'toolbar' => 0,
106106
'wraplines' => 1, // 2.x only
107-
'quickcode' => 1,
107+
'quickcode' => 1, // 3.x only
108108
) );
109109

110110
// Create the settings array by merging the user's settings and the defaults
@@ -359,6 +359,10 @@ function enqueue_block_editor_assets() {
359359
'supported' => true,
360360
'default' => (bool) $this->settings['autolinks'],
361361
),
362+
'quickCode' => (object) array(
363+
'supported' => ( '3' == $this->settings['shversion'] ),
364+
'default' => (bool) $this->settings['quickcode'],
365+
),
362366
);
363367

364368
wp_add_inline_script(
@@ -497,6 +501,7 @@ public function render_block( $attributes, $content ) {
497501
'highlightLines' => 'highlight',
498502
'wrapLines' => 'wraplines',
499503
'makeURLsClickable' => 'autolinks',
504+
'quickCode' => 'quickcode',
500505
);
501506

502507
foreach ( $remaps as $from => $to ) {
@@ -1399,7 +1404,7 @@ function settings_page() { ?>
13991404
<label for="syntaxhighlighter-light"><input name="syntaxhighlighter_settings[light]" type="checkbox" id="syntaxhighlighter-light" value="1" <?php checked( $this->settings['light'], 1 ); ?> /> <?php _e( 'Use the light display mode, best for single lines of code', 'syntaxhighlighter' ); ?></label><br />
14001405
<label for="syntaxhighlighter-smarttabs"><input name="syntaxhighlighter_settings[smarttabs]" type="checkbox" id="syntaxhighlighter-smarttabs" value="1" <?php checked( $this->settings['smarttabs'], 1 ); ?> /> <?php _e( 'Use smart tabs allowing tabs being used for alignment', 'syntaxhighlighter' ); ?></label><br />
14011406
<label for="syntaxhighlighter-wraplines"><input name="syntaxhighlighter_settings[wraplines]" type="checkbox" id="syntaxhighlighter-wraplines" value="1" <?php checked( $this->settings['wraplines'], 1 ); ?> /> <?php _e( 'Wrap long lines (v2.x only, disabling this will make a scrollbar show instead)', 'syntaxhighlighter' ); ?></label><br />
1402-
<label for="syntaxhighlighter-quickcode"><input name="syntaxhighlighter_settings[quickcode]" type="checkbox" id="syntaxhighlighter-quickcode" value="1" <?php checked( $this->settings['quickcode'], 1 ); ?> /> <?php _e( 'Enable edit mode on double click', 'syntaxhighlighter' ); ?></label><br />
1407+
<label for="syntaxhighlighter-quickcode"><input name="syntaxhighlighter_settings[quickcode]" type="checkbox" id="syntaxhighlighter-quickcode" value="1" <?php checked( $this->settings['quickcode'], 1 ); ?> /> <?php _e( 'Enable edit mode on double click (v3.x only)', 'syntaxhighlighter' ); ?></label><br />
14031408
<!--<label for="syntaxhighlighter-htmlscript"><input name="syntaxhighlighter_settings[htmlscript]" type="checkbox" id="syntaxhighlighter-htmlscript" value="1" <?php checked( $this->settings['htmlscript'], 1 ); ?> /> <?php _e( 'Enable &quot;HTML script&quot; mode by default (see the bottom of this page for details). Checking this box is not recommended as this mode only works with certain languages.', 'syntaxhighlighter' ); ?></label>-->
14041409
</fieldset>
14051410
</td>
@@ -1562,7 +1567,7 @@ function validate_settings( $settings ) {
15621567
$settings['smarttabs'] = ( ! empty($settings['smarttabs']) ) ? 1 : 0;
15631568
$settings['toolbar'] = ( ! empty($settings['toolbar']) ) ? 1 : 0; // May be overridden below
15641569
$settings['wraplines'] = ( ! empty($settings['wraplines']) ) ? 1 : 0; // 2.x only for now
1565-
$settings['quickcode'] = ( ! empty($settings['quickcode']) ) ? 1 : 0;
1570+
$settings['quickcode'] = ( ! empty($settings['quickcode']) ) ? 1 : 0; // 3.x only for now
15661571

15671572
// If the version changed, then force change the toolbar version setting
15681573
if ( $settings['shversion'] != $this->settings['shversion'] ) {

0 commit comments

Comments
 (0)