bobbingwide / oik-blocks

WordPress 5.0 blocks for oik shortcodes
https://oik-plugins.com/oik-plugins/oik-blocks
GNU General Public License v3.0
1 stars 0 forks source link

Create GeSHi block - server side rendered - for the [bw_geshi] shortcode #18

Closed bobbingwide closed 2 years ago

bobbingwide commented 5 years ago

Requirements

Proposed solution

This block to be added to the list of experimental blocks in #16

bobbingwide commented 5 years ago

This information may help someone attempting to debug their own server side rendered block. The following message is may be shown when you attempt to create a block that is server side rendered but haven't written the server side logic.

Error loading block: No route was found matching the URL and request method 

This was the case when I first developed the geshi block. I'd only written some JS; none of the PHP.

bobbingwide commented 5 years ago

If the server side rendering doesn't return anything then you'll get a spinner. s b_wordpress_wp-admin_post php_post 952 action edit

bobbingwide commented 5 years ago

If you see This block has encountered an error and cannot be previewed then you should look at the JavaScript console. You might find something like this... ReferenceError: SelectControl is not defined. This indicates that you need to add an import statement.

bobbingwide commented 5 years ago

Error loading block: Invalid parameter(s): attributes is produced when one or more of the attributes passed to the server is not recognised.

bobbingwide commented 5 years ago

Here's what I have so far. image

I can make it hide the input field when the block is not selected, but can't position the input field above the server rendered output nor prevent the server rendering while I'm typing into the field.

bobbingwide commented 5 years ago

Primary purpose is to avoid problems with unwanted p and br tags created by Gutenberg when attempting to write a post using the Block editor which contains the [bw_geshi] shortcode.

The reason this happens is because the shortcode block is rendered using

function render_block_core_shortcode( $attributes, $content ) {
    return wpautop( $content );
}
bobbingwide commented 5 years ago

It appears I need to change the oik_geshi() code to accept a default value of "none" for the lang. The server side rendering logic doesn't always want to pass "lang=none" from the SelectControl.

bobbingwide commented 4 years ago

The logic for this block has been copied to https://github.com/bobbingwide/oik-css which is being converted to a standalone plugin for two blocks oik-css/css and oik-css/geshi. Over time the solution in oik-blocks will be deprecated.

bobbingwide commented 2 years ago

The GeSHi block is now delivered by the oik-css plugin