Skip to content
Permalink
Browse files

html5lib filters (minify and xmllike)

Undocumented for now. For testing purposes while considering
transitioning to html5lib and developers who like the libs’ output.
  • Loading branch information...
da2x committed Jun 4, 2015
1 parent 7c73f76 commit 1f6f571437e487aec9040da3664ff4a55a5ff094
Showing with 27 additions and 1 deletion.
  1. +27 −1 nikola/filters.py
@@ -146,7 +146,6 @@ 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")

@@ -172,6 +171,33 @@ def _html_tidy_runner(infile, options):
return status


@apply_to_text_file
def html5lib_minify(data):
import html5lib
import html5lib.serializer
data = html5lib.serializer.serialize(html5lib.parse(data, treebuilder='lxml'),
tree='lxml',
quote_attr_values=False,
omit_optional_tags=True,
minimize_boolean_attributes=True,
strip_whitespace=True,
alphabetical_attributes=True,
escape_lt_in_attrs=True)
return data

@apply_to_text_file
def html5lib_xmllike(data):
import html5lib
import html5lib.serializer
data = html5lib.serializer.serialize(html5lib.parse(data, treebuilder='lxml'),
tree='lxml',
quote_attr_values=True,
omit_optional_tags=False,
strip_whitespace=False,
alphabetical_attributes=True,
escape_lt_in_attrs=True)
return data

@apply_to_text_file
def minify_lines(data):
return data

0 comments on commit 1f6f571

Please sign in to comment.
You can’t perform that action at this time.