Forum Replies Created

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter javier

    (@jnigro)

    Thanks, will do. When you update your plugin, it could be a good idea to add a transformation option. I added a simple one to my block and it made it very easy to migrate from <code> to my <snippet> block type:

    transforms: {
            from: [
            {
                type: 'block',
                blocks: [ 'core/code' ],
                transform: function( attributes) {
                    const regex = /[ \t]*language-[^ \t]*[ \t]*/gi;
    
                    return createBlock( 'javier/snippet', {
                            content: attributes.content,
                            className: attributes.className.replace(regex, ' ').trim(),
                    } );
                },
            },
        ],
    },

    Cheers,
    Javier.

    Thread Starter javier

    (@jnigro)

    Hi Jeff,

    I don’t think there is an issue with Prismatic blocks. It’s probably the intended behavior. But in my case it is a problem. I finally managed to solved it by creating my own custom block <snippet>, inspired mostly by blocks-prism.js

    To explain it better, here are two pictures. In the first image, there are 3 columns. First column is the edit page when code blocks are first created. Second column is the view page, with Prismatic settings for content escaping off, and third column with content escaping on. As you can see, when the code block works fine, prismatic doesn’t and viceversa.

    Of the three blocks, one is created with the standard code block (language-swift class), the second with prismatic block and the third with my own block (snippet). Also notice how Prismatic does not use a fixed-size width font for the editing block.

    https://i.ibb.co/Qnb5D7W/prismatic1.png

    In the second image you can see what I mentioned in my first post. When revisiting the edit page, the code block applies the style to the editor but it doesn’t do a good job, and new lines are gone, messing everything up.

    https://i.ibb.co/fqNVCbw/prismatic2.png

    As I said, I already have my issue resolved… but I did owe you a full explanation.

    Cheers,
    Javier

    Thread Starter javier

    (@jnigro)

    Thank you Jeff for your super-fast reply! I’m an experienced programmer but absolutely new to WordPress… I’m getting to understand how the different components interact in WordPress. After posting I continue to investigate and began to create my own custom block, only to understand the issue better.

    I though of using block filters to modify the core/code block edit part, but there’s still a lot I have to learn to even attempt that… and I don’t have the time at the moment.

    The safest route right now is to start using “Prismatic” blocks, but I am facing a problem with escaping. If I change the prismatic configuration to properly escape my new prismatic snippets, it makes my existing old “code” snippets to show “lt” entities instead of the actual < character. It’s either one or the other. And I have so much content already, that going through all and updating every single snippet to the Prismatic block is just not possible.

    I understand this is out of your hands, but thanks for listening. And thank you for the plugin!

Viewing 3 replies - 1 through 3 (of 3 total)