Create HTML listing of source code
There are a ton of good template rendering libraries out there, but I'd leave it to you to figure out if they are better suited to your needs than hand rolled code. 

Assuming you still want to write this yourself, I'd look for ways to make the code more completely data driven and also to make it more readable. 

On the data driven side, you might want save your design as an html file.  That way you can use whatever styling or graphic layout tools you want to produce the layout. You merely need to leave template placeholders where you want the data to go and apply the substitutions.  Django's templating system offers a great example of what you'd expect: vanilla html data with placeholders where the data's gonna go.

Going data driven will reduce a ton of the code here (since so much of it is just string assembly).  You can do some nice syntactic tricks to clean up things like writing html tags, for example

 tag = lambda t, c : "&lt;%s&gt;%s&gt;&lt;/%s&gt;" % (t,c,t)

 tag('footer','footer goes here')
 &gt;  &lt;footer&gt;footer goes here&lt;/footer&gt;


And you you could also use a context manager for tag nesting (example here) to keep things neat

Lastly, use string.Template to allow for keyword or dictionary based replacement you can do things like 

header = Template("&lt;header&gt;&lt;span font=$font&gt;$text&lt;/span&gt;&lt;/header")
header.subsitute(font='sans-serif',text='hello world')


that would make it easier to clean up the series of temp = temp.replace... lines.  Python is a great language for this sort of thing - it should be easy to cut this down by half or more with built in tools.