A Pen by Heiswayi Nrird on CodePen.
Last active
November 16, 2017 04:12
-
-
Save manbearwolf/b21f89059aee69f9debeed58a753a0cf to your computer and use it in GitHub Desktop.
Add line numbers to the code block generated by markdown
<?php
header('Content-type: text/css');
ob_start("compress");
function compress($buffer) {
/* remove comments */
$buffer = preg_replace('!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $buffer);
/* remove tabs, spaces, newlines, etc. */
$buffer = str_replace(array("\r\n", "\r", "\n", "\t", ' ', ' ', ' '), '', $buffer);
return $buffer;
}
/* css files for compression */
include('grid.css');
include('typography.css');
include('button.css');
include('form.css');
include('table.css');
include('backgrounds.css');
include('pagination.css');
include('breadcrumbs.css');
include('font.css');
include('helpers.css');
include('print.css');
include('animation.css');
include('responsive.css');
ob_end_flush();
?>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
var pre = document.getElementsByTagName('pre'), | |
pl = pre.length; | |
for (var i = 0; i < pl; i++) { | |
pre[i].innerHTML = '<span class="line-number"></span>' + pre[i].innerHTML + '<span class="cl"></span>'; | |
var num = pre[i].innerHTML.split(/\n/).length; | |
for (var j = 0; j < (num); j++) { | |
var line_num = pre[i].getElementsByTagName('span')[0]; | |
line_num.innerHTML += '<span>' + (j + 1) + '</span>'; | |
} | |
} | |
})(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
padding: 100px; | |
font-size: 16px; | |
} | |
pre { | |
display: block; | |
margin-top: 0; | |
margin-bottom: 1rem; | |
font-size: 0.7rem; | |
line-height: 1.4; | |
white-space: pre; | |
overflow: auto; | |
background-color: #f9f9f9; | |
border: 1px solid #ddd; | |
padding: .5rem; | |
max-height: 800px; | |
font-family: monospace; | |
code { | |
color: inherit; | |
background-color: transparent; | |
padding: 0; | |
display: block; | |
} | |
.line-number { | |
display: block; | |
float: left; | |
margin: 0 1em 0 -1em; | |
border-right: 1px solid #ddd; | |
text-align: right; | |
span { | |
display: block; | |
padding: 0 .5em 0 1em; | |
color: #ccc; | |
} | |
} | |
.cl { | |
display: block; | |
clear: both; | |
} | |
} |
Note: Not JQuery...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
for copy button