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

Why I started a Blog Writing to start conversations
Categories:  Random
Posted: June 03, 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
Things I Like Bootstrapping our reader/writer relationship by front-loading all the things I love and would inevitably tell you about anyway
Categories:  Random
Posted: May 24, 2020
Scalability Dimensions A few words on how you should order parameters to maximize codebase consistency and scalability
Categories:  Coding
Posted: May 20, 2020
Unwritten Coding Standards: Parameter Ordering A few words on how you should order parameters to maximize codebase consistency and scalability
Categories:  Coding, mike8
Posted: May 13, 2020