From 88c00027ea23f75f54ba1e41f28659e49d73a14f Mon Sep 17 00:00:00 2001 From: andreimarcu Date: Thu, 12 Nov 2015 11:17:53 -0500 Subject: [PATCH] Add line numbers for pastebin. Fixes #70 --- static/css/highlight/tomorrow.css | 13 +++++++++++++ static/js/bin_hljs.js | 1 + static/js/highlight/highlightjs-line-numbers.min.js | 3 +++ templates/display/bin.html | 1 + 4 files changed, 18 insertions(+) create mode 100644 static/js/highlight/highlightjs-line-numbers.min.js diff --git a/static/css/highlight/tomorrow.css b/static/css/highlight/tomorrow.css index ae9d1f8..9bc0645 100644 --- a/static/css/highlight/tomorrow.css +++ b/static/css/highlight/tomorrow.css @@ -79,6 +79,19 @@ padding: 0.5em; } +.hljs-line-numbers { + text-align: right; + border-right: 1px solid #ccc; + margin-right: 5px; + color: #999; + -webkit-touch-callout: none; + -webkit-user-select: none; + -khtml-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + user-select: none; +} + .coffeescript .javascript, .javascript .xml, .tex .hljs-formula, diff --git a/static/js/bin_hljs.js b/static/js/bin_hljs.js index 61e7f52..5ccbd53 100644 --- a/static/js/bin_hljs.js +++ b/static/js/bin_hljs.js @@ -2,5 +2,6 @@ hljs.tabReplace = ' '; hljs.initHighlightingOnLoad(); +hljs.initLineNumbersOnLoad(); // @license-end diff --git a/static/js/highlight/highlightjs-line-numbers.min.js b/static/js/highlight/highlightjs-line-numbers.min.js new file mode 100644 index 0000000..8ef50bc --- /dev/null +++ b/static/js/highlight/highlightjs-line-numbers.min.js @@ -0,0 +1,3 @@ +// @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&dn=expat.txt Expat +!function(e){"use strict";function t(){e.addEventListener("load",function(){try{var e=document.querySelectorAll("code.hljs");for(var t in e)e.hasOwnProperty(t)&&n(e[t])}catch(r){console.error("LineNumbers error: ",r)}})}function n(e){if("object"==typeof e){var t=e.parentNode,n=r(t.textContent);if(n>1){for(var o="",l=0;n>l;l++)o+=l+1+"\n";var c=document.createElement("code");c.className="hljs hljs-line-numbers",c.style["float"]="left",c.textContent=o,t.insertBefore(c,e)}}}function r(e){if(0===e.length)return 0;var t=/\r\n|\r|\n/g,n=e.match(t);return n=n?n.length:0,e[e.length-1].match(t)||(n+=1),n}"undefined"==typeof e.hljs?console.error("highlight.js not detected!"):(e.hljs.initLineNumbersOnLoad=t,e.hljs.lineNumbersBlock=n)}(window); +// @license-end \ No newline at end of file diff --git a/templates/display/bin.html b/templates/display/bin.html index bfa66c2..00d8177 100644 --- a/templates/display/bin.html +++ b/templates/display/bin.html @@ -44,6 +44,7 @@ {% if extra.lang_hl != "text" %} + {% endif %}