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

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
How to add Currently Playing to your homepage A code snippet to add a last.fm based currently playing section to your personal site
Technology
posted: February 05, 2024
rough draft 1: is it possible to start anywhere that isn’t the beginning? essay 1 - should we even get started?
Technology
posted: February 02, 2024