-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
35 lines (30 loc) · 1.03 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
$(document).ready(function() {
// Remove beginning whitespace from each line on code block elements.
// This code assumes that each code block uses only spaces as indentations.
// It also assumes that the first non-space of the first line is the
// normalization point.
$('pre code').text(function(i, text) {
const lines = text.split('\n');
let firstLine = null;
let firstLineIndex = -1;
for (let i = 0; i < lines.length; i++) {
if (lines[i].length > 0) {
firstLine = lines[i];
firstLineIndex = i;
break;
}
}
let firstIndex = 0;
for (let i = 0; i < firstLine.length; i++) {
if (firstLine.charAt(i) != ' ') {
firstIndex = i;
break;
}
}
const newText = lines.slice(firstLineIndex).map(function(line) {
return line.slice(firstIndex);
}).join('\n');
return newText;
});
hljs.initHighlighting();
});