# decorateCooked in theme vs HighlighJS

**URL:** <https://meta.discourse.org/t/decoratecooked-in-theme-vs-highlighjs/126208>\
**Category:** Product Support\
**Created:** [19 באוגוסט,‏ 2019,‏ 6:21pm UTC](https://meta.discourse.org/t/decoratecooked-in-theme-vs-highlighjs/126208 "2019-08-19T18:21:14Z")\
**Posts on this page:** 1\
**Showing post:** 1

<div class="post-metadata">

**Author:** ![alldritt](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/alldritt/32/119516_2.png) [@alldritt](https://meta.discourse.org/u/alldritt)\
**Post date:** [19 באוגוסט,‏ 2019,‏ 6:21pm UTC](https://meta.discourse.org/t/decoratecooked-in-theme-vs-highlighjs/126208/1 "2019-08-19T18:21:14Z")

</div>

I’m using `decorateCooked` in my site’s theme to post-process HighlightJS code blocks for a particular language. It is working when ``` is used to indicate code in a post but It is failing when indentation is used to include code.

In the successful case the HighligtJS classes are present before my `decorateCooked` code is invoked and I can use JQuery to find code blocks carrying my language class (‘applescript’). In the failing case, it appears that HighlightJS is applying its magic after my plugin code runs because the HighlighJS classes (`hljs applescript`) are missing. But these classes are present when I later inspect the loaded page.

Here’s my code which is defined in the `</HEAD>` portion of my theme:

```plaintext
<script type="text/discourse-plugin" version="0.1">
    if (navigator.appVersion.indexOf('Mac') >= 0) { // Only do this on the Mac
        api.decorateCooked(
            $elem => {
                console.log($elem.find('code'));
                console.log($elem.find('code').attr('class'));
                $elem.find('.lang-applescript, .applescript').filter(function () {
		            return $(this).parents('.d-editor-preview').length < 1; // Don't do this in editor previews
            	}).each(function(index) {
   		            var src = encodeURIComponent(this.innerText);

        		    $( '<a class="widget-button btn btn-default" href="sdapplescript://com.apple.scripteditor?action=new&script=' + src + '">Open in Script Debugger</a>' ).insertAfter($(this).parent());
        	    });
            },
            { id: 'applescript-decorator' }
        );
    }
</script>

```

Looking at the console log, I see that I’m finding the `<code>` blocks in my posts, but the `class` attribute is reported as `undefined`.

Is there a way of having my `decorateCooked` code run **after** HighlightJS has done its thing?

---

_[View the full topic](https://meta.discourse.org/t/decoratecooked-in-theme-vs-highlighjs/126208)._
