Last active
January 29, 2020 07:42
-
-
Save raymyers/d180c1175fedae8894eafb538041b3f1 to your computer and use it in GitHub Desktop.
Using diff2html on output of 'diff -u'
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<!-- CSS --> | |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.13.1/styles/github.min.css" /> | |
<link rel="stylesheet" type="text/css" href="vendor-js/diff2html-3.0.0/bundles/css/diff2html.min.css" /> | |
<!-- Javascripts --> | |
<script type="text/javascript" src="vendor-js/diff2html-3.0.0/bundles/js/diff2html-ui.min.js"></script> | |
<script type="text/javascript" src="vendor-js/diff2html-3.0.0/bundles/js/diff2html.min.js"></script> | |
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> | |
<script type="text/javascript"> | |
document.addEventListener('DOMContentLoaded', () => { | |
const handleDiffText = function(diffText) { | |
diffText = diffText.replace(/^--- (\S+)\s.*$/mg, '\ndiff --git a/$1 b/$1\n--- $1'); | |
diffText = diffText.replace(/^\+\+\+.*$/mg, ''); | |
console.log('converted', diffText) | |
// const filedf.match(/--- (\S+)\s/g)[1] | |
// const filename = diffString.match(/--- (\S+)\s/)[1] | |
const targetElement = document.getElementById('destination-elem-id'); | |
const configuration = { | |
drawFileList: true, | |
matching: 'lines', | |
highlight: false, | |
// outputFormat: 'side-by-side' // '' // | |
outputFormat: 'line-by-line' | |
}; | |
const diff2htmlUi = new Diff2HtmlUI(targetElement, diffText, configuration); | |
diff2htmlUi.draw(); | |
} | |
fetch('diff.txt').then((response) => { | |
return response.text().then(function (text) { | |
console.log("diff text:", text) | |
handleDiffText(text); | |
}); | |
}).catch(error => console.error(error)); | |
}); | |
</script> | |
</head> | |
<body> | |
<h1>Pass Integration Test Diffs</h1> | |
<div id="destination-elem-id"></div> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import http.server | |
import socketserver | |
PORT = 9999 | |
Handler = http.server.SimpleHTTPRequestHandler | |
with socketserver.TCPServer(("", PORT), Handler) as httpd: | |
print("serving at port", PORT) | |
httpd.serve_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment