diff options
author | Donald Stufft <donald@stufft.io> | 2014-05-03 01:13:28 -0400 |
---|---|---|
committer | Donald Stufft <donald@stufft.io> | 2014-05-03 01:13:28 -0400 |
commit | 0e72f65bf4e5ea6b8fd17d02fe4cae0ba7da5113 (patch) | |
tree | 5c04afcabe3c7087e38b8114b19de437f2cf4ab3 /pip/_vendor/html5lib/serializer/htmlserializer.py | |
parent | bdef6cebfb4e92a388cf84ed55cbd4ead8ef269c (diff) | |
parent | 93098d0c6781dd7019dfa43d9030f14b28f1bf2d (diff) | |
download | pip-1.5.5.tar.gz |
Merge branch '1.5.X'1.5.5
Conflicts:
.travis/py34.sh
CHANGES.txt
PROJECT.txt
Diffstat (limited to 'pip/_vendor/html5lib/serializer/htmlserializer.py')
-rw-r--r-- | pip/_vendor/html5lib/serializer/htmlserializer.py | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/pip/_vendor/html5lib/serializer/htmlserializer.py b/pip/_vendor/html5lib/serializer/htmlserializer.py index 08b60dfcc..157840a05 100644 --- a/pip/_vendor/html5lib/serializer/htmlserializer.py +++ b/pip/_vendor/html5lib/serializer/htmlserializer.py @@ -92,15 +92,17 @@ class HTMLSerializer(object): resolve_entities = True # miscellaneous options + alphabetical_attributes = False inject_meta_charset = True strip_whitespace = False sanitize = False options = ("quote_attr_values", "quote_char", "use_best_quote_char", - "minimize_boolean_attributes", "use_trailing_solidus", - "space_before_trailing_solidus", "omit_optional_tags", - "strip_whitespace", "inject_meta_charset", "escape_lt_in_attrs", - "escape_rcdata", "resolve_entities", "sanitize") + "omit_optional_tags", "minimize_boolean_attributes", + "use_trailing_solidus", "space_before_trailing_solidus", + "escape_lt_in_attrs", "escape_rcdata", "resolve_entities", + "alphabetical_attributes", "inject_meta_charset", + "strip_whitespace", "sanitize") def __init__(self, **kwargs): """Initialize HTMLSerializer. @@ -143,6 +145,8 @@ class HTMLSerializer(object): See `html5lib user documentation`_ omit_optional_tags=True|False Omit start/end tags that are optional. + alphabetical_attributes=False|True + Reorder attributes to be in alphabetical order. .. _html5lib user documentation: http://code.google.com/p/html5lib/wiki/UserDocumentation """ @@ -171,10 +175,11 @@ class HTMLSerializer(object): self.encoding = encoding in_cdata = False self.errors = [] + if encoding and self.inject_meta_charset: from ..filters.inject_meta_charset import Filter treewalker = Filter(treewalker, encoding) - # XXX: WhitespaceFilter should be used before OptionalTagFilter + # WhitespaceFilter should be used before OptionalTagFilter # for maximum efficiently of this latter filter if self.strip_whitespace: from ..filters.whitespace import Filter @@ -185,6 +190,12 @@ class HTMLSerializer(object): if self.omit_optional_tags: from ..filters.optionaltags import Filter treewalker = Filter(treewalker) + # Alphabetical attributes must be last, as other filters + # could add attributes and alter the order + if self.alphabetical_attributes: + from ..filters.alphabeticalattributes import Filter + treewalker = Filter(treewalker) + for token in treewalker: type = token["type"] if type == "Doctype": |