8000 Add publicId and systemId to Doctype's while building the tree (not a… · html5lib/html5lib-python@18fb114 · GitHub
[go: up one dir, main page]

Skip to content

Commit 18fb114

Browse files
committed
Add publicId and systemId to Doctype's while building the tree (not all trees support these attributes)
--HG-- extra : convert_revision : svn%3Aacbfec75-9323-0410-a652-858a13e371e0/trunk%40880
1 parent 444e5b3 commit 18fb114

File tree

6 files changed

+29
-6
lines changed

6 files changed

+29
-6
lines changed

src/html5lib/html5parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ def processDoctype(self, name, publicId, systemId, correct):
322322
systemId != None:
323323
self.parser.parseError(_("Erroneous DOCTYPE."))
324324
# XXX need to update DOCTYPE tokens
325-
self.tree.insertDoctype(name)
325+
self.tree.insertDoctype(name, publicId, systemId)
326326

327327
if publicId == None:
328328
publicId = ""

src/html5lib/treebuilders/_base.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,11 @@ def elementInActiveFormattingElements(self, name):
207207
return item
208208
return False
209209

210-
def insertDoctype(self, name):
211-
self.document.appendChild(self.doctypeClass(name))
210+
def insertDoctype(self, name, publicId, systemId):
211+
doctype = self.doctypeClass(name)
212+
doctype.publicId = publicId
213+
doctype.systemId = systemId
214+
self.document.appendChild(doctype)
212215

213216
def insertComment(self, data, parent=None):
214217
if parent is None:

src/html5lib/treebuilders/dom.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ def documentClass(self):
7373
self.dom = minidom.getDOMImplementation().createDocument(None,None,None)
7474
return self
7575

76-
def insertDoctype(self, name):
76+
def insertDoctype(self, name, publicId, systemId):
7777
domimpl = minidom.getDOMImplementation()
78-
doctype = domimpl.createDocumentType(name,None,None)
78+
doctype = domimpl.createDocumentType(name, publicId, systemId)
7979
self.document.appendChild(NodeBuilder(doctype))
8080
doctype.ownerDocument = self.dom
8181

src/html5lib/treebuilders/etree.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,24 @@ class DocumentType(Element):
135135
def __init__(self, name):
136136
Element.__init__(self, "<!DOCTYPE>")
137137
self._element.text = name
138+
139+
def _getPublicId(self):
140+
return self._element.get(u"publicId", None)
141+
142+
def _setPublicId(self, value):
143+
if value is not None:
144+
self._element.set(u"publicId", value)
145+
146+
publicId = property(_getPublicId, _setPublicId)
147+
148+
def _getSystemId(self):
149+
return self._element.get(u"systemId", None)
150+
151+
def _setSystemId(self, value):
152+
if value is not None:
153+
self._element.set(u"systemId", value)
154+
155+
systemId = property(_getSystemId, _setSystemId)
138156

139157
class Document(Element):
140158
def __init__(self):

src/html5lib/treebuilders/simpletree.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ class DocumentType(Node):
107107
type = 3
108108
def __init__(self, name):
109109
Node.__init__(self, name)
110+
self.publicId = u""
111+
self.systemId = u""
110112

111113
def __unicode__(self):
112114
if self.name:

src/html5lib/treebuilders/soup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def documentClass(self):
103103
self.soup = BeautifulSoup("")
104104
return Element(self.soup, self.soup)
105105

106-
def insertDoctype(self, name):
106+
def insertDoctype(self, name, publicId, systemId):
107107
self.soup.insert(0, Declaration(name))
108108

109109
def elementClass(self, name):

0 commit comments

Comments
 (0)
0