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

Commitca84401

Browse files
author
James Graham
committed
Implement the Noah's Ark algorithm
--HG--extra : transplant_source : %B2V%FAS%81%F9%8E%EB%C1%16%A6%84%1Bq%B9%06%8B%E4%D5%C9
1 parentabd0b0b commitca84401

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

‎html5lib/html5parser.py‎

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -977,11 +977,35 @@ def __init__(self, parser, tree):
977977
])
978978
self.endTagHandler.default=self.endTagOther
979979

980+
defisMatchingFormattingElement(self,node1,node2):
981+
ifnode1.name!=node2.nameornode1.namespace!=node2.namespace:
982+
returnFalse
983+
eliflen(node1.attributes)!=len(node2.attributes):
984+
returnFalse
985+
else:
986+
attributes1=sorted(node1.attributes.items())
987+
attributes2=sorted(node2.attributes.items())
988+
forattr1,attr2inzip(attributes1,attributes2):
989+
ifattr1!=attr2:
990+
returnFalse
991+
returnTrue
992+
980993
# helper
981994
defaddFormattingElement(self,token):
982995
self.tree.insertElement(token)
983-
self.tree.activeFormattingElements.append(
984-
self.tree.openElements[-1])
996+
element=self.tree.openElements[-1]
997+
998+
matchingElements= []
999+
fornodeinself.tree.activeFormattingElements[::-1]:
1000+
ifnodeisMarker:
1001+
break
1002+
elifself.isMatchingFormattingElement(node,element):
1003+
matchingElements.append(node)
1004+
1005+
assertlen(matchingElements)<=3
1006+
iflen(matchingElements)==3:
1007+
self.tree.activeFormattingElements.remove(matchingElements[-1])
1008+
self.tree.activeFormattingElements.append(element)
9851009

9861010
# the real deal
9871011
defprocessEOF(self):
@@ -2422,6 +2446,7 @@ def processEndTag(self, token):
24222446

24232447
whileTrue:
24242448
ifnode.name.translate(asciiUpper2Lower)==token["name"]:
2449+
#XXX this isn't in the spec but it seems necessary
24252450
ifself.parser.phase==self.parser.phases["inTableText"]:
24262451
self.parser.phase.flushCharacters()
24272452
self.parser.phase=self.parser.phase.originalPhase

‎html5lib/treebuilders/dom.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@ def getDomModule(DomImplementation):
2323

2424
defgetDomBuilder(DomImplementation):
2525
Dom=DomImplementation
26-
classAttrList:
26+
classAttrList(object):
2727
def__init__(self,element):
2828
self.element=element
2929
def__iter__(self):
3030
returnself.element.attributes.items().__iter__()
3131
def__setitem__(self,name,value):
3232
self.element.setAttribute(name,value)
33+
def__len__(self):
34+
returnlen(self.element.attributes.items())
3335
defitems(self):
3436
return [(item[0],item[1])foritemin
3537
self.element.attributes.items()]

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp