diff --git a/diff2html.js b/diff2html.js index 0a1756c..c8e4344 100644 --- a/diff2html.js +++ b/diff2html.js @@ -66,6 +66,8 @@ /* create file structure */ currentFile = {}; currentFile.blocks = []; + currentFile.deletedLines = 0, + currentFile.addedLines = 0; /* save file paths, before and after the diff */ var values = /^diff --git a\/(\S+) b\/(\S+).*$/.exec(line); @@ -88,8 +90,9 @@ currentBlock.lines = []; currentBlock.oldStartLine = oldLine = values[2]; currentBlock.newStartLine = newLine = values[4]; - currentBlock.deletedLines = values[3]; - currentBlock.addedLines = values[5]; + /* update file added and deleted lines */ + currentFile.deletedLines += currentBlock.deletedLines = parseInt(values[3], 10); + currentFile.addedLines += currentBlock.addedLines = parseInt(values[5], 10); /* create block header line */ var currentLine = {}; @@ -150,6 +153,10 @@ return "
" + "
" + + "
" + + " +" + file.addedLines + "" + + " -" + file.deletedLines + "" + + "
" + "
" + fileHeader + "
" + "
" + "
" + diff --git a/style.css b/style.css index 875457c..4298065 100644 --- a/style.css +++ b/style.css @@ -34,12 +34,38 @@ body { } .file-name { + display: inline-block; font: 13px Helvetica, arial, freesans, clean, sans-serif, "Segoe UI Emoji", "Segoe UI Symbol"; line-height: 1.4; height: 33px; line-height: 33px; } +.file-stats { + display: inline-block; + font-family: monospace,monospace; + font-size: 12px; + vertical-align: middle; +} + +.lines-added { + background-color: #ceffce; + border-color: #b4e2b4; + border: 1px solid; + color: #399839; + border-radius: 5px 0 0 5px; + padding: 5px; +} + +.lines-deleted { + background-color: #f7c8c8; + border-color: #e9aeae; + border: 1px solid; + color: #c33; + border-radius: 0 5px 5px 0; + padding: 5px; +} + .file-diff { overflow: auto; }