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

How to design a motherboard for your electronics project - Part 1 Designing a motherboard for your project is a great second step when developing an electronics project. This is the guide I wish existed when I got started doing this.
Categories:  Projects
Posted: February 21, 2021
Caffstat Beta Caffstat is the first Hackable Home Thermostat
Categories:  Projects
Posted: February 20, 2021
v2 Updates to my HomeKit Thermostat Making my thermostat project into something I can actually use every day
Categories:  Projects
Posted: December 31, 2020
Building my own HomeKit Thermostat Holiday 2020 project, building a custom HomeKit enabled thermostat
Categories:  Projects
Posted: December 27, 2020
Unwritten Coding Standards: Vertical Whitespace Simple vertical whitespace rules that will make any code easier to read
Categories:  Coding, mike8
Posted: May 27, 2020