@@ -192,16 +192,24 @@ def processEndTag(self, name):
192
192
193
193
194
194
class InitialPhase (Phase ):
195
- # XXX This phase deals with error handling as well which is currently not
196
- # in the specification.
197
-
198
- def processDoctype (self , name , error ):
199
- self .tree .insertDoctype (name )
195
+ # This phase deals with error handling as well which is currently not
196
+ # covered in the specification. The error handling is typically known as
197
+ # "quirks mode". It is expected that a future version of HTML5 will defin
198
+ # this.
199
+ #
200
+ # AT Given that. I think it should be possible to merge this phase with the
201
+ # root element phase in due course.
202
+ def processEOF (self ):
200
203
self .parser .phase = self .parser .phases ["rootElement" ]
204
+ self .parser .phase .processEOF ()
201
205
202
206
def processComment (self , data ):
203
207
self .tree .insertComment (data , self .tree .document )
204
208
209
+ def processDoctype (self , name , error ):
210
+ self .tree .insertDoctype (name )
211
+ self .parser .phase = self .parser .phases ["rootElement" ]
212
+
205
213
def processSpaceCharacters (self , data ):
206
214
self .tree .insertText (data , self .tree .document )
207
215
@@ -218,10 +226,6 @@ def processEndTag(self, name):
218
226
self .parser .phase = self .parser .phases ["rootElement" ]
219
227
self .parser .phase .processEndTag (name )
220
228
221
- def processEOF (self ):
222
- self .parser .phase = self .parser .phases ["rootElement" ]
223
- self .parser .phase .processEOF ()
224
-
225
229
226
230
class RootElementPhase (Phase ):
227
231
# helper methods
@@ -232,6 +236,10 @@ def insertHtmlElement(self):
232
236
self .parser .phase = self .parser .phases ["beforeHead" ]
233
237
234
238
# other
239
+ def processEOF (self ):
240
+ self .insertHtmlElement ()
241
+ self .parser .phase .processEOF ()
242
+
235
243
def processComment (self , data ):
236
244
self .tree .insertComment (data , self .tree .document )
237
245
@@ -250,10 +258,6 @@ def processEndTag(self, name):
250
258
self .insertHtmlElement ()
251
259
self .parser .phase .processEndTag (name )
252
260
253
- def processEOF (self ):
254
- self .insertHtmlElement ()
255
- self .parser .phase .processEOF ()
256
-
257
261
258
262
class BeforeHeadPhase (Phase ):
259
263
def __init__ (self , parser , tree ):
@@ -1585,12 +1589,12 @@ def endTagOther(self, name):
1585
1589
1586
1590
1587
1591
class TrailingEndPhase (Phase ):
1588
- def processComment (self , data ):
1589
- self .parser .insertCommenr (data , self .tree .document )
1590
-
1591
1592
def processEOF (self ):
1592
1593
pass
1593
1594
1595
+ def processComment (self , data ):
1596
+ self .parser .insertCommenr (data , self .tree .document )
1597
+
1594
1598
def processSpaceCharacters (self , data ):
1595
1599
self .parser .lastPhase .processCharacters (data )
1596
1600
0 commit comments