Permalink
Browse files

Added tidy filter

* Whitelists some warnings that appear to be acceptable
* Will abort for unknown warnings.
  • Loading branch information...
1 parent 8678c46 commit b3232941c004f9235502d16f7816a55059925a8b Kay Hayen committed with Sep 30, 2012
Showing with 32 additions and 0 deletions.
  1. +32 −0 nikola/filters.py
View
@@ -25,6 +25,7 @@
"""Utility functions to help you run filters on files."""
import os
+import re
import shutil
import subprocess
import tempfile
@@ -66,3 +67,34 @@ def optipng(infile):
def jpegoptim(infile):
return runinplace(r"jpegoptim -p --strip-all -q %1",infile)
+
+def tidy(inplace):
+ # Goggle site verifcation files are no HTML
+ if re.match(r"google[a-f0-9]+.html", os.path.basename(inplace)) \
+ and open(inplace).readline().startswith("google-site-verification:"):
+ return
+
+ # Tidy will give error exits, that we will ignore.
+ output = subprocess.check_output( "tidy -m -w 90 --indent no --quote-marks no --keep-time yes --tidy-mark no '%s'; exit 0" % inplace, stderr = subprocess.STDOUT, shell = True )
+
+ for line in output.split( "\n" ):
+ if "Warning:" in line:
+ if '<meta> proprietary attribute "charset"' in line:
+ # We want to set it though.
+ continue
+ elif '<meta> lacks "content" attribute' in line:
+ # False alarm to me.
+ continue
+ elif '<div> anchor' in line and 'already defined' in line:
+ # Some seeming problem with JavaScript terminators.
+ continue
+ elif '<img> lacks "alt" attribute' in line:
+ # Happens in gallery code, probably can be tolerated.
+ continue
+ elif '<table> lacks "summary" attribute' in line:
+ # Happens for tables, TODO: Check this is normal.
+ continue
+ else:
+ assert False, (inplace,line)
+ elif "Error:" in line:
+ assert False, line

0 comments on commit b323294

Please sign in to comment.