Set proper HTML5 doctype and encoding for HTML output.

This commit is contained in:
Bastian Kleineidam 2013-03-07 18:21:05 +01:00
parent 9f13af7750
commit d1e5ad2696

View file

@ -3,6 +3,7 @@
import os import os
import time import time
import urllib import urllib
import codecs
from . import rss, util, configuration from . import rss, util, configuration
class EventHandler(object): class EventHandler(object):
@ -120,9 +121,11 @@ class HtmlEventHandler(EventHandler):
yesterdayUrl = self.getUrlFromFilename(self.fnFromDate(yesterday)) yesterdayUrl = self.getUrlFromFilename(self.fnFromDate(yesterday))
tomorrowUrl = self.getUrlFromFilename(self.fnFromDate(tomorrow)) tomorrowUrl = self.getUrlFromFilename(self.fnFromDate(tomorrow))
self.html = file(fn, 'w') self.html = codecs.open(fn, 'w', 'utf-8')
self.html.write('''<html> self.html.write(u'''<!DOCTYPE html>
<html lang="en">
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Comics for %s</title> <title>Comics for %s</title>
</head> </head>
<body> <body>
@ -137,22 +140,22 @@ class HtmlEventHandler(EventHandler):
if self.lastComic != comic: if self.lastComic != comic:
self.newComic(comic) self.newComic(comic)
url = self.getUrlFromFilename(filename) url = self.getUrlFromFilename(filename)
self.html.write(' <li><a href="%s">%s</a></li>\n' % (url, os.path.basename(filename))) self.html.write(u' <li><a href="%s">%s</a></li>\n' % (url, os.path.basename(filename)))
def newComic(self, comic): def newComic(self, comic):
"""Start new comic list in HTML.""" """Start new comic list in HTML."""
if self.lastComic is not None: if self.lastComic is not None:
self.html.write(' </ul>\n') self.html.write(u' </ul>\n')
self.lastComic = comic self.lastComic = comic
self.html.write(''' <li>%s</li> self.html.write(u''' <li>%s</li>
<ul> <ul>
''' % (comic,)) ''' % (comic,))
def end(self): def end(self):
"""End HTML output.""" """End HTML output."""
if self.lastComic is not None: if self.lastComic is not None:
self.html.write(' </ul>\n') self.html.write(u' </ul>\n')
self.html.write('''</ul> self.html.write(u'''</ul>
</body> </body>
</html>''') </html>''')
self.html.close() self.html.close()