Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
function require(){return global}var global=this;!function(global,undefined){var JsDiff=function(){function map(arr,mapper,that){if(Array.prototype.map)return Array.prototype.map.call(arr,mapper,that);for(var other=new Array(arr.length),i=0,n=arr.length;n>i;i++)other[i]=mapper.call(that,arr[i],i,arr);return other}function clonePath(path){return{newPos:path.newPos,components:path.components.slice(0)}}function removeEmpty(array){for(var ret=[],i=0;i<array.length;i++)array[i]&&ret.push(array[i]);return ret}function escapeHTML(s){var n=s;return n=n.replace(/&/g,"&amp;"),n=n.replace(/</g,"&lt;"),n=n.replace(/>/g,"&gt;"),n=n.replace(/"/g,"&quot;")}function buildValues(components,newString,oldString,useLongestToken){for(var componentPos=0,componentLen=components.length,newPos=0,oldPos=0;componentLen>componentPos;componentPos++){var component=components[componentPos];if(component.removed)component.value=oldString.slice(oldPos,oldPos+component.count).join(""),oldPos+=component.count;else{if(!component.added&&useLongestToken){var value=newString.slice(newPos,newPos+component.count);value=map(value,function(value,i){var oldValue=oldString[oldPos+i];return oldValue.length>value.length?oldValue:value}),component.value=value.join("")}else component.value=newString.slice(newPos,newPos+component.count).join("");newPos+=component.count,component.added||(oldPos+=component.count)}}return components}function canonicalize(obj,stack,replacementStack){stack=stack||[],replacementStack=replacementStack||[];for(var i,i=0;i<stack.length;i+=1)if(stack[i]===obj)return replacementStack[i];var canonicalizedObj;if("[object Array]"===objectPrototypeToString.call(obj)){for(stack.push(obj),canonicalizedObj=new Array(obj.length),replacementStack.push(canonicalizedObj),i=0;i<obj.length;i+=1)canonicalizedObj[i]=canonicalize(obj[i],stack,replacementStack);stack.pop(),replacementStack.pop()}else if("object"==typeof obj&&null!==obj){stack.push(obj),canonicalizedObj={},replacementStack.push(canonicalizedObj);var sortedKeys=[];for(var key in obj)sortedKeys.push(key);for(sortedKeys.sort(),i=0;i<sortedKeys.length;i+=1){var key=sortedKeys[i];canonicalizedObj[key]=canonicalize(obj[key],stack,replacementStack)}stack.pop(),replacementStack.pop()}else canonicalizedObj=obj;return canonicalizedObj}var Diff=function(ignoreWhitespace){this.ignoreWhitespace=ignoreWhitespace};Diff.prototype={diff:function(oldString,newString,callback){function done(value){return callback?(setTimeout(function(){callback(undefined,value)},0),!0):value}function execEditLength(){for(var diagonalPath=-1*editLength;editLength>=diagonalPath;diagonalPath+=2){var basePath,addPath=bestPath[diagonalPath-1],removePath=bestPath[diagonalPath+1];oldPos=(removePath?removePath.newPos:0)-diagonalPath,addPath&&(bestPath[diagonalPath-1]=undefined);var canAdd=addPath&&addPath.newPos+1<newLen,canRemove=removePath&&oldPos>=0&&oldLen>oldPos;if(canAdd||canRemove){!canAdd||canRemove&&addPath.newPos<removePath.newPos?(basePath=clonePath(removePath),self.pushComponent(basePath.components,undefined,!0)):(basePath=addPath,basePath.newPos++,self.pushComponent(basePath.components,!0,undefined));var oldPos=self.extractCommon(basePath,newString,oldString,diagonalPath);if(basePath.newPos+1>=newLen&&oldPos+1>=oldLen)return done(buildValues(basePath.components,newString,oldString,self.useLongestToken));bestPath[diagonalPath]=basePath}else bestPath[diagonalPath]=undefined}editLength++}var self=this;if(newString===oldString)return done([{value:newString}]);if(!newString)return done([{value:oldString,removed:!0}]);if(!oldString)return done([{value:newString,added:!0}]);newString=this.tokenize(newString),oldString=this.tokenize(oldString);var newLen=newString.length,oldLen=oldString.length,maxEditLength=newLen+oldLen,bestPath=[{newPos:-1,components:[]}],oldPos=this.extractCommon(bestPath[0],newString,oldString,0);if(bestPath[0].newPos+1>=newLen&&oldPos+1>=oldLen)return done([{value:newString.join("")}]);var editLength=1;if(callback)!function exec(){setTimeout(function(){return editLength>maxEditLength?callback():void(execEditLength()||exec())},0)}();else for(;maxEditLength>=editLength;){var ret=execEditLength();if(ret)return ret}},pushComponent:function(components,added,removed){var last=components[components.length-1];last&&last.added===added&&last.removed===removed?components[components.length-1]={count:last.count+1,added:added,removed:removed}:components.push({count:1,added:added,removed:removed})},extractCommon:function(basePath,newString,oldString,diagonalPath){for(var newLen=newString.length,oldLen=oldString.length,newPos=basePath.newPos,oldPos=newPos-diagonalPath,commonCount=0;newLen>newPos+1&&oldLen>oldPos+1&&this.equals(newString[newPos+1],oldString[oldPos+1]);)newPos++,oldPos++,commonCount++;return commonCount&&basePath.components.push({count:commonCount}),basePath.newPos=newPos,oldPos},equals:function(left,right){var reWhitespace=/\S/;return left===right||this.ignoreWhitespace&&!reWhitespace.test(left)&&!reWhitespace.test(right)},tokenize:function(value){return value.split("")}};var CharDiff=new Diff,WordDiff=new Diff(!0),WordWithSpaceDiff=new Diff;WordDiff.tokenize=WordWithSpaceDiff.tokenize=function(value){return removeEmpty(value.split(/(\s+|\b)/))};var CssDiff=new Diff(!0);CssDiff.tokenize=function(value){return removeEmpty(value.split(/([{}:;,]|\s+)/))};var LineDiff=new Diff,TrimmedLineDiff=new Diff;TrimmedLineDiff.ignoreTrim=!0,LineDiff.tokenize=TrimmedLineDiff.tokenize=function(value){for(var retLines=[],lines=value.split(/^/m),i=0;i<lines.length;i++){var line=lines[i],lastLine=lines[i-1],lastLineLastChar=lastLine?lastLine[lastLine.length-1]:"";"\n"===line&&"\r"===lastLineLastChar?retLines[retLines.length-1]=retLines[retLines.length-1].slice(0,-1)+"\r\n":line&&(this.ignoreTrim&&(line=line.trim(),i<lines.length-1&&(line+="\n")),retLines.push(line))}return retLines};var SentenceDiff=new Diff;SentenceDiff.tokenize=function(value){return removeEmpty(value.split(/(\S.+?[.!?])(?=\s+|$)/))};var JsonDiff=new Diff;JsonDiff.useLongestToken=!0,JsonDiff.tokenize=LineDiff.tokenize,JsonDiff.equals=function(left,right){return LineDiff.equals(left.replace(/,([\r\n])/g,"$1"),right.replace(/,([\r\n])/g,"$1"))};var objectPrototypeToString=Object.prototype.toString;return{Diff:Diff,diffChars:function(oldStr,newStr,callback){return CharDiff.diff(oldStr,newStr,callback)},diffWords:function(oldStr,newStr,callback){return WordDiff.diff(oldStr,newStr,callback)},diffWordsWithSpace:function(oldStr,newStr,callback){return WordWithSpaceDiff.diff(oldStr,newStr,callback)},diffLines:function(oldStr,newStr,callback){return LineDiff.diff(oldStr,newStr,callback)},diffTrimmedLines:function(oldStr,newStr,callback){return TrimmedLineDiff.diff(oldStr,newStr,callback)},diffSentences:function(oldStr,newStr,callback){return SentenceDiff.diff(oldStr,newStr,callback)},diffCss:function(oldStr,newStr,callback){return CssDiff.diff(oldStr,newStr,callback)},diffJson:function(oldObj,newObj,callback){return JsonDiff.diff("string"==typeof oldObj?oldObj:JSON.stringify(canonicalize(oldObj),undefined,"  "),"string"==typeof newObj?newObj:JSON.stringify(canonicalize(newObj),undefined,"  "),callback)},createPatch:function(fileName,oldStr,newStr,oldHeader,newHeader){function contextLines(lines){return map(lines,function(entry){return" "+entry})}function eofNL(curRange,i,current){var last=diff[diff.length-2],isLast=i===diff.length-2,isLastOfType=i===diff.length-3&&(current.added!==last.added||current.removed!==last.removed);/\n$/.test(current.value)||!isLast&&!isLastOfType||curRange.push("\\ No newline at end of file")}var ret=[];ret.push("Index: "+fileName),ret.push("==================================================================="),ret.push("--- "+fileName+("undefined"==typeof oldHeader?"":"	"+oldHeader)),ret.push("+++ "+fileName+("undefined"==typeof newHeader?"":"	"+newHeader));var diff=LineDiff.diff(oldStr,newStr);diff[diff.length-1].value||diff.pop(),diff.push({value:"",lines:[]});for(var oldRangeStart=0,newRangeStart=0,curRange=[],oldLine=1,newLine=1,i=0;i<diff.length;i++){var current=diff[i],lines=current.lines||current.value.replace(/\n$/,"").split("\n");if(current.lines=lines,current.added||current.removed){if(!oldRangeStart){var prev=diff[i-1];oldRangeStart=oldLine,newRangeStart=newLine,prev&&(curRange=contextLines(prev.lines.slice(-4)),oldRangeStart-=curRange.length,newRangeStart-=curRange.length)}curRange.push.apply(curRange,map(lines,function(entry){return(current.added?"+":"-")+entry})),eofNL(curRange,i,current),current.added?newLine+=lines.length:oldLine+=lines.length}else{if(oldRangeStart)if(lines.length<=8&&i<diff.length-2)curRange.push.apply(curRange,contextLines(lines));else{var contextSize=Math.min(lines.length,4);ret.push("@@ -"+oldRangeStart+","+(oldLine-oldRangeStart+contextSize)+" +"+newRangeStart+","+(newLine-newRangeStart+contextSize)+" @@"),ret.push.apply(ret,curRange),ret.push.apply(ret,contextLines(lines.slice(0,contextSize))),lines.length<=4&&eofNL(ret,i,current),oldRangeStart=0,newRangeStart=0,curRange=[]}oldLine+=lines.length,newLine+=lines.length}}return ret.join("\n")+"\n"},applyPatch:function(oldStr,uniDiff){for(var diffstr=uniDiff.split("\n"),diff=[],i=0,remEOFNL=!1,addEOFNL=!1;i<diffstr.length&&!/^@@/.test(diffstr[i]);)i++;for(;i<diffstr.length;i++)if("@"===diffstr[i][0]){var meh=diffstr[i].split(/@@ -(\d+),(\d+) \+(\d+),(\d+) @@/);diff.unshift({start:meh[3],oldlength:meh[2],oldlines:[],newlength:meh[4],newlines:[]})}else"+"===diffstr[i][0]?diff[0].newlines.push(diffstr[i].substr(1)):"-"===diffstr[i][0]?diff[0].oldlines.push(diffstr[i].substr(1)):" "===diffstr[i][0]?(diff[0].newlines.push(diffstr[i].substr(1)),diff[0].oldlines.push(diffstr[i].substr(1))):"\\"===diffstr[i][0]&&("+"===diffstr[i-1][0]?remEOFNL=!0:"-"===diffstr[i-1][0]&&(addEOFNL=!0));for(var str=oldStr.split("\n"),i=diff.length-1;i>=0;i--){for(var d=diff[i],j=0;j<d.oldlength;j++)if(str[d.start-1+j]!==d.oldlines[j])return!1;Array.prototype.splice.apply(str,[d.start-1,+d.oldlength].concat(d.newlines))}if(remEOFNL)for(;!str[str.length-1];)str.pop();else addEOFNL&&str.push("");return str.join("\n")},convertChangesToXML:function(changes){for(var ret=[],i=0;i<changes.length;i++){var change=changes[i];change.added?ret.push("<ins>"):change.removed&&ret.push("<del>"),ret.push(escapeHTML(change.value)),change.added?ret.push("</ins>"):change.removed&&ret.push("</del>")}return ret.join("")},convertChangesToDMP:function(changes){for(var change,ret=[],i=0;i<changes.length;i++)change=changes[i],ret.push([change.added?1:change.removed?-1:0,change.value]);return ret},canonicalize:canonicalize}}();"undefined"!=typeof module&&module.exports?module.exports=JsDiff:"function"==typeof define&&define.amd?define([],function(){return JsDiff}):"undefined"==typeof global.JsDiff&&(global.JsDiff=JsDiff)}(this),function(global,undefined){function Utils(){}Utils.prototype.escape=function(str){return str.slice(0).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/\t/g,"    ")},Utils.prototype.startsWith=function(str,start){return 0===str.indexOf(start)},Utils.prototype.valueOrEmpty=function(value){return value?value:""},"undefined"!=typeof module&&module.exports?module.exports.Utils=new Utils:"undefined"==typeof global.Utils&&(global.Utils=new Utils)}(this),function(global,undefined){function DiffParser(){}function getExtension(filename,language){var nameSplit=filename.split(".");return nameSplit.length>1?nameSplit[nameSplit.length-1]:language}var utils=require("./utils.js").Utils,LINE_TYPE={INSERTS:"d2h-ins",DELETES:"d2h-del",CONTEXT:"d2h-cntx",INFO:"d2h-info"};DiffParser.prototype.LINE_TYPE=LINE_TYPE,DiffParser.prototype.generateDiffJson=function(diffInput){var files=[],currentFile=null,currentBlock=null,oldLine=null,newLine=null,saveBlock=function(){currentBlock&&(currentFile.blocks.push(currentBlock),currentBlock=null)},saveFile=function(){currentFile&&currentFile.newName&&(files.push(currentFile),currentFile=null)},startFile=function(){saveBlock(),saveFile(),currentFile={},currentFile.blocks=[],currentFile.deletedLines=0,currentFile.addedLines=0},startBlock=function(line){saveBlock();var values;(values=/^@@ -(\d+),\d+ \+(\d+),\d+ @@.*/.exec(line))?currentFile.isCombined=!1:(values=/^@@@ -(\d+),\d+ -\d+,\d+ \+(\d+),\d+ @@@.*/.exec(line))?currentFile.isCombined=!0:(values=[0,0],currentFile.isCombined=!1),oldLine=values[1],newLine=values[2],currentBlock={},currentBlock.lines=[],currentBlock.oldStartLine=oldLine,currentBlock.newStartLine=newLine,currentBlock.header=line},createLine=function(line){var currentLine={};currentLine.content=line,utils.startsWith(line,"+")||utils.startsWith(line," +")?(currentFile.addedLines++,currentLine.type=LINE_TYPE.INSERTS,currentLine.oldNumber=null,currentLine.newNumber=newLine++,currentBlock.lines.push(currentLine)):utils.startsWith(line,"-")||utils.startsWith(line," -")?(currentFile.deletedLines++,currentLine.type=LINE_TYPE.DELETES,currentLine.oldNumber=oldLine++,currentLine.newNumber=null,currentBlock.lines.push(currentLine)):(currentLine.type=LINE_TYPE.CONTEXT,currentLine.oldNumber=oldLine++,currentLine.newNumber=newLine++,currentBlock.lines.push(currentLine))},diffLines=diffInput.split("\n");return diffLines.forEach(function(line){if(line&&!utils.startsWith(line,"*")){var oldMode=/^old mode (\d{6})/,newMode=/^new mode (\d{6})/,deletedFileMode=/^deleted file mode (\d{6})/,newFileMode=/^new file mode (\d{6})/,copyFrom=/^copy from (.+)/,copyTo=/^copy to (.+)/,renameFrom=/^rename from (.+)/,renameTo=/^rename to (.+)/,similarityIndex=/^similarity index (\d+)%/,dissimilarityIndex=/^dissimilarity index (\d+)%/,index=/^index ([0-9a-z]+)..([0-9a-z]+) (\d{6})?/,combinedIndex=/^index ([0-9a-z]+),([0-9a-z]+)..([0-9a-z]+)/,combinedMode=/^mode (\d{6}),(\d{6})..(\d{6})/,combinedNewFile=/^new file mode (\d{6})/,combinedDeletedFile=/^deleted file mode (\d{6}),(\d{6})/,values=[];utils.startsWith(line,"diff")?startFile():currentFile&&!currentFile.oldName&&(values=/^--- a\/(\S+).*$/.exec(line))?(currentFile.oldName=values[1],currentFile.language=getExtension(currentFile.oldName,currentFile.language)):currentFile&&!currentFile.newName&&(values=/^\+\+\+ [b]?\/(\S+).*$/.exec(line))?(currentFile.newName=values[1],currentFile.language=getExtension(currentFile.newName,currentFile.language)):currentFile&&utils.startsWith(line,"@@")?startBlock(line):(values=oldMode.exec(line))?currentFile.oldMode=values[1]:(values=newMode.exec(line))?currentFile.newMode=values[1]:(values=deletedFileMode.exec(line))?currentFile.deletedFileMode=values[1]:(values=newFileMode.exec(line))?currentFile.newFileMode=values[1]:(values=copyFrom.exec(line))?(currentFile.oldName=values[1],currentFile.isCopy=!0):(values=copyTo.exec(line))?(currentFile.newName=values[1],currentFile.isCopy=!0):(values=renameFrom.exec(line))?(currentFile.oldName=values[1],currentFile.isRename=!0):(values=renameTo.exec(line))?(currentFile.newName=values[1],currentFile.isRename=!0):(values=similarityIndex.exec(line))?currentFile.unchangedPercentage=values[1]:(values=dissimilarityIndex.exec(line))?currentFile.changedPercentage=values[1]:(values=index.exec(line))?(currentFile.checksumBefore=values[1],currentFile.checksumAfter=values[2],values[2]&&(currentFile.mode=values[3])):(values=combinedIndex.exec(line))?(currentFile.checksumBefore=[values[2],values[3]],currentFile.checksumAfter=values[1]):(values=combinedMode.exec(line))?(currentFile.oldMode=[values[2],values[3]],currentFile.newMode=values[1]):(values=combinedNewFile.exec(line))?currentFile.newFileMode=values[1]:(values=combinedDeletedFile.exec(line))?currentFile.deletedFileMode=values[1]:currentBlock&&createLine(line)}}),saveBlock(),saveFile(),files},"undefined"!=typeof module&&module.exports?module.exports.DiffParser=new DiffParser:"undefined"==typeof global.DiffParser&&(global.DiffParser=new DiffParser)}(this),function(global,undefined){function PrinterUtils(){}function isDeletedName(name){return"dev/null"===name}function removeIns(line){return line.replace(/(<ins>((.|\n)*?)<\/ins>)/g,"")}function removeDel(line){return line.replace(/(<del>((.|\n)*?)<\/del>)/g,"")}var jsDiff="undefined"!=typeof JsDiff&&JsDiff||require("../lib/diff.js"),utils=require("./utils.js").Utils;PrinterUtils.prototype.getDiffName=function(file){var oldFilename=file.oldName,newFilename=file.newName;return oldFilename&&newFilename&&oldFilename!==newFilename&&!isDeletedName(newFilename)?oldFilename+" -> "+newFilename:newFilename&&!isDeletedName(newFilename)?newFilename:oldFilename?oldFilename:"Unknown filename"},PrinterUtils.prototype.diffHighlight=function(diffLine1,diffLine2,config){var lineStart1,lineStart2,prefixSize=1;config.isCombined&&(prefixSize=2),lineStart1=diffLine1.substr(0,prefixSize),lineStart2=diffLine2.substr(0,prefixSize),diffLine1=diffLine1.substr(prefixSize),diffLine2=diffLine2.substr(prefixSize);var diff;diff=config.charByChar?jsDiff.diffChars(diffLine1,diffLine2):jsDiff.diffWordsWithSpace(diffLine1,diffLine2);var highlightedLine="";return diff.forEach(function(part){var elemType=part.added?"ins":part.removed?"del":null,escapedValue=utils.escape(part.value);highlightedLine+=null!==elemType?"<"+elemType+">"+escapedValue+"</"+elemType+">":escapedValue}),{first:{prefix:lineStart1,line:removeIns(highlightedLine)},second:{prefix:lineStart2,line:removeDel(highlightedLine)}}},"undefined"!=typeof module&&module.exports?module.exports.PrinterUtils=new PrinterUtils:"undefined"==typeof global.PrinterUtils&&(global.PrinterUtils=new PrinterUtils)}(this),function(global,undefined){function SideBySidePrinter(){}function generateSideBySideFileHtml(file,config){var fileHtml={};return fileHtml.left="",fileHtml.right="",file.blocks.forEach(function(block){fileHtml.left+='<tr>\n  <td class="d2h-code-side-linenumber '+diffParser.LINE_TYPE.INFO+'"></td>\n  <td class="'+diffParser.LINE_TYPE.INFO+'">    <div class="d2h-code-side-line '+diffParser.LINE_TYPE.INFO+'">'+utils.escape(block.header)+"</div>  </td>\n</tr>\n",fileHtml.right+='<tr>\n  <td class="d2h-code-side-linenumber '+diffParser.LINE_TYPE.INFO+'"></td>\n  <td class="'+diffParser.LINE_TYPE.INFO+'">    <div class="d2h-code-side-line '+diffParser.LINE_TYPE.INFO+'"></div>  </td>\n</tr>\n';for(var oldLines=[],newLines=[],tmpHtml="",i=0;i<block.lines.length;i++){var line=block.lines[i],escapedLine=utils.escape(line.content);if(line.type!=diffParser.LINE_TYPE.CONTEXT||oldLines.length||newLines.length)if(line.type!=diffParser.LINE_TYPE.INSERTS||oldLines.length||newLines.length)if(line.type!=diffParser.LINE_TYPE.DELETES||newLines.length)if(line.type==diffParser.LINE_TYPE.INSERTS&&oldLines.length>newLines.length)newLines.push(line);else{var oldLine,newLine,j=0;if(oldLines.length===newLines.length)for(j=0;j<oldLines.length;j++){oldLine=oldLines[j],newLine=newLines[j],config.isCombined=file.isCombined;var diff=printerUtils.diffHighlight(oldLine.content,newLine.content,config);fileHtml.left+=generateSingleLineHtml(oldLine.type,oldLine.oldNumber,diff.first.line,diff.first.prefix),fileHtml.right+=generateSingleLineHtml(newLine.type,newLine.newNumber,diff.second.line,diff.second.prefix)}else tmpHtml=processLines(oldLines,newLines),fileHtml.left+=tmpHtml.left,fileHtml.right+=tmpHtml.right;oldLines=[],newLines=[],i--}else oldLines.push(line);else fileHtml.left+=generateSingleLineHtml(diffParser.LINE_TYPE.CONTEXT,"","",""),fileHtml.right+=generateSingleLineHtml(line.type,line.newNumber,escapedLine);else fileHtml.left+=generateSingleLineHtml(line.type,line.oldNumber,escapedLine),fileHtml.right+=generateSingleLineHtml(line.type,line.newNumber,escapedLine)}tmpHtml=processLines(oldLines,newLines),fileHtml.left+=tmpHtml.left,fileHtml.right+=tmpHtml.right}),fileHtml}function processLines(oldLines,newLines){var fileHtml={};fileHtml.left="",fileHtml.right="";var maxLinesNumber=Math.max(oldLines.length,newLines.length);for(j=0;j<maxLinesNumber;j++){var oldLine=oldLines[j],newLine=newLines[j];oldLine&&newLine?(fileHtml.left+=generateSingleLineHtml(oldLine.type,oldLine.oldNumber,utils.escape(oldLine.content)),fileHtml.right+=generateSingleLineHtml(newLine.type,newLine.newNumber,utils.escape(newLine.content))):oldLine?(fileHtml.left+=generateSingleLineHtml(oldLine.type,oldLine.oldNumber,utils.escape(oldLine.content)),fileHtml.right+=generateSingleLineHtml(diffParser.LINE_TYPE.CONTEXT,"","","")):newLine?(fileHtml.left+=generateSingleLineHtml(diffParser.LINE_TYPE.CONTEXT,"","",""),fileHtml.right+=generateSingleLineHtml(newLine.type,newLine.newNumber,utils.escape(newLine.content))):console.error("How did it get here?")}return fileHtml}function generateSingleLineHtml(type,number,content,prefix){var htmlPrefix="";prefix&&(htmlPrefix='<span class="d2h-code-line-prefix">'+prefix+"</span>");var htmlContent="";return content&&(htmlContent='<span class="d2h-code-line-ctn">'+content+"</span>"),'<tr>\n    <td class="d2h-code-side-linenumber '+type+'">'+number+'</td>\n    <td class="'+type+'">      <div class="d2h-code-side-line '+type+'">'+htmlPrefix+htmlContent+"</div>    </td>\n  </tr>\n"}function generateEmptyDiff(){var fileHtml={};return fileHtml.right="",fileHtml.left='<tr>\n  <td class="'+diffParser.LINE_TYPE.INFO+'">    <div class="d2h-code-side-line '+diffParser.LINE_TYPE.INFO+'">File without changes    </div>  </td>\n</tr>\n',fileHtml}var diffParser=require("./diff-parser.js").DiffParser,printerUtils=require("./printer-utils.js").PrinterUtils,utils=require("./utils.js").Utils;SideBySidePrinter.prototype.generateSideBySideJsonHtml=function(diffFiles,config){return'<div class="d2h-wrapper">\n'+diffFiles.map(function(file){var diffs;return diffs=file.blocks.length?generateSideBySideFileHtml(file,config):generateEmptyDiff(),'<div class="d2h-file-wrapper" data-lang="'+file.language+'">\n     <div class="d2h-file-header">\n       <div class="d2h-file-stats">\n         <span class="d2h-lines-added">+'+file.addedLines+'</span>\n         <span class="d2h-lines-deleted">-'+file.deletedLines+'</span>\n       </div>\n       <div class="d2h-file-name">'+printerUtils.getDiffName(file)+'</div>\n     </div>\n     <div class="d2h-files-diff">\n       <div class="d2h-file-side-diff">\n         <div class="d2h-code-wrapper">\n           <table class="d2h-diff-table">\n             <tbody class="d2h-diff-tbody">\n           '+diffs.left+'             </tbody>\n           </table>\n         </div>\n       </div>\n       <div class="d2h-file-side-diff">\n         <div class="d2h-code-wrapper">\n           <table class="d2h-diff-table">\n             <tbody class="d2h-diff-tbody">\n           '+diffs.right+"             </tbody>\n           </table>\n         </div>\n       </div>\n     </div>\n   </div>\n"}).join("\n")+"</div>\n"},"undefined"!=typeof module&&module.exports?module.exports.SideBySidePrinter=new SideBySidePrinter:"undefined"==typeof global.SideBySidePrinter&&(global.SideBySidePrinter=new SideBySidePrinter)}(this),function(global,undefined){function LineByLinePrinter(){}function generateFileHtml(file,config){return file.blocks.map(function(block){for(var lines='<tr>\n  <td class="d2h-code-linenumber '+diffParser.LINE_TYPE.INFO+'"></td>\n  <td class="'+diffParser.LINE_TYPE.INFO+'">    <div class="d2h-code-line '+diffParser.LINE_TYPE.INFO+'">'+utils.escape(block.header)+"</div>  </td>\n</tr>\n",oldLines=[],newLines=[],processedOldLines=[],processedNewLines=[],i=0;i<block.lines.length;i++){var line=block.lines[i],escapedLine=utils.escape(line.content);if(line.type!=diffParser.LINE_TYPE.CONTEXT||oldLines.length||newLines.length)if(line.type!=diffParser.LINE_TYPE.INSERTS||oldLines.length||newLines.length)if(line.type!=diffParser.LINE_TYPE.DELETES||newLines.length)if(line.type==diffParser.LINE_TYPE.INSERTS&&oldLines.length>newLines.length)newLines.push(line);else{var oldLine,newLine,j=0;if(oldLines.length===newLines.length){for(j=0;j<oldLines.length;j++){oldLine=oldLines[j],newLine=newLines[j],config.isCombined=file.isCombined;var diff=printerUtils.diffHighlight(oldLine.content,newLine.content,config);processedOldLines+=generateLineHtml(oldLine.type,oldLine.oldNumber,oldLine.newNumber,diff.first.line,diff.first.prefix),processedNewLines+=generateLineHtml(newLine.type,newLine.oldNumber,newLine.newNumber,diff.second.line,diff.second.prefix)}lines+=processedOldLines+processedNewLines}else lines+=processLines(oldLines,newLines);oldLines=[],newLines=[],processedOldLines=[],processedNewLines=[],i--}else oldLines.push(line);else lines+=generateLineHtml(line.type,line.oldNumber,line.newNumber,escapedLine);else lines+=generateLineHtml(line.type,line.oldNumber,line.newNumber,escapedLine)}return lines+=processLines(oldLines,newLines)}).join("\n")}function processLines(oldLines,newLines){var lines="";for(j=0;j<oldLines.length;j++){var oldLine=oldLines[j],oldEscapedLine=utils.escape(oldLine.content);lines+=generateLineHtml(oldLine.type,oldLine.oldNumber,oldLine.newNumber,oldEscapedLine)}for(j=0;j<newLines.length;j++){var newLine=newLines[j],newEscapedLine=utils.escape(newLine.content);lines+=generateLineHtml(newLine.type,newLine.oldNumber,newLine.newNumber,newEscapedLine)}return lines}function generateLineHtml(type,oldNumber,newNumber,content,prefix){var htmlPrefix="";prefix&&(htmlPrefix='<span class="d2h-code-line-prefix">'+prefix+"</span>");var htmlContent="";return content&&(htmlContent='<span class="d2h-code-line-ctn">'+content+"</span>"),'<tr>\n  <td class="d2h-code-linenumber '+type+'">    <div class="line-num1">'+utils.valueOrEmpty(oldNumber)+'</div>    <div class="line-num2">'+utils.valueOrEmpty(newNumber)+'</div>  </td>\n  <td class="'+type+'">    <div class="d2h-code-line '+type+'">'+htmlPrefix+htmlContent+"</div>  </td>\n</tr>\n"}function generateEmptyDiff(){return'<tr>\n  <td class="'+diffParser.LINE_TYPE.INFO+'">    <div class="d2h-code-line '+diffParser.LINE_TYPE.INFO+'">File without changes    </div>  </td>\n</tr>\n'}var diffParser=require("./diff-parser.js").DiffParser,printerUtils=require("./printer-utils.js").PrinterUtils,utils=require("./utils.js").Utils;LineByLinePrinter.prototype.generateLineByLineJsonHtml=function(diffFiles,config){return'<div class="d2h-wrapper">\n'+diffFiles.map(function(file){var diffs;return diffs=file.blocks.length?generateFileHtml(file,config):generateEmptyDiff(),'<div class="d2h-file-wrapper" data-lang="'+file.language+'">\n     <div class="d2h-file-header">\n       <div class="d2h-file-stats">\n         <span class="d2h-lines-added">+'+file.addedLines+'</span>\n         <span class="d2h-lines-deleted">-'+file.deletedLines+'</span>\n       </div>\n       <div class="d2h-file-name">'+printerUtils.getDiffName(file)+'</div>\n     </div>\n     <div class="d2h-file-diff">\n       <div class="d2h-code-wrapper">\n         <table class="d2h-diff-table">\n           <tbody class="d2h-diff-tbody">\n         '+diffs+"           </tbody>\n         </table>\n       </div>\n     </div>\n   </div>\n"}).join("\n")+"</div>\n"},"undefined"!=typeof module&&module.exports?module.exports.LineByLinePrinter=new LineByLinePrinter:"undefined"==typeof global.LineByLinePrinter&&(global.LineByLinePrinter=new LineByLinePrinter)}(this),function(global,undefined){function HtmlPrinter(){}var lineByLinePrinter=require("./line-by-line-printer.js").LineByLinePrinter,sideBySidePrinter=require("./side-by-side-printer.js").SideBySidePrinter;HtmlPrinter.prototype.generateLineByLineJsonHtml=lineByLinePrinter.generateLineByLineJsonHtml,HtmlPrinter.prototype.generateSideBySideJsonHtml=sideBySidePrinter.generateSideBySideJsonHtml,"undefined"!=typeof module&&module.exports?module.exports.HtmlPrinter=new HtmlPrinter:"undefined"==typeof global.HtmlPrinter&&(global.HtmlPrinter=new HtmlPrinter)}(this),function(global,undefined){function Diff2Html(){}var diffParser=require("./diff-parser.js").DiffParser,htmlPrinter=require("./html-printer.js").HtmlPrinter;Diff2Html.prototype.getPrettyHtmlFromDiff=function(diffInput,config){var diffJson=diffParser.generateDiffJson(diffInput),configOrEmpty=config||{};return htmlPrinter.generateLineByLineJsonHtml(diffJson,configOrEmpty)},Diff2Html.prototype.getJsonFromDiff=function(diffInput){return diffParser.generateDiffJson(diffInput)},Diff2Html.prototype.getPrettyHtmlFromJson=function(diffJson,config){var configOrEmpty=config||{};return htmlPrinter.generateLineByLineJsonHtml(diffJson,configOrEmpty)},Diff2Html.prototype.getPrettySideBySideHtmlFromDiff=function(diffInput,config){var diffJson=diffParser.generateDiffJson(diffInput),configOrEmpty=config||{};return htmlPrinter.generateSideBySideJsonHtml(diffJson,configOrEmpty)},Diff2Html.prototype.getPrettySideBySideHtmlFromJson=function(diffJson,config){var configOrEmpty=config||{};return htmlPrinter.generateSideBySideJsonHtml(diffJson,configOrEmpty)},"undefined"!=typeof module&&module.exports?module.exports.Diff2Html=new Diff2Html:"undefined"==typeof global.Diff2Html&&(global.Diff2Html=new Diff2Html)}(this);
New to GrepCode? Check out our FAQ X