tack2us/app/assets/javascripts/pastes.js.coffee
Andrew Tomaka 6933084926 Add line numbers
Line numbers are not supported by highlight.js.  This is hacked in through
JavaScript.  At page load, the number of new line characters are counted in the
code element.  Then, JavaScript loops through and adds a number and line break
to an empty div that is floated left.  This gives the appearence of line
numbers.
2014-03-09 15:25:15 -04:00

13 lines
467 B
CoffeeScript

# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
$(document).on 'ready page:load', ->
$(".code pre code").each (i, e) ->
hljs.highlightBlock e
numberLines e
numberLines = (e) ->
$('.line-numbers').html([1..lineCount(e)].join("<br/>"))
lineCount = (e) ->
$(e).html().split("\n").length - 1