Skip to content

Commit 4e8e048

Browse files
committed
Get non-namespaced mode working.
1 parent 9041a5d commit 4e8e048

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/html5lib/treebuilders/_base.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import warnings
21
from html5lib.constants import scopingElements, tableInsertModeElements, namespaces
32
try:
43
frozenset
@@ -115,7 +114,6 @@ def __init__(self, namespaceHTMLElements):
115114
self.defaultNamespace = "http://www.w3.org/1999/xhtml"
116115
else:
117116
self.defaultNamespace = None
118-
warnings.warn(u"namespaceHTMLElements=False is currently rather broken, you probably don't want to use it")
119117
self.reset()
120118

121119
def reset(self):

src/html5lib/treebuilders/etree_lxml.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,7 @@ def insertRoot(self, token):
304304
docStr += ' PUBLIC "%s" "%s"'%(self.doctype.publicId or "",
305305
self.doctype.systemId or "")
306306
docStr += ">"
307-
#TODO - this needs to work when elements are not put into the default ns
308-
docStr += "<html xmlns='http://www.w3.org/1999/xhtml'></html>"
307+
docStr += "<THIS_SHOULD_NEVER_APPEAR_PUBLICLY/>"
309308

310309
try:
311310
root = etree.fromstring(docStr)
@@ -321,9 +320,17 @@ def insertRoot(self, token):
321320
self.document = self.documentClass()
322321
self.document._elementTree = root.getroottree()
323322

324-
#Add the root element to the internal child/open data structures
323+
# Give the root element the right name
324+
name = token["name"]
325325
namespace = token.get("namespace", None)
326-
root_element = self.elementClass(token["name"], namespace)
326+
if namespace is None:
327+
etree_tag = name
328+
else:
329+
etree_tag = "{%s}%s"%(namespace, name)
330+
root.tag = etree_tag
331+
332+
#Add the root element to the internal child/open data structures
333+
root_element = self.elementClass(name, namespace)
327334
root_element._element = root
328335
self.document._childNodes.append(root_element)
329336
self.openElements.append(root_element)

0 commit comments

Comments
 (0)