Commit cfc5b28733448e844b57db879704bbe89187d7b7
Syntax highlight diffs
Charles Lehner committed on 4/2/2016, 2:26:14 AMParent: 12f054e8b00dd52e785740807429a28d8ed8200f
Files changed
index.js | changed |
index.js | ||
---|---|---|
@@ -31,8 +31,12 @@ | ||
31 | 31 | return encodeLink([this.options.repo.id, 'commit', url]) |
32 | 32 | return url |
33 | 33 | } |
34 | 34 | |
35 | +function getExtension(filename) { | |
36 | + return (/\.([^.]+)$/.exec(filename) || [,filename])[1] | |
37 | +} | |
38 | + | |
35 | 39 | function highlight(code, lang) { |
36 | 40 | return lang |
37 | 41 | ? Highlight.highlight(lang, code).value |
38 | 42 | : Highlight.highlightAuto(code).value |
@@ -700,9 +704,9 @@ | ||
700 | 704 | ) |
701 | 705 | } |
702 | 706 | |
703 | 707 | function renderObjectData(obj, filename, repo) { |
704 | - var ext = (/\.([^.]+)$/.exec(filename) || [,filename])[1] | |
708 | + var ext = getExtension(filename) | |
705 | 709 | return readOnce(function (cb) { |
706 | 710 | readObjectString(obj, function (err, buf) { |
707 | 711 | buf = buf.toString('utf8') |
708 | 712 | if (err) return cb(err) |
@@ -1344,9 +1348,9 @@ | ||
1344 | 1348 | '</td></tr>' |
1345 | 1349 | return [header].concat(hunk.lines.map(function (line) { |
1346 | 1350 | var s = line[0] |
1347 | 1351 | if (s == '\\') return |
1348 | - var html = escapeHTML(line) | |
1352 | + var html = highlight(line, getExtension(filename)) | |
1349 | 1353 | var trClass = s == '+' ? 'diff-new' : s == '-' ? 'diff-old' : '' |
1350 | 1354 | var lineNums = [s == '+' ? '' : oldLine++, s == '-' ? '' : newLine++] |
1351 | 1355 | var id = [filename].concat(lineNums).join('-') |
1352 | 1356 | return '<tr id="' + escapeHTML(id) + '" class="' + trClass + '">' + |
Built with git-ssb-web