Modifying/using highlight.js

Heya,

I’m trying to get the following plugin for Highlight.js to work.
https://github.com/wcoder/highlightjs-line-numbers.js

Problem is that I don’t seem to have access to the hljs object and I am at a total loss as to how Discourse includes the Highlight.js code and styling.
Can anyone give me some pointers?

It is done via

api.decorateCooked(highlightSyntax)

There is no existing hook to extend highlight js, but you can run decorateCooked in your plugin to apply further transforms to cooked.

3 Likes

Thanks, I’ll have a look :slight_smile:

Is decorateCooked documented anywhere though? Couldn’t find anything at http://docs.discourse.org

There’s always the source code :wink:

https://github.com/discourse/discourse/blob/master/app/assets/javascripts/discourse/lib/plugin-api.js.es6#L93-L107

3 Likes

Yeah, guess that would work :slight_smile:

I’ll toy around with this a bit later on and see how to get some javascript to fire on every load