git ssb

30+

cel / git-ssb-web



Commit cfc5b28733448e844b57db879704bbe89187d7b7

Syntax highlight diffs

Charles Lehner committed on 4/2/2016, 2:26:14 AM
Parent: 12f054e8b00dd52e785740807429a28d8ed8200f

Files changed

index.jschanged
index.jsView
@@ -31,8 +31,12 @@
3131 return encodeLink([this.options.repo.id, 'commit', url])
3232 return url
3333 }
3434
35+function getExtension(filename) {
36+ return (/\.([^.]+)$/.exec(filename) || [,filename])[1]
37+}
38+
3539 function highlight(code, lang) {
3640 return lang
3741 ? Highlight.highlight(lang, code).value
3842 : Highlight.highlightAuto(code).value
@@ -700,9 +704,9 @@
700704 )
701705 }
702706
703707 function renderObjectData(obj, filename, repo) {
704- var ext = (/\.([^.]+)$/.exec(filename) || [,filename])[1]
708+ var ext = getExtension(filename)
705709 return readOnce(function (cb) {
706710 readObjectString(obj, function (err, buf) {
707711 buf = buf.toString('utf8')
708712 if (err) return cb(err)
@@ -1344,9 +1348,9 @@
13441348 '</td></tr>'
13451349 return [header].concat(hunk.lines.map(function (line) {
13461350 var s = line[0]
13471351 if (s == '\\') return
1348- var html = escapeHTML(line)
1352+ var html = highlight(line, getExtension(filename))
13491353 var trClass = s == '+' ? 'diff-new' : s == '-' ? 'diff-old' : ''
13501354 var lineNums = [s == '+' ? '' : oldLine++, s == '-' ? '' : newLine++]
13511355 var id = [filename].concat(lineNums).join('-')
13521356 return '<tr id="' + escapeHTML(id) + '" class="' + trClass + '">' +

Built with git-ssb-web