Click anywhere to close

Highlight JS with Turbolinks

The Turbolinks gem doesn't let you use the $(document).ready() calls that highlight_js requires to highlight your code. Instead include the following at the bottom of your application.js:

$(document).on('page:change',  function() {
  $('pre code').each(function(i, e) {hljs.highlightBlock(e)});
});
$(document).on('page:restore', function() {
  $('pre code').each(function(i, e) {hljs.highlightBlock(e)});
});

This runs the text highlighting when the page is changed or restored using Turbolinks.

Source: http://kingori.co/minutae/2014/02/highlightjs-on-turbolinks/

Recent Posts

Complicated Custom Apple Watch Complications, enabled by WebHooks
Categories:  Projects, iOS, Complicated
Posted: March 09, 2019
Complicated API Documentation API Documentation
Categories:  Projects, iOS, Complicated-Tutorial
Posted: March 08, 2019
Update your Apple Watch from IFTTT Use IFTTT and Complicated to update your Apple Watch
Categories:  Projects, iOS, Complicated-Tutorial
Posted: March 07, 2019
Making Mini Dor Sensors Using silicone moulding to make party favors for my product launch party
Categories:  Projects
Posted: January 26, 2019
How to make custom Apple Watch complications with Complicated Simple Apple Watch Complications via Webhooks
Categories:  Projects, iOS, Complicated-Tutorial
Posted: January 13, 2019