#!/usr/bin/env python
import sys, cgi

def sanitise(string):
    return cgi.escape(string)

html_head = '''
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>QuickReview</title>

<!-- JQuery -->
<script src="http://code.jquery.com/jquery-2.1.4.min.js"></script>

<!-- Code syntax highlighting -->
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.6/styles/zenburn.min.css">
<script src="http://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.6/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
</head>

<!-- Custom QuickReview CSS styling -->
<link rel="stylesheet" href="./quickreview.css">

<!-- Custom QuickReview JavaScript -->
<script src="./quickreview.js"></script>

<body>
'''
html_foot = '''
</body>
</html>
'''
html_line = '''
<div class="loc-container"><div class="line-no">%(linenumber)s</div><div class="loc"><pre><code>%(code)s</code></pre></div><div contenteditable="true" class="comment"></div></div>
'''
html_review_head = '''
<div class="review">
<div class="review-title">%(filename)s</div>
'''
html_review_foot = '''
</div>
'''

print html_head
for input_filename in sys.argv[1:]:
    with open(input_filename) as input_f:
        print html_review_head % {'filename': input_filename}
        lines = input_f.readlines()
        zeros = len(str(len(lines)+1))
        for lineno, line in enumerate(lines):
            lineno = str(lineno + 1).zfill(zeros)
            print html_line % {'linenumber': lineno, 'code': sanitise(line)}

print html_foot
