mkaz / code-syntax-block

A WordPress plugin which extends Gutenberg adding color syntax highlighting to the code block.
319 stars 50 forks source link

Styles not applied to dynamically added posts #55

Open uamv opened 5 years ago

uamv commented 5 years ago

Posts that are added to a post feed via an AJAX call do not seem to have styles applied from the Code Syntax Block plugin. Is there a way to automatically catch newly added content or a way that restyling could be triggered on elements after such content has been added? You can see this issue here when you load more posts.

uamv commented 5 years ago

I was able to hook into an event after having added posts and called Prism.highlightAll(); which fixed this for me.

ajaykarwal commented 4 years ago

Hey @uamv, I've just ran into the same issue. No styles being added to post which is loaded via the Worpress 'Recent Posts' widget.

Could you share some details on how you got this working?

uamv commented 4 years ago

I was encountering this while using GeneratePress theme and its infinite scroll feature for archive pages. I was able to use the following code to trigger Prism.highlightAll() when append.infiniteScroll ran.

jQuery(document).ready(function($) {

    var $container = $( '#main article' ).first().parent();

    $container.on( 'append.infiniteScroll', function( event, response, path, items ) {
        Prism.highlightAll();
    } );

});
ajaykarwal commented 4 years ago

I've tried getting it to trigger like you have but not having any luck. But, I noticed in the readme you can force it to load by adding this to functions.php

add_filter('mkaz_code_syntax_force_loading', '__return_true');

Worked a treat