about summary refs log tree commit diff stats
path: root/js/games/nluqo.github.io/broughlike-tutorial/diff.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/games/nluqo.github.io/broughlike-tutorial/diff.js')
-rw-r--r--js/games/nluqo.github.io/broughlike-tutorial/diff.js38
1 files changed, 38 insertions, 0 deletions
diff --git a/js/games/nluqo.github.io/broughlike-tutorial/diff.js b/js/games/nluqo.github.io/broughlike-tutorial/diff.js
new file mode 100644
index 0000000..e70df1b
--- /dev/null
+++ b/js/games/nluqo.github.io/broughlike-tutorial/diff.js
@@ -0,0 +1,38 @@
+//hardcoded contents
+content.NEWLINE = "\n\n";
+
+Object.keys(content).forEach(k => {
+	document.querySelectorAll("#content"+k).forEach(contentContainer => {
+		if(contentContainer){
+			contentContainer.textContent = content[k];
+		}else{
+			console.log("MISSING CONTAINER FOR #content"+k);
+		}
+	});
+});
+
+hljs.initHighlightingOnLoad();
+
+document.querySelectorAll("pre code").forEach(n => {
+	let lines = n.innerHTML.split("\n");
+	let prefixChar = ''
+	prefixChar += '<span class="diff">';
+	if(n.classList.contains('add')){
+		prefixChar += '<span class="noselect">&nbsp;+&nbsp;</span>';
+	}else if(n.classList.contains('remove')){
+		prefixChar += '<span class="noselect">&nbsp;-&nbsp;</span>';
+	}else{
+		prefixChar += '<span class="noselect">&nbsp;&nbsp;&nbsp;</span>';
+	}
+	prefixChar += '</span>';
+	if(lines.length){
+		let lineHtml = lines[0];
+		//ignore first and last lines
+		for(let i=1;i<lines.length-1;i++){
+			lineHtml += "\n";
+			lineHtml += prefixChar;
+			lineHtml += lines[i] ;
+		}
+		n.innerHTML = lineHtml;
+	}
+});