8000 Fix Doctype tokens generated by tree walkers wrt publicId and systemI… · awesome-python/html5lib-python@fcf0d4a · GitHub
[go: up one dir, main page]

Skip to content

Commit fcf0d4a

Browse files
committed
Fix Doctype tokens generated by tree walkers wrt publicId and systemId attributes (not all trees support these attributes)
--HG-- extra : convert_revision : svn%3Aacbfec75-9323-0410-a652-858a13e371e0/trunk%40881
1 parent 18fb114 commit fcf0d4a

File tree

4 files changed

+7
-6
lines changed

4 files changed

+7
-6
lines changed

src/html5lib/treewalkers/_base.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,10 @@ def text(self, data):
5151
def comment(self, data):
5252
return {"type": "Comment", "data": unicode(data)}
5353

54-
def doctype(self, name):
55-
return {"type": "Doctype", "name": unicode(name),
56-
"data": name and name.upper() == "HTML"}
54+
def doctype(self, name, publicId=None, systemId=None, correct=True):
55+
return {"type": "Doctype", "name": name and unicode(name) or None,
56+
"publicId": publicId, "systemId": systemId,
57+
"correct": correct}
5758

5859
def unknown(self, nodeType):
5960
return self.error(_("Unknown node type: ") + nodeType)

src/html5lib/treewalkers/dom.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
class TreeWalker(_base.NonRecursiveTreeWalker):
1111
def getNodeDetails(self, node):
1212
if node.nodeType == Node.DOCUMENT_TYPE_NODE:
13-
return _base.DOCTYPE, node.nodeName or ''
13+
return _base.DOCTYPE, node.name, node.publicId, node.systemId
1414

1515
elif node.nodeType in (Node.TEXT_NODE, Node.CDATA_SECTION_NODE):
1616
return _base.TEXT, node.nodeValue

src/html5lib/treewalkers/genshistream.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def tokens(self, event, next):
5757
yield token
5858

5959
elif kind == DOCTYPE:
60-
yield self.doctype(data[0])
60+
yield self.doctype(*data)
6161

6262
elif kind in (XML_DECL, DOCTYPE, START_NS, END_NS, \
6363
START_CDATA, END_CDATA, PI):

src/html5lib/treewalkers/simpletree.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def getNodeDetails(self, node):
2626
return (_base.DOCUMENT,)
2727

2828
elif node.type == 3: # DocumentType
29-
return _base.DOCTYPE, node.name
29+
return _base.DOCTYPE, node.name, node.publicId, node.systemId
3030

3131
elif node.type == 4: # TextNode
3232
return _base.TEXT, node.value

0 commit comments

Comments
 (0)
0