git ssb

30+

cel / git-ssb-web



Commit 94fac4ede25741324d83db694a7252b79325a855

Catch error if highlight fails

cel committed on 11/30/2016, 1:43:31 PM
Parent: 6086011c37856d731385a00682e6f7fc4c01ed4b

Files changed

lib/util.jschanged
lib/util.jsView
@@ -14,9 +14,10 @@
1414 bmp: 'image/bmp'
1515 }
1616
1717 u.getExtension = function(filename) {
18- return (/\.([^.]+)$/.exec(filename) || [,filename])[1]
18 + var m = /\.([^.]+)$/.exec(filename)
19 + return m && m[1]
1920 }
2021
2122 u.readNext = function (fn) {
2223 var next
@@ -111,11 +112,17 @@
111112 }).join('')
112113 }
113114
114115 u.highlight = function(code, lang) {
116 + if (!lang && /^#!\/bin\/[^\/]*sh$/m.test(code)) lang = 'sh'
115117 if (!lang || code.length > 100000) return u.escape(code)
116118 // 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 + }
118125 }
119126
120127 u.pre = function (text) {
121128 return '<pre>' + u.escape(text) + '</pre>'

Built with git-ssb-web