Index: publish.py =================================================================== --- publish.py (revision 24226) +++ publish.py (working copy) @@ -56,6 +56,10 @@ """ +TIDY_IGNORE = [ + 'Warning: lacks "summary" attribute', + ] + class Publisher: """ The core of Quixote and of any Quixote application. This class is @@ -502,11 +506,50 @@ """Hook for post processing the output. Subclasses may wish to override (e.g. check HTML syntax). """ + c_type=request.response.headers.get("content-type") if (output and + (not c_type or c_type=="text/html") and + not isinstance(output, Stream)): + self.html_tidy(request, output) + if (output and self.config.compress_pages and not isinstance(output, Stream)): output = self.compress_output(request, str(output)) return output + + def html_tidy(self, request, output): + """ + Small hack to call html-tidy for every html + page which is serverd by quixote. + + It is used for checking the html syntax only, the html + output won't be changed. + """ + import os, tempfile + htmlfile = tempfile.NamedTemporaryFile() + htmlfile.write(str(output)) + htmlfile.flush() + htmlfile.seek(0) + fp = os.popen("tidy -q -e '%s' 2>&1" % htmlfile.name, "r") + errors = [] + for line in fp: + line = line.strip() + if line: + for ign in TIDY_IGNORE: + if ign in line: + break + else: + errors.append(line) + if errors: + self.log("HTML-Tidy: %s" % request.get_path()) + for line in errors[:20]: + self.log(" " + line) + if len(errors) > 20: + self.log(" [...more errors...]") + else: + self.log("HTML-Tidy: %s okay" % request.get_path()) + fp.close() + htmlfile.close() def process_request (self, request, env): """process_request(request : HTTPRequest, env : dict) : string