Changeset 4539:6fba03c6fc2d in livinglogic.python.xist

Show
Ignore:
Timestamp:
08/10/11 17:07:09 (8 years ago)
Author:
Walter Doerwald <walter@…>
Branch:
default
Message:

Sort attributes in Tidy().

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • src/ll/xist/parse.py

    r4475 r4539  
    14031403            if elok: 
    14041404                yield (u"enterstarttag", elementname) 
     1405                # Collect all attributes, so we can sort them 
     1406                attrs = [] 
    14051407                attr = node.properties 
    14061408                while attr is not None: 
    14071409                    attrname = decode(attr.name).lower() 
    14081410                    if not self.skipbad or el.Attrs.isallowed_xml(attrname): 
    1409                         content = decode(attr.content) if attr.content is not None else u"" 
    1410                         yield (u"enterattr", attrname) 
    1411                         yield (u"text", content) 
    1412                         yield (u"leaveattr", attrname) 
     1411                        attrcontent = decode(attr.content) if attr.content is not None else u"" 
     1412                        attrs.append((attrname, attrcontent)) 
    14131413                    attr = attr.next 
     1414                # We sort the attribute, because this gives a canonical event stream for HTML 
     1415                for (attrname, attrcontent) in sorted(attrs): 
     1416                    yield (u"enterattr", attrname) 
     1417                    yield (u"text", attrcontent) 
     1418                    yield (u"leaveattr", attrname) 
    14141419                yield (u"leavestarttag", elementname) 
    14151420            child = node.children