Commit 94fac4ede25741324d83db694a7252b79325a855
Catch error if highlight fails
cel committed on 11/30/2016, 1:43:31 PMParent: 6086011c37856d731385a00682e6f7fc4c01ed4b
Files changed
lib/util.js | changed |
lib/util.js | |||
---|---|---|---|
@@ -14,9 +14,10 @@ | |||
14 | 14 … | bmp: 'image/bmp' | |
15 | 15 … | } | |
16 | 16 … | ||
17 | 17 … | u.getExtension = function(filename) { | |
18 | - return (/\.([^.]+)$/.exec(filename) || [,filename])[1] | ||
18 … | + var m = /\.([^.]+)$/.exec(filename) | ||
19 … | + return m && m[1] | ||
19 | 20 … | } | |
20 | 21 … | ||
21 | 22 … | u.readNext = function (fn) { | |
22 | 23 … | var next | |
@@ -111,11 +112,17 @@ | |||
111 | 112 … | }).join('') | |
112 | 113 … | } | |
113 | 114 … | ||
114 | 115 … | u.highlight = function(code, lang) { | |
116 … | + if (!lang && /^#!\/bin\/[^\/]*sh$/m.test(code)) lang = 'sh' | ||
115 | 117 … | if (!lang || code.length > 100000) return u.escape(code) | |
116 | 118 … | // auto highlighting removed because it was causing highlight.js to hang | |
117 | - return Highlight.highlight(lang, code).value | ||
119 … | + try { | ||
120 … | + return Highlight.highlight(lang, code).value | ||
121 … | + } catch(e) { | ||
122 … | + console.error('highlight:', e) | ||
123 … | + return u.escape(code) | ||
124 … | + } | ||
118 | 125 … | } | |
119 | 126 … | ||
120 | 127 … | u.pre = function (text) { | |
121 | 128 … | return '<pre>' + u.escape(text) + '</pre>' |
Built with git-ssb-web