diff --git a/diff2html.js b/diff2html.js index d9b342b..a346b89 100644 --- a/diff2html.js +++ b/diff2html.js @@ -3,7 +3,7 @@ * Diff to HTML (diff2html.js) * Author: rtfpessoa * Date: Friday 29 August 2014 - * Last Update: Sunday 25 January 2015 + * Last Update: Sunday 2 February 2015 * * Diff command: * git diff @@ -165,6 +165,9 @@ currentFile.oldName = values[1]; } else if (currentFile && !currentFile.newName && (values = /^\+\+\+ b\/(\S+).*$/.exec(line))) { currentFile.newName = values[1]; + + var fileSplit = currentFile.newName.split("."); + currentFile.language = fileSplit[fileSplit.length - 1]; } else if (currentFile && startsWith(line, "@@")) { startBlock(line); } else if (currentBlock) { @@ -185,7 +188,7 @@ var generateJsonHtml = function (diffFiles) { return "
\n" + diffFiles.map(function (file) { - return "
\n" + + return "
\n" + "
\n" + "
\n" + " +" + file.addedLines + "\n" + @@ -270,7 +273,7 @@ diffFiles.map(function (file) { var diffs = generateSideBySideFileHtml(file); - return "
\n" + + return "
\n" + "
\n" + "
\n" + " +" + file.addedLines + "\n" + diff --git a/index.html b/index.html index bffbf42..380122a 100644 --- a/index.html +++ b/index.html @@ -8,7 +8,7 @@ Diff to HTML (template.html) Author: rtfpessoa Date: Friday 29 August 2014 - Last Update: Sunday 25 January 2015 + Last Update: Sunday 2 February 2015 --> @@ -183,6 +183,14 @@ $(document).ready(function () { var diffJson = Diff2Html.getJsonFromDiff(lineDiffExample); + var languages = diffJson.map(function (line) { + return line.language; + }); + var uniqueLanguages = languages.filter(function (v, i) { + return languages.indexOf(v) == i; + }); + hljs.configure({languages: uniqueLanguages}); + $("#line-by-line").html(Diff2Html.getPrettyHtmlFromJson(diffJson)); var code = $(".d2h-code-line"); code.map(function (i, line) {