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 Other Posts

Google Cache Javascript Shortcut Automatically takes you to the lastest google cached version of a site
Categories:  Web
Posted: June 12, 2017
I hate writing web scrapers Proposition for a better way to scrape`
Categories:  Projects, Web, Scraping
Posted: April 02, 2016
One-to-Many Relationships in CouchDB How to best create One-to-Many relationships in CouchDB
Categories:  Web, CouchDB
Posted: July 09, 2014
ReddPics Javascript Shortcut Automatically takes you from reddit to reddpics
Categories:  Web
Posted: June 03, 2014
JP Morgan Code For Good 2013 Jawbone UP data based donation page
Categories:  Python, Web
Posted: May 29, 2014