Skip to content

Commit ec00c92

Browse files
committed
start with InTable
--HG-- extra : convert_revision : svn%3Aacbfec75-9323-0410-a652-858a13e371e0/trunk%40104
1 parent 4ec27bf commit ec00c92

File tree

2 files changed

+54
-7
lines changed

2 files changed

+54
-7
lines changed

parser.py

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,54 @@ def startTagIsIndex(self, name, attributes):
889889
self.parser.processStartTag("hr")
890890
self.parser.processEndTag("form")
891891

892-
class InTable(InsertionMode): pass
892+
class InTable(InsertionMode):
893+
# http://www.whatwg.org/specs/web-apps/current-work/#in-table
894+
895+
# helper methods
896+
def clearStackToTableContext(self):
897+
# "clear the stack back to a table context"
898+
while self.parser.openElements[-1].name not in ("table", "html"):
899+
self.parser.openElements.pop()
900+
self.parser.parseError()
901+
902+
# When the current node is <html> it's an innerHTML case
903+
904+
905+
# processing methods
906+
def processCharacter(self, data):
907+
# XXX
908+
pass
909+
910+
def processComment(self, data):
911+
# XXX AT Perhaps this should be done in InsertionMode and then we can
912+
# overwrite it when you don't need to do this...
913+
self.parser.openElements[-1].appendChild(CommentNode(data))
914+
915+
def processStartTag(self, name, attributes):
916+
handlers = utils.MethodDispatcher([
917+
("caption", self.startTagCaption),
918+
("colgroup", self.startTagColgroup),
919+
("col", self.startTagCol),
920+
(("tbody", "tfoot", "thead"), self.startTagRowGroup),
921+
(("td", "th", "tr"), self.startTagImplyTbody),
922+
("table", self.startTagTable)
923+
])
924+
# XXX Can we handle this through the anything else case??
925+
handlers.setDefaultValue(self.processAnythingElse)
926+
handlers[name](name, attributes)
927+
928+
def startTagCaption(self, name, attributes):
929+
self.clearStackToTableContext()
930+
# XXX insert marker etc.
931+
932+
def startTagColgroup(self, name="colgroup", attributes={}):
933+
self.clearStackToTableContext()
934+
# XXX switch modes
935+
936+
def startTagCol(self, name, attributes):
937+
self.startTagColgroup()
938+
self.parser.processStartTag(name, attributes)
939+
893940
class InCaption(InsertionMode): pass
894941
class InColumnGroup(InsertionMode): pass
895942
class InTableBody(InsertionMode): pass
@@ -972,7 +1019,7 @@ def endTagTableElements(self, name):
9721019
self.parser.parseError()
9731020
# XXX table elements in scope blah...
9741021

975-
def processAnythingElse(self):
1022+
def processAnythingElse(self, name, attributes={}):
9761023
self.parser.parseError()
9771024

9781025
class AfterBody(InsertionMode):
@@ -985,7 +1032,7 @@ def processStartTag(self, name, attributes):
9851032
self.parser.processStartTag(name, attributes)
9861033

9871034
def processEndTag(self, name):
988-
handlers = utils.MethodDispatcher([('html',self.endTagHtml)])
1035+
handlers = utils.MethodDispatcher([("html", self.endTagHtml)])
9891036
handlers.setDefaultValue(self.endTagOther)
9901037
handlers[name](name)
9911038

utils/utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
class MethodDispatcher(dict):
22
"""Dict with 2 special properties:
33
4-
On initiation, keys that are lists, sets or tuples are converted to
5-
multiple keys so accessing any one of the items in the original
4+
On initiation, keys that are lists, sets or tuples are converted to
5+
multiple keys so accessing any one of the items in the original
66
list-like object returns the matching value
7-
7+
88
md = MethodDispatcher({["foo", "bar"]:"baz"})
99
md["foo"] == "baz"
1010
@@ -21,7 +21,7 @@ def __init__(self, items=()):
2121
else:
2222
_dictEntries.append((name, value))
2323
dict.__init__(self, _dictEntries)
24-
24+
2525
def setDefaultValue(self, value):
2626
self.defaultValue = value
2727

0 commit comments

Comments
 (0)