Add class to wp core/code child element code tag

35 views Asked by At

I'm have a drop down select that adds the option to the wp core/code block pre tag class. I need to add the class to the code tag that is inside of the pre tag. I am new to react/gutenberg custom blocks and not sure how to go about this.

/**
 * Add custom class to block in Edit
 */
const withSidebarSelectProp = createHigherOrderComponent( ( BlockListBlock ) => {
    return ( props ) => {

        // If current block is not allowed
        if ( ! enableSidebarSelectOnBlocks.includes( props.name ) ) {
            return (
                <BlockListBlock { ...props } />
            );
        }

        const { attributes } = props;
        const { codeAttribute } = attributes;

        if ( codeAttribute ) {
            return <BlockListBlock { ...props } className={ 'language-' + codeAttribute } />
        } else {
            return <BlockListBlock { ...props } />
        }
    };
}, 'withSidebarSelectProp' );

wp.hooks.addFilter(
    'editor.BlockListBlock',
    'custom-attributes/with-sidebar-select-prop',
    withSidebarSelectProp
);
0

There are 0 answers