Andrew Tomaka
6933084926
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.
13 lines
467 B
CoffeeScript
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
|