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

rough draft 3: you are going to have to do it alone you are the only person who can swim under the iceberg
Personal
posted: October 26, 2024
rough draft 2: falling in love by being radically honest chapter 2 is where we realize it's not a normal book about productivity
Personal
posted: August 29, 2024
Farewell to Arkansas St a farewell letter to the best apartment I have ever had
Personal
posted: July 01, 2024
A quick teardown of the NES Zapper Lightgun A quick teardown of the NES Zapper Lightgun, mostly as a love letter to the geniuses who built this and a girl I will always love
Technology
posted: April 26, 2024
shouldibreaknocontact.com I have too much money, and I like to buy novelty domains
Personal
posted: March 28, 2024