# super simple

import os
import sys
import html

title = "Paper's blog"

def addtitle(out_str, title):
    # add stuff here
    # The title in question:
    out_str += """	<div class="entry">\n		<h1>%s</h1>\n		<pre>\n""" % html.escape(title.strip())
    return out_str

def main(argv):
    file = open(argv[1], 'r')
    out = open(argv[2], 'w')
    out_str = (
    """<!DOCTYPE html>
<head>
    <title>%s</title>
    <meta name="viewport" content="width=device-width;initial-scale=1.0" />
    <link rel="stylesheet" type="text/css" href="blog.css" />
</head>
<body>
""" % (title))
    lines = file.readlines()
    for line in range(len(lines)):
        if lines[line][0] == "#":
            out_str = addtitle(out_str, lines[line][1:])
            continue
        # this sucks.
        if lines[line][0:3] == "---" or len(lines)-line == 1:
            if len(lines)-line == 1:
                out_str += """%s\n""" % html.escape(lines[line].strip())
            out_str += "		</pre>\n	</div>\n"
            continue
        out_str += """%s\n""" % html.escape(lines[line].strip())
    out_str += "</body>"
    print(out_str, file=out)

if __name__ == "__main__":
    main(sys.argv)
