Support » Plugin: CodeMirror Blocks » Problems with the default highlighting setting

  • Resolved Mikko Saari

    (@msaari)


    If I save a post with PHP set as the block language, the highlighting doesn’t work. The block is saved with these settings:

    <!-- wp:codemirror-blocks/code-block {"theme":"monokai"} -->

    If I save the post with eg. Perl as the block language, the parameters are stored correctly:

    <!-- wp:codemirror-blocks/code-block {"mode":"perl","mime":"text/x-perl","theme":"monokai"} -->

    If I manually change that in the database to

    <!-- wp:codemirror-blocks/code-block {"mode":"php","mime":"text/x-php","theme":"monokai"} -->

    the highlighting works.

    So, for some reason, the PHP language setting is not saved to the block correctly. The problem started with 1.1 and the new default settings, and still persists in 1.1.3.

    Looks like part of the problem is in render_code_block(), where you combine the block parameters with the default parameters with wp_parse_args(). This is fine, except the parameters for the block without a mode setting look like this:

    array(3) {
      ["theme"]=>
      string(7) "monokai"
      ["mode"]=>
      string(9) "htmlmixed"
      ["mime"]=>
      string(9) "text/html"
    }

    So there’s a default htmlmixed coming in, and that since that’s there, wp_parse_args() won’t override it with the PHP I’ve set as default in the settings.

    If I do

    
    unset($attributes['mode']);
    unset($attributes['mime']);
    

    before the wp_parse_args(), the highlighting works again. It also works if I uncomment the default values for mode and mime in init(), so that’s the root cause I suppose – those should be empty, otherwise the default values set in the plugin settings won’t take effect.

    However, it would also be good that if I explicitly save the block as a PHP block that selection would be saved in the block metadata – I don’t want it to change if I change the default setting. Based on my tests it looks like if the current block setting matches the default setting, it’s not saved in the block – but I think it should be.

Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Problems with the default highlighting setting’ is closed to new replies.