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

Shirtbot It's a slack bot that makes shirts
Posted: August 01, 2021
I feel stuck in the the engineering for engineers trap If you aren't an engineer please read this and reach out, I'd love to chat
Posted: June 20, 2021
Unwritten Coding Standards: Function Ordering A standard for how you should order functions in files to increase the consistency of your code bases
Posted: May 15, 2021
Designing a guitar with hot-swappable pickups I made a custom guitar with hot-swappable pickups
Posted: May 02, 2021
How to design a motherboard for your electronics project - Part 2 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.
Posted: April 25, 2021