Skip to content
Browse files
Add new Tidy5 filters
  • Loading branch information
da2x committed May 3, 2015
1 parent cea211a commit 078077fb94cf88e984ca3f7846008e46af12b857
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
@@ -4,6 +4,8 @@ New in master

* Four new filters: html_tidy_nowrap, html_tidy_wrap, html_tidy_wrap_attr,
and html_tidy_mini for prettification and minification. Requires tidy5.
* Multilingual sitemaps (Issue #1610)
* Compatibility with doit v0.28.0 (Issue #1655)
* AddThis is no longer added by default to users’ sites
@@ -1347,6 +1347,18 @@ The currently available filters are:
".html": [apply_to_text_file(string.upper)]

Prettify HTML 5 documents with `tidy5 <>`_

Prettify HTML 5 documents wrapped at 80 characters with `tidy5 <>`_

Prettify HTML 5 documents and wrap lines and attributes with `tidy5 <>`_

Minify HTML 5 into smaller documents with `tidy5 <>`_

**THIS FILTER HAS BEEN TURNED INTO A NOOP** and currently does nothing.

@@ -146,6 +146,25 @@ def optipng(infile):
def jpegoptim(infile):
return runinplace(r"jpegoptim -p --strip-all -q %1", infile)

def html_tidy_nowrap(infile):
return _html_tidy_runner(infile, r"-quiet --show-info no --show-warnings no -utf8 -indent --indent-attributes no --sort-attributes alpha --wrap 0 --wrap-sections no --tidy-mark no -modify %1")

def html_tidy_wrap(infile):
return _html_tidy_runner(infile, r"-quiet --show-info no --show-warnings no -utf8 -indent --indent-attributes no --sort-attributes alpha --wrap 80 --wrap-sections no --tidy-mark no -modify %1")

def html_tidy_wrap_attr(infile):
return _html_tidy_runner(infile, r"-quiet --show-info no --show-warnings no -utf8 -indent --indent-attributes yes --sort-attributes alpha --wrap 80 --wrap-sections no --tidy-mark no -modify %1")

def html_tidy_mini(infile):
return _html_tidy_runner(infile, r"-quiet --show-info no --show-warnings no -utf8 --indent-attributes no --sort-attributes alpha --wrap 0 --wrap-sections no --tidy-mark no -modify %1")

def _html_tidy_runner(infile, options):
""" Warnings (returncode 1) are not critical, and *everything* is a warning """
status = runinplace(r"tidy5 " + options, infile)
except subprocess.CalledProcessError as err:
status = 0 if err.returncode is 1 else err.returncode

This comment has been minimized.

Copy link

Kwpolska May 3, 2015


use == instead, is can be problematic as it does identity and not value comparison (won’t break with small integers in current CPython though)

return status

def minify_lines(data):

0 comments on commit 078077f

Please sign in to comment.