diff --git a/diff2html.css b/diff2html.css index f5823f0..8c7ba1b 100644 --- a/diff2html.css +++ b/diff2html.css @@ -3,7 +3,7 @@ * Diff to HTML (diff2html.css) * Author: rtfpessoa * Date: Friday 29 August 2014 - * Last Update: Sunday 14 September 2014 + * Last Update: Saturday 27 September 2014 * */ @@ -109,7 +109,7 @@ display: inline-block; margin-top: -1px; text-decoration: none; - background-color: #f99; + background-color: #ffb6ba; font-weight: 700; border-radius: 0.2em; } @@ -119,7 +119,7 @@ display: inline-block; margin-top: -1px; text-decoration: none; - background-color: #6f7; + background-color: #97f295; font-weight: 700; border-radius: 0.2em; } @@ -174,12 +174,12 @@ } .d2h-del { - background-color: #f7c8c8; + background-color: #fee8e9; border-color: #e9aeae; } .d2h-ins { - background-color: #ceffce; + background-color: #dfd; border-color: #b4e2b4; } diff --git a/diff2html.js b/diff2html.js index a26c22c..5983a76 100644 --- a/diff2html.js +++ b/diff2html.js @@ -3,10 +3,10 @@ * Diff to HTML (diff2html.js) * Author: rtfpessoa * Date: Friday 29 August 2014 - * Last Update: Sunday 14 September 2014 + * Last Update: Saturday 27 September 2014 * * Diff command: - * git diff --word-diff-regex=. HEAD~1 + * git diff */ (function (window) { @@ -16,14 +16,8 @@ var LINE_TYPE = { INSERTS: "d2h-ins", - ALL_NEW: "d2h-all-ins", - DELETES: "d2h-del", - ALL_DELETED: "d2h-all-del", - - INSERTS_AND_DELETES: "d2h-ins-and-del", CONTEXT: "d2h-cntx", - INFO: "d2h-info" }; @@ -127,74 +121,34 @@ }; var createLine = function (line) { - /* Line Types */ - var isLineWithInserts = /{\+.*?\+}/.exec(line); - var isNewLine = /^{\+.*?\+}$/.exec(line); - - var isLineWithDeletes = /\[-.*?-\]/.exec(line); - var isRemovedLine = /^\[-.*?-\]$/.exec(line); - - var isLineWithBoth = isLineWithInserts && isLineWithDeletes; - var isContextLine = !isLineWithInserts && !isLineWithDeletes; - var currentLine = {}; currentLine.content = line; /* fill the line data */ - if (isLineWithBoth) { - currentFile.deletedLines++; + if (startsWith(line, "+")) { currentFile.addedLines++; - currentLine.type = LINE_TYPE.INSERTS_AND_DELETES; - currentLine.oldNumber = oldLine++; - currentLine.newNumber = newLine++; - - currentBlock.lines.push(currentLine); - - } else if (isContextLine) { - - currentLine.type = LINE_TYPE.CONTEXT; - currentLine.oldNumber = oldLine++; - currentLine.newNumber = newLine++; - - currentBlock.lines.push(currentLine); - - } else if (isNewLine) { - currentFile.addedLines++; - - currentLine.type = LINE_TYPE.ALL_NEW; + currentLine.type = LINE_TYPE.INSERTS; currentLine.oldNumber = null; currentLine.newNumber = newLine++; currentBlock.lines.push(currentLine); - } else if (isRemovedLine) { + } else if (startsWith(line, "-")) { currentFile.deletedLines++; - currentLine.type = LINE_TYPE.ALL_DELETED; + currentLine.type = LINE_TYPE.DELETES; currentLine.oldNumber = oldLine++; currentLine.newNumber = null; currentBlock.lines.push(currentLine); - } else if (isLineWithInserts) { - currentFile.addedLines++; - - currentLine.type = LINE_TYPE.INSERTS; + } else { + currentLine.type = LINE_TYPE.CONTEXT; currentLine.oldNumber = oldLine++; currentLine.newNumber = newLine++; currentBlock.lines.push(currentLine); - - } else if (isLineWithDeletes) { - currentFile.deletedLines++; - - currentLine.type = LINE_TYPE.DELETES; - currentLine.oldNumber = oldLine++; - currentLine.newNumber = newLine++; - - currentBlock.lines.push(currentLine); - } }; @@ -256,75 +210,47 @@ var generateFileHtml = function (file) { return file.blocks.map(function (block) { - return "