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

Commitabd0b0b

Browse files
author
James Graham
committed
Make foreign content switch on namespace of current node rather than insertion mode
--HG--extra : transplant_source : %E4%FE%9F%C8T%9Cd%8F/%0C%2Cm%95%1B6%A8%BF%A0%5Bd
1 parent12dd376 commitabd0b0b

File tree

4 files changed

+132
-164
lines changed

4 files changed

+132
-164
lines changed

‎html5lib/constants.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,8 @@
483483
"area",
484484
"col",
485485
"input",
486-
"source"
486+
"source",
487+
"track"
487488
))
488489

489490
cdataElements=frozenset(('title','textarea'))

‎html5lib/html5parser.py‎

Lines changed: 81 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,19 @@ def reset(self):
150150
self.beforeRCDataPhase=None
151151

152152
self.framesetOK=True
153+
154+
defisHTMLIntegrationPoint(self,element):
155+
if (element.name=="annotation-xml"and
156+
element.namespace==namespaces["mathml"]):
157+
return ("encoding"inelement.attributesand
158+
element.attributes["encoding"].translate(
159+
asciiUpper2Lower)in
160+
("text/html","application/xhtml+xml"))
161+
else:
162+
return (element.namespace,element.name)inhtmlIntegrationPointElements
163+
164+
defisMathMLTextIntegrationPoint(self,element):
165+
return (element.namespace,element.name)inmathmlTextIntegrationPointElements
153166

154167
defmainLoop(self):
155168
CharactersToken=tokenTypes["Characters"]
@@ -158,27 +171,48 @@ def mainLoop(self):
158171
EndTagToken=tokenTypes["EndTag"]
159172
CommentToken=tokenTypes["Comment"]
160173
DoctypeToken=tokenTypes["Doctype"]
161-
174+
ParseErrorToken=tokenTypes["ParseError"]
162175

163176
fortokeninself.normalizedTokens():
164177
new_token=token
165178
whilenew_tokenisnotNone:
179+
currentNode=self.tree.openElements[-1]ifself.tree.openElementselseNone
180+
currentNodeNamespace=currentNode.namespaceifcurrentNodeelseNone
181+
currentNodeName=currentNode.nameifcurrentNodeelseNone
182+
166183
type=new_token["type"]
167-
iftype==CharactersToken:
168-
new_token=self.phase.processCharacters(new_token)
169-
eliftype==SpaceCharactersToken:
170-
new_token=self.phase.processSpaceCharacters(new_token)
171-
eliftype==StartTagToken:
172-
new_token=self.phase.processStartTag(new_token)
173-
eliftype==EndTagToken:
174-
new_token=self.phase.processEndTag(new_token)
175-
eliftype==CommentToken:
176-
new_token=self.phase.processComment(new_token)
177-
eliftype==DoctypeToken:
178-
new_token=self.phase.processDoctype(new_token)
179-
else:
184+
185+
iftype==ParseErrorToken:
180186
self.parseError(new_token["data"],new_token.get("datavars", {}))
181187
new_token=None
188+
else:
189+
if (len(self.tree.openElements)==0or
190+
currentNodeNamespace==self.tree.defaultNamespaceor
191+
(self.isMathMLTextIntegrationPoint(currentNode)and
192+
((type==StartTagTokenand
193+
token["name"]notinfrozenset(["mglyph","malignmark"]))or
194+
typein (CharactersToken,SpaceCharactersToken)))or
195+
(currentNodeNamespace==namespaces["mathml"]and
196+
currentNodeName=="annotation-xml"and
197+
token["name"]=="svg")or
198+
(self.isHTMLIntegrationPoint(currentNode)and
199+
typein (StartTagToken,CharactersToken,SpaceCharactersToken))):
200+
phase=self.phase
201+
else:
202+
phase=self.phases["inForeignContent"]
203+
204+
iftype==CharactersToken:
205+
new_token=phase.processCharacters(new_token)
206+
eliftype==SpaceCharactersToken:
207+
new_token=phase.processSpaceCharacters(new_token)
208+
eliftype==StartTagToken:
209+
new_token=phase.processStartTag(new_token)
210+
eliftype==EndTagToken:
211+
new_token=phase.processEndTag(new_token)
212+
eliftype==CommentToken:
213+
new_token=phase.processComment(new_token)
214+
eliftype==DoctypeToken:
215+
new_token=phase.processDoctype(new_token)
182216

183217
if (type==StartTagTokenandtoken["selfClosing"]
184218
andnottoken["selfClosingAcknowledged"]):
@@ -379,12 +413,12 @@ def resetInsertionMode(self):
379413
ifnodeNamein ("select","colgroup","head","html"):
380414
assertself.innerHTML
381415

416+
ifnotlastandnode.namespace!=self.tree.defaultNamespace:
417+
continue
418+
382419
ifnodeNameinnewModes:
383420
new_phase=self.phases[newModes[nodeName]]
384421
break
385-
elifnode.namespacein (namespaces["mathml"],namespaces["svg"]):
386-
new_phase=self.phases["inForeignContent"]
387-
break
388422
eliflast:
389423
new_phase=self.phases["inBody"]
390424
break
@@ -419,7 +453,6 @@ def wrapped(self, *args, **kwargs):
419453
try:
420454
info= {"type":type_names[token['type']]}
421455
except:
422-
printtoken
423456
raise
424457
iftoken['type']inconstants.tagTokenTypes:
425458
info["name"]=token['name']
@@ -1243,7 +1276,6 @@ def startTagMath(self, token):
12431276
self.tree.insertElement(token)
12441277
#Need to get the parse error right for the case where the token
12451278
#has a namespace not equal to the xmlns attribute
1246-
self.parser.phase=self.parser.phases["inForeignContent"]
12471279
iftoken["selfClosing"]:
12481280
self.tree.openElements.pop()
12491281
token["selfClosingAcknowledged"]=True
@@ -1256,7 +1288,6 @@ def startTagSvg(self, token):
12561288
self.tree.insertElement(token)
12571289
#Need to get the parse error right for the case where the token
12581290
#has a namespace not equal to the xmlns attribute
1259-
self.parser.phase=self.parser.phases["inForeignContent"]
12601291
iftoken["selfClosing"]:
12611292
self.tree.openElements.pop()
12621293
token["selfClosingAcknowledged"]=True
@@ -1741,7 +1772,7 @@ def processSpaceCharacters(self, token):
17411772
self.characterTokens.append(token)
17421773
# assert False
17431774

1744-
defprocessStartTag(self,token):
1775+
defprocessStartTag(self,token):
17451776
self.flushCharacters()
17461777
self.parser.phase=self.originalPhase
17471778
returntoken
@@ -2298,7 +2329,7 @@ def endTagOther(self, token):
22982329
classInForeignContentPhase(Phase):
22992330
breakoutElements=frozenset(["b","big","blockquote","body","br",
23002331
"center","code","dd","div","dl","dt",
2301-
"em","embed","font","h1","h2","h3",
2332+
"em","embed","h1","h2","h3",
23022333
"h4","h5","h6","head","hr","i","img",
23032334
"li","listing","menu","meta","nobr",
23042335
"ol","p","pre","ruby","s","small",
@@ -2307,19 +2338,6 @@ class InForeignContentPhase(Phase):
23072338
def__init__(self,parser,tree):
23082339
Phase.__init__(self,parser,tree)
23092340

2310-
defisHTMLIntegrationPoint(self,element):
2311-
if (element.name=="annotation-xml"and
2312-
element.namespace==namespaces["mathml"]):
2313-
return ("encoding"inelement.attributesand
2314-
element.attributes["encoding"].translate(
2315-
asciiUpper2Lower)in
2316-
("text/html","application/xhtml+xml"))
2317-
else:
2318-
return (element.namespace,element.name)inhtmlIntegrationPointElements
2319-
2320-
defisMathMLTextIntegrationPoint(self,element):
2321-
return (element.namespace,element.name)inmathmlTextIntegrationPointElements
2322-
23232341
defadjustSVGTagNames(self,token):
23242342
replacements= {u"altglyph":u"altGlyph",
23252343
u"altglyphdef":u"altGlyphDef",
@@ -2362,48 +2380,25 @@ def adjustSVGTagNames(self, token):
23622380
token["name"]=replacements[token["name"]]
23632381

23642382
defprocessCharacters(self,token):
2365-
if (self.tree.openElements[-1].namespace==self.tree.defaultNamespaceor
2366-
self.isHTMLIntegrationPoint(self.tree.openElements[-1])):
2367-
new_token=self.parser.phases["inBody"].processCharacters(token)
2368-
self.parser.resetInsertionMode()
2369-
returnnew_token
2370-
eliftoken["data"]==u"\u0000":
2383+
iftoken["data"]==u"\u0000":
23712384
token["data"]=u"\uFFFD"
23722385
elif (self.parser.framesetOKand
23732386
any(charnotinspaceCharactersforcharintoken["data"])):
23742387
self.parser.framesetOK=False
23752388
Phase.processCharacters(self,token)
23762389

2377-
defprocessEOF(self):
2378-
reprocess=self.parser.phases["inBody"].processEOF()
2379-
self.parser.resetInsertionMode()
2380-
returnreprocess
2381-
23822390
defprocessStartTag(self,token):
23832391
currentNode=self.tree.openElements[-1]
2384-
currentNodeNamespace=currentNode.namespace
2385-
currentNodeName=currentNode.name
2386-
if (currentNodeNamespace==self.tree.defaultNamespaceor
2387-
(self.isMathMLTextIntegrationPoint(currentNode)and
2388-
token["name"]notinfrozenset(["mglyph","malignmark"]))or
2389-
(currentNodeNamespace==namespaces["mathml"]and
2390-
currentNodeName=="annotation-xml"and
2391-
token["name"]=="svg")or
2392-
self.isHTMLIntegrationPoint(currentNode)):
2393-
2394-
new_token=self.parser.phases["inBody"].processStartTag(token)
2395-
self.parser.resetInsertionMode()
2396-
returnnew_token
2397-
2398-
eliftoken["name"]inself.breakoutElements:
2392+
if (token["name"]inself.breakoutElementsor
2393+
(token["name"]=="font"and
2394+
set(token["data"].keys())|set("color","face","size"))):
23992395
self.parser.parseError("unexpected-html-element-in-foreign-content",
24002396
token["name"])
24012397
while (self.tree.openElements[-1].namespace!=
24022398
self.tree.defaultNamespaceand
2403-
notself.isHTMLIntegrationPoint(self.tree.openElements[-1])and
2404-
notself.isMathMLTextIntegrationPoint(self.tree.openElements[-1])):
2399+
notself.parser.isHTMLIntegrationPoint(self.tree.openElements[-1])and
2400+
notself.parser.isMathMLTextIntegrationPoint(self.tree.openElements[-1])):
24052401
self.tree.openElements.pop()
2406-
self.parser.resetInsertionMode()
24072402
returntoken
24082403

24092404
else:
@@ -2420,33 +2415,29 @@ def processStartTag(self, token):
24202415
token["selfClosingAcknowledged"]=True
24212416

24222417
defprocessEndTag(self,token):
2423-
ifself.tree.openElements[-1].namespace==self.tree.defaultNamespace:
2424-
new_token=self.parser.phases["inBody"].processEndTag(token)
2425-
self.parser.resetInsertionMode()
2426-
returnnew_token
2427-
else:
2428-
nodeIndex=len(self.tree.openElements)-1
2429-
node=self.tree.openElements[-1]
2430-
ifnode.name!=token["name"]:
2431-
self.parser.parseError("unexpected-end-tag",token["name"])
2432-
2433-
whileTrue:
2434-
ifnode.name.translate(asciiUpper2Lower)==token["name"]:
2435-
whileself.tree.openElements.pop()!=node:
2436-
assertself.tree.openElements
2437-
new_token=None
2438-
break
2439-
nodeIndex-=1
2418+
nodeIndex=len(self.tree.openElements)-1
2419+
node=self.tree.openElements[-1]
2420+
ifnode.name!=token["name"]:
2421+
self.parser.parseError("unexpected-end-tag",token["name"])
2422+
2423+
whileTrue:
2424+
ifnode.name.translate(asciiUpper2Lower)==token["name"]:
2425+
ifself.parser.phase==self.parser.phases["inTableText"]:
2426+
self.parser.phase.flushCharacters()
2427+
self.parser.phase=self.parser.phase.originalPhase
2428+
whileself.tree.openElements.pop()!=node:
2429+
assertself.tree.openElements
2430+
new_token=None
2431+
break
2432+
nodeIndex-=1
24402433

2441-
node=self.tree.openElements[nodeIndex]
2442-
ifnode.namespace!=self.tree.defaultNamespace:
2443-
continue
2444-
else:
2445-
new_token=self.parser.phases["inBody"].processEndTag(token)
2446-
break
2447-
ifself.parser.phase==self:
2448-
self.parser.resetInsertionMode()
2449-
returnnew_token
2434+
node=self.tree.openElements[nodeIndex]
2435+
ifnode.namespace!=self.tree.defaultNamespace:
2436+
continue
2437+
else:
2438+
new_token=self.parser.phase.processEndTag(token)
2439+
break
2440+
returnnew_token
24502441

24512442

24522443
classAfterBodyPhase(Phase):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp