Skip to content

Commit 326fa42

Browse files
committed
better hightlight
1 parent f21492f commit 326fa42

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

dist/template.html

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,25 @@
88
Diff to HTML (template.html)
99
Author: rtfpessoa
1010
Date: Friday 29 August 2014
11-
Last Update: Sunday 25 January 2015
11+
Last Update: Sunday 2 February 2015
1212
-->
1313

1414
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.4/styles/default.min.css">
1515
<link rel="stylesheet" type="text/css" href="{{css}}">
1616

17-
1817
<script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
1918
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.4/highlight.min.js"></script>
2019
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.4/languages/scala.min.js"></script>
2120
<script>
2221
$(document).ready(function () {
22+
var languages = $(".d2h-file-wrapper").map(function (i, file) {
23+
return $(file).data("lang");
24+
});
25+
var uniqueLanguages = languages.filter(function (i, v) {
26+
return $.inArray(v, languages) == i;
27+
});
28+
hljs.configure({languages: uniqueLanguages.toArray()});
29+
2330
var code = $(".d2h-code-line");
2431
code.map(function (i, line) {
2532
hljs.highlightBlock(line);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "diff2html",
3-
"version": "0.1.6-3",
3+
"version": "0.1.7",
44

55
"homepage": "https://www.github.com/rtfpessoa/diff2html-nodejs",
66
"description": "Fast Diff to colorized HTML",

src/diff2html.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Diff to HTML (diff2html.js)
44
* Author: rtfpessoa
55
* Date: Friday 29 August 2014
6-
* Last Update: Sunday 25 January 2015
6+
* Last Update: Sunday 2 February 2015
77
*
88
* Diff commands:
99
* git diff
@@ -167,6 +167,9 @@ module.exports = (function () {
167167
currentFile.oldName = values[1];
168168
} else if (currentFile && !currentFile.newName && (values = /^\+\+\+ b\/(\S+).*$/.exec(line))) {
169169
currentFile.newName = values[1];
170+
171+
var fileSplit = currentFile.newName.split(".");
172+
currentFile.language = fileSplit[fileSplit.length - 1];
170173
} else if (currentFile && startsWith(line, "@@")) {
171174
startBlock(line);
172175
} else if (currentBlock) {
@@ -187,7 +190,7 @@ module.exports = (function () {
187190
var generateJsonHtml = function (diffFiles) {
188191
return "<div class=\"d2h-wrapper\">\n" +
189192
diffFiles.map(function (file) {
190-
return "<div class=\"d2h-file-wrapper\">\n" +
193+
return "<div class=\"d2h-file-wrapper\" data-lang=\"" + file.language + "\">\n" +
191194
" <div class=\"d2h-file-header\">\n" +
192195
" <div class=\"d2h-file-stats\">\n" +
193196
" <span class=\"d2h-lines-added\">+" + file.addedLines + "</span>\n" +
@@ -272,7 +275,7 @@ module.exports = (function () {
272275
diffFiles.map(function (file) {
273276
var diffs = generateSideBySideFileHtml(file);
274277

275-
return "<div class=\"d2h-file-wrapper\">\n" +
278+
return "<div class=\"d2h-file-wrapper\" data-lang=\"" + file.language + "\">\n" +
276279
" <div class=\"d2h-file-header\">\n" +
277280
" <div class=\"d2h-file-stats\">\n" +
278281
" <span class=\"d2h-lines-added\">+" + file.addedLines + "</span>\n" +

0 commit comments

Comments
 (0)