diff --git a/diff2html.css b/diff2html.css index d75dccc..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: Saturday 6 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; } @@ -128,12 +128,16 @@ display: inline-block; float: left; width: 30px; + overflow: hidden; + text-overflow: ellipsis; } .line-num2 { display: inline-block; float: right; width: 30px; + overflow: hidden; + text-overflow: ellipsis; } .d2h-code-linenumber { @@ -154,8 +158,7 @@ .d2h-code-side-linenumber { position: absolute; - width: 2%; - min-width: 35px; + width: 35px; padding-left: 10px; padding-right: 10px; height: 18px; @@ -166,15 +169,17 @@ border: solid #eeeeee; border-width: 0 1px 0 1px; cursor: pointer; + overflow: hidden; + text-overflow: ellipsis; } .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 6e13907..c29d4f5 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: Saturday 6 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" }; @@ -52,6 +46,14 @@ return generateJsonHtml(diffJson); }; + /* + * Generates pretty side by side html from string diff input + */ + Diff2Html.prototype.getPrettySideBySideHtmlFromDiff = function (diffInput) { + var diffJson = generateDiffJson(diffInput); + return generateSideBySideJsonHtml(diffJson); + }; + /* * Generates pretty side by side html from a json object */ @@ -119,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); - } }; @@ -248,75 +210,53 @@ var generateFileHtml = function (file) { return file.blocks.map(function (block) { - return "