Skip to content

Commit

Permalink
Add new Tidy5 filters
Browse files Browse the repository at this point in the history
  • Loading branch information
da2x committed May 3, 2015
1 parent cea211a commit 078077f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGES.txt
Expand Up @@ -4,6 +4,8 @@ New in master
Features
--------

* 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
Expand Down
12 changes: 12 additions & 0 deletions docs/manual.txt
Expand Up @@ -1347,6 +1347,18 @@ The currently available filters are:
".html": [apply_to_text_file(string.upper)]
}

html_tidy_nowrap
Prettify HTML 5 documents with `tidy5 <http://www.html-tidy.org/>`_

html_tidy_wrap
Prettify HTML 5 documents wrapped at 80 characters with `tidy5 <http://www.html-tidy.org/>`_

html_tidy_wrap_attr
Prettify HTML 5 documents and wrap lines and attributes with `tidy5 <http://www.html-tidy.org/>`_

html_tidy_mini
Minify HTML 5 into smaller documents with `tidy5 <http://www.html-tidy.org/>`_

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

Expand Down
19 changes: 19 additions & 0 deletions nikola/filters.py
Expand Up @@ -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 """
try:
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

Kwpolska May 3, 2015

Member

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

@apply_to_text_file
def minify_lines(data):
Expand Down

0 comments on commit 078077f

Please sign in to comment.