Support » Plugin: Syntax-highlighting Code Block (with Server-side Rendering) » Easy migration path to this plugin from ‘Code Syntax Block’

  • Is there an easy migration path from mkaz’s Code Syntax Block plugin to yours? Code blocks are broken since I disabled ‘Code Syntax Block’ and need to be converted. I don’t want to edit hundreds of posts manually with possibly even more code blocks.. 🙂

    What I have now is, for example

    <!-- wp:code -->
    <pre class="wp-block-code"><code lang="powershell" class="language-powershell">Get-SmbServerConfiguration | Select EnableSMB1Protocol</code></pre>
    <!-- /wp:code -->
    

    And this needs to be converted into:

    <!-- wp:code {"language":"powershell"} -->
    <pre class="wp-block-code"><code>Get-SmbServerConfiguration | Select EnableSMB1Protocol</code></pre>
    <!-- /wp:code -->

    BTW: I tried to use John Godley’s Search Regex plugin, but that broke more than it fixed… A kind of working regexp is:

    s/<!-- wp:code -->\n<pre class="wp-block-code"><code lang="\(.*\)" class="language-.*">/<!-- wp:code {"language":"\1"} -->\r<pre class="wp-block-code"><code>/

    But I like a more fail-safe migration path 🙂 I’ll update this support question if I find a solution in the meantime.

Viewing 1 replies (of 1 total)
  • Thread Starter Jan Reilink

    (@janr)

    For anyone facing the same issue: I used MariaDB’s REGEXP_REPLACE function (MySQL has it too).

    UPDATE test_posts SET post_content = REGEXP_REPLACE( post_content, '<!-- wp:code -->\n<pre class="wp-block-code"><code lang="(.*)" class="language-.*">', '<!-- wp:code {"language":"\\1"} -->\n<pre class="wp-block-code"><code>');
    

    After this, I had to perform some smaller changes, as not all language names are the same:

    UPDATE test_posts SET post_content = REGEXP_REPLACE( post_content, '<!-- wp:code {"language":"csharp"} -->', '<!-- wp:code {"language":"cs"} -->');
    UPDATE test_posts SET post_content = REGEXP_REPLACE( post_content, '<!-- wp:code {"language":"visual-basic"} -->', '<!-- wp:code {"language":"vbnet"} -->');
    UPDATE test_posts SET post_content = REGEXP_REPLACE( post_content, '<!-- wp:code {"language":"none"} -->', '<!-- wp:code {"language":"plaintext"} -->');

    PS:
    Gutenberg does not recognize the language when using an alias, e.g if I have <!-- wp:code {"language":"vb"} -->, then editing a post shows Auto-detect instead of VB.NET

    • This reply was modified 10 months, 2 weeks ago by Jan Reilink.
    • This reply was modified 10 months, 2 weeks ago by Jan Reilink. Reason: had to remove backtics for code blocks
Viewing 1 replies (of 1 total)
  • The topic ‘Easy migration path to this plugin from ‘Code Syntax Block’’ is closed to new replies.