Commits

Juha Kuitunen committed fe69b6d

show diff with colors

  • Participants
  • Parent commits 49ac9c4

Comments (0)

Files changed (1)

File assets/diff.html

 <script language="javascript">
 	document.getElementById("code").innerHTML = bitbeaker.getCode();
 	//prettyPrint();
+
+	String.prototype.startsWith = function(needle) { return(this.indexOf(needle) == 0); };
+	var lines = document.getElementById("code").innerHTML.split(/\r?\n/);
+	var colored = "";
+	for (i=0; i<lines.length; i++) {
+		var lines_modified = lines[i].match(/@@[ \-\+\d,]+@@/);
+		if (lines_modified != null) {
+			colored += "<span style=\"background-color: #DEB887;\">" + lines_modified[0] + "</span>" + lines[i].substring(lines_modified[0].length) + "\n";
+		} else if (lines[i].startsWith("+")) {
+			colored += "<span style=\"background-color: #CCFFCC;\">" + lines[i] + "</span>\n";
+		} else if (lines[i].startsWith("-")) {
+			colored += "<span style=\"background-color: #FFDDDD;\">" + lines[i] + "</span>\n";
+		} else if (lines[i].startsWith("diff") || lines[i].startsWith("index")) {
+			colored += "<span style=\"color: #A0A0A0;\">" + lines[i] + "</span>\n";
+		} else {
+			colored += lines[i] + "\n";
+		}
+	}
+	document.getElementById("code").innerHTML = colored;
+
 </script>
 </body>
 </html>