code-syntax-block icon indicating copy to clipboard operation
code-syntax-block copied to clipboard

Styles not applied to dynamically added posts

Open uamv opened this issue 5 years ago • 4 comments

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 avatar Oct 01 '19 02:10 uamv

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

uamv avatar Oct 01 '19 19:10 uamv

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?

ajaykarwal avatar May 05 '20 15:05 ajaykarwal

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();
    } );

});

uamv avatar May 05 '20 18:05 uamv

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

ajaykarwal avatar May 05 '20 21:05 ajaykarwal