import os from WebUtils.Funcs import htmlEncode from MiscUtils import StringIO def encodeWithIndentation(html): html = htmlEncode(html).replace(' ', ' ') return html.replace('\t', ' ') def validateHTML(html): """ Validate the input using Web Design Group's HTML validator available at http://www.htmlhelp.com/tools/validator/ Make sure you install the offline validator (called "validate") which can be called from the command-line. The "validate" script must be in your path. If no errors are found, an empty string is returned. Otherwise, the HTML with the error messages is returned. """ input, output = os.popen4('validate') input.write(html) input.close() out = output.readlines() output.close() errorLines = {} for line in out: if line[0:5] == 'Line ': i = line.find(',') if i != -1: linenum = int(line[5:i]) errorLines[linenum] = line # Be quiet if all's well if not errorLines: return '' result = StringIO() result.write('
\n')
result.write("%s" % "".join(out)) result.write(' | |
| %d | %s |
| %s | |
| %d | %s |