Skip to content

Commit a8ff004

Browse files
committed
Changed the structure of the suffix-brush mapping, so the code is much simpler and faster.
1 parent 3ee7fb3 commit a8ff004

File tree

1 file changed

+86
-24
lines changed

1 file changed

+86
-24
lines changed

html/views/fileview/fileview.js

Lines changed: 86 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,98 @@
11
var showFile = function(txt, fileName) {
22
$("source").style.display = "";
33
var suffix_map = {
4-
"objc": ["m", "h"],
5-
"ruby": ["rb", "rbx", "rjs", "Rakefile", "rake", "gemspec", "irbrc", "capfile"],
6-
"xml": ['xml', 'tld', 'jsp', 'pt', 'cpt', 'dtml', 'rss', 'opml', 'xsl', 'xslt'],
7-
"javascript": ['js', 'htc', 'jsx', 'jscript', 'javascript'],
8-
"sql": ['sql', 'ddl', 'dml'],
9-
"sass": ['sass', 'scss'],
10-
"bash": ['sh', 'bash', 'zsh', 'bashrc', 'bash_profile', 'bash_login', 'profile', 'bash_logout'],
11-
"diff": ['diff', 'patch'],
12-
"java": ['java', 'bsh'],
13-
"css": ['css', 'css.erb'],
14-
"perl": ['pl', 'pm', 'pod', 't', 'PL'],
15-
"erlang": ['erl', 'hrl'],
16-
"php": ['php'],
17-
"python": ['py', 'rpy', 'pyw', 'cpy', 'SConstruct', 'Sconstruct', 'sconstruct', 'SConscript'],
18-
"cpp": ['cc', 'cpp', 'cp', 'cxx', 'c++', 'C', 'h', 'hh', 'hpp', 'h++', 'c']
4+
"m": "objc",
5+
"h": "objc",
6+
7+
"rb": "ruby",
8+
"rbx": "ruby",
9+
"rjs": "ruby",
10+
"Rakefile": "ruby",
11+
"rake": "ruby",
12+
"gemspec": "ruby",
13+
"irbrc": "ruby",
14+
"capfile": "ruby",
15+
16+
"xml": "xml",
17+
"tld": "xml",
18+
"jsp": "xml",
19+
"pt": "xml",
20+
"cpt": "xml",
21+
"dtml": "xml",
22+
"rss": "xml",
23+
"opml": "xml",
24+
"xsl": "xml",
25+
"xslt": "xml",
26+
27+
"js": "javascript",
28+
"htc": "javascript",
29+
"jsx": "javascript",
30+
"jscript": "javascript",
31+
"javascript": "javascript",
32+
33+
"sql": "sql",
34+
"ddl": "sql",
35+
"dml": "sql",
36+
37+
"sass": "sass",
38+
"scss": "sass",
39+
40+
"sh": "bash",
41+
"bash": "bash",
42+
"zsh": "bash",
43+
"bashrc": "bash",
44+
"bash_profile": "bash",
45+
"bash_login": "bash",
46+
"profile": "bash",
47+
"bash_logout": "bash",
48+
49+
"diff": "diff",
50+
"patch": "diff",
51+
52+
"java": "java",
53+
"bsh": "java",
54+
55+
"css": "css",
56+
"css": "css.erb",
57+
"pl": "perl",
58+
"pm": "perl",
59+
"pod": "perl",
60+
"t": "perl",
61+
"PL": "perl",
62+
63+
"erl": "erlang",
64+
"hrl": "erlang",
65+
66+
"php": "php",
67+
68+
"py": "python",
69+
"rpy": "python",
70+
"pyw": "python",
71+
"cpy": "python",
72+
"SConstruct": "python",
73+
"Sconstruct": "python",
74+
"sconstruct": "python",
75+
"SConscript": "python",
76+
77+
"cc": "cpp",
78+
"cpp": "cpp",
79+
"cp": "cpp",
80+
"cxx": "cpp",
81+
"c++":"cpp",
82+
"C": "cpp",
83+
"h": "cpp",
84+
"hh": "cpp",
85+
"hpp": "cpp",
86+
"cpp": "h++",
87+
"c": "cpp"
1988
}
2089
var brush = "objc";
2190
var suffix = "";
2291
if (fileName && fileName != '') {
2392
suffix = fileName.substr(fileName.lastIndexOf('.') + 1);
2493
}
25-
var keys = get_keys(suffix_map);
26-
for (var key in keys) {
27-
var suffixes = suffix_map[key];
28-
for (var possible_suffix in suffixes) {
29-
if (possible_suffix == suffix) {
30-
brush = key;
31-
}
32-
}
33-
}
94+
95+
brush = suffix_map[suffix];
3496

3597
$("source").innerHTML="<pre class='first-line: 1;brush: " + brush + "'>" + txt + "</pre>";
3698

0 commit comments

Comments
 (0)