Skip to content

Commit e67ed4f

Browse files
committed
Implemented "compatMode"
--HG-- extra : convert_revision : svn%3Aacbfec75-9323-0410-a652-858a13e371e0/trunk%401119
1 parent c8140dd commit e67ed4f

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

src/html5lib/html5parser.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ def __init__(self, strict = False, tree=simpletree.TreeBuilder,
5353
self.tokenizer_class = tokenizer
5454
self.errors = []
5555

56-
# "quirks" / "almost-standards" / "standards"
57-
self.quirksMode = "standards"
56+
# "quirks" / "limited-quirks" / "no-quirks"
57+
self.compatMode = "no-quirks"
5858

5959
self.phases = {
6060
"initial": InitialPhase(self, self.tree),
@@ -304,6 +304,7 @@ class InitialPhase(Phase):
304304
# this.
305305
def processEOF(self):
306306
self.parser.parseError("expected-doctype-but-got-eof")
307+
self.compatMode = "quirks"
307308
self.parser.phase = self.parser.phases["beforeHtml"]
308309
self.parser.phase.processEOF()
309310

@@ -323,11 +324,8 @@ def processDoctype(self, name, publicId, systemId, correct):
323324
if publicId != "":
324325
publicId = publicId.translate(asciiUpper2Lower)
325326

326-
if nameLower != "html":
327-
# XXX quirks mode
328-
pass
329-
else:
330-
if publicId in\
327+
if not correct or nameLower != "html"\
328+
or publicId in\
331329
("+//silmaril//dtd html pro v0r11 19970101//en",
332330
"-//advasoft ltd//dtd html 3.0 aswedit + extensions//en",
333331
"-//as//dtd html 3.0 aswedit + extensions//en",
@@ -397,13 +395,19 @@ def processDoctype(self, name, publicId, systemId, correct):
397395
"-//webtechs//dtd mozilla html//en",
398396
"-/w3c/dtd html 4.0 transitional/en",
399397
"html")\
400-
or (publicId in\
398+
or (publicId in\
401399
("-//w3c//dtd html 4.01 frameset//EN",
402400
"-//w3c//dtd html 4.01 transitional//EN") and systemId == None)\
403-
or (systemId != None and\
401+
or (systemId != None and\
404402
systemId == "http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd"):
405-
#XXX quirks mode
406-
pass
403+
self.compatMode = "quirks"
404+
elif publicId in\
405+
("-//w3c//dtd xhtml 1.0 frameset//EN",
406+
"-//w3c//dtd xhtml 1.0 transitional//EN")\
407+
or (publicId in\
408+
("-//w3c//dtd html 4.01 frameset//EN",
409+
"-//w3c//dtd html 4.01 transitional//EN") and systemId == None):
410+
self.compatMode = "limited-quirks"
407411

408412
self.parser.phase = self.parser.phases["beforeHtml"]
409413

@@ -412,18 +416,21 @@ def processSpaceCharacters(self, data):
412416

413417
def processCharacters(self, data):
414418
self.parser.parseError("expected-doctype-but-got-chars")
419+
self.compatMode = "quirks"
415420
self.parser.phase = self.parser.phases["beforeHtml"]
416421
self.parser.phase.processCharacters(data)
417422

418423
def processStartTag(self, name, attributes):
419424
self.parser.parseError("expected-doctype-but-got-start-tag",
420425
{"name": name})
426+
self.compatMode = "quirks"
421427
self.parser.phase = self.parser.phases["beforeHtml"]
422428
self.parser.phase.processStartTag(name, attributes)
423429

424430
def processEndTag(self, name):
425431
self.parser.parseError("expected-doctype-but-got-end-tag",
426432
{"name": name})
433+
self.compatMode = "quirks"
427434
self.parser.phase = self.parser.phases["beforeHtml"]
428435
self.parser.phase.processEndTag(name)
429436

0 commit comments

Comments
 (0)