-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathprism-treeview.js
64 lines (60 loc) · 1.31 KB
/
prism-treeview.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
Prism.languages.treeview = {
"treeview-part": {
pattern: /(^|\n).+/,
inside: {
"entry-line": [
{
pattern: /\|-- |├── /,
alias: "line-h"
},
{
pattern: /\| |│ /,
alias: "line-v"
},
{
pattern: /`-- |└── /,
alias: "line-v-last"
},
{
pattern: / {4}/,
alias: "line-v-gap"
}
],
"entry-name": {
pattern: /.*\S.*/,
inside: {
// symlink
"operator": / -> /,
}
}
}
}
};
Prism.hooks.add('wrap', function(env) {
if (env.language === 'treeview') {
// Remove line breaks
if(env.type === 'treeview-part') {
env.content = env.content.replace(/\n/g,'')+'<br />';
}
if(env.type === 'entry-name') {
if(/(^|[^\\])\/\s*$/.test(env.content)) {
env.content = env.content.slice(0,-1);
// This is a folder
env.classes.push('dir');
} else {
if(/(^|[^\\])[=*|]\s*$/.test(env.content)) {
env.content = env.content.slice(0,-1);
}
var parts = env.content.toLowerCase().split('.');
while (parts.length > 1) {
parts.shift();
// Ex. 'foo.min.js' would become '<span class="token keyword ext-min-js ext-js">foo.min.js</span>'
env.classes.push('ext-' + parts.join('-'));
}
if(env.content.charAt(0)==='.') {
env.classes.push('dotfile');
}
}
}
}
});