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

ghosts but dear reader, how can you open instagram if your thumbs are ephemeral?
Personal
posted: March 30, 2025
what if? chapter 1 this is my first time publishing work with dialogue. Don't judge me too harshly my dear reader
Personal
posted: March 07, 2025
on refusing to become a pessimist what sound does a hedgehog make?
Personal
posted: March 06, 2025
definitions chapter 3: getting over something wow 3 posts in one day, my dear readers are eating today
Personal
posted: March 06, 2025
i'll have to think about that i guess, at least, trying again will give me something new to write about
Personal
posted: March 05, 2025