-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpretty.js
More file actions
39 lines (34 loc) · 1.05 KB
/
pretty.js
File metadata and controls
39 lines (34 loc) · 1.05 KB
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
36
37
38
39
const Pretty = (el) => {
el.style.margin = '0.5ch';
el.style.fontFamily = 'monospace';
el.style.fontSize = '1.5em';
el.style.background = '#000';
el.style.color = '#fff';
let dent = '';
const print = (str) => {
el.innerHTML += dent + str
.replace(/&/g, '&')
.replace(/>/g, '>')
.replace(/</g, '<')
.replace(/ /g, ' ')
.replace(/\n/g, '<br>' + dent)
.replace(/\\\[([^\]]+)\]/g, '<span style="$1">')
.replace(/\\/g, '</span>')
;
};
const println = (str) => {
print(str + '\n');
};
const dentchars = ' ';
const indent = (amnt=1) => {
dent = [...Array(dent.length/dentchars.length + amnt)].map(e => dentchars).join('');
};
const dedent = (amnt=1) => {
dent = [...Array(dent.length/dentchars.length - amnt)].map(e => dentchars).join('');
};
return {
print, println,
indent, dedent,
dent: () => dent,
};
};