Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb6ce031

Browse files
committed
Add alphabetical_attributes option to the serializer
1 parent508ab39 commitb6ce031

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

‎html5lib/serializer/htmlserializer.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ class HTMLSerializer(object):
9292
resolve_entities=True
9393

9494
# miscellaneous options
95+
alphabetical_attributes=False
9596
inject_meta_charset=True
9697
strip_whitespace=False
9798
sanitize=False
@@ -100,7 +101,8 @@ class HTMLSerializer(object):
100101
"omit_optional_tags","minimize_boolean_attributes",
101102
"use_trailing_solidus","space_before_trailing_solidus",
102103
"escape_lt_in_attrs","escape_rcdata","resolve_entities",
103-
"inject_meta_charset","strip_whitespace","sanitize")
104+
"alphabetical_attributes","inject_meta_charset",
105+
"strip_whitespace","sanitize")
104106

105107
def__init__(self,**kwargs):
106108
"""Initialize HTMLSerializer.
@@ -143,6 +145,8 @@ def __init__(self, **kwargs):
143145
See `html5lib user documentation`_
144146
omit_optional_tags=True|False
145147
Omit start/end tags that are optional.
148+
alphabetical_attributes=False|True
149+
Reorder attributes to be in alphabetical order.
146150
147151
.. _html5lib user documentation: http://code.google.com/p/html5lib/wiki/UserDocumentation
148152
"""
@@ -185,6 +189,12 @@ def serialize(self, treewalker, encoding=None):
185189
ifself.omit_optional_tags:
186190
from ..filters.optionaltagsimportFilter
187191
treewalker=Filter(treewalker)
192+
# Alphabetical attributes must be last, as other filters
193+
# could add attributes and alter the order
194+
ifself.alphabetical_attributes:
195+
from ..filters.alphabeticalattributesimportFilter
196+
treewalker=Filter(treewalker)
197+
188198
fortokenintreewalker:
189199
type=token["type"]
190200
iftype=="Doctype":

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp