diff options
author | Leonard Richardson <leonard.richardson@canonical.com> | 2012-02-16 16:33:40 -0500 |
---|---|---|
committer | Leonard Richardson <leonard.richardson@canonical.com> | 2012-02-16 16:33:40 -0500 |
commit | e1b321db7331752a3aea8dd7070dd0db4c60c51d (patch) | |
tree | 96ce9539fb1e0dbb1dc8b4f264737159e9a2cd1d /bs4/builder/_html5lib.py | |
parent | 1a50d9623831990ae0a78ea3a7e66fa098fe92ac (diff) |
It's a start, at least.
Diffstat (limited to 'bs4/builder/_html5lib.py')
-rw-r--r-- | bs4/builder/_html5lib.py | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/bs4/builder/_html5lib.py b/bs4/builder/_html5lib.py index 0d7a1a9..7ce69aa 100644 --- a/bs4/builder/_html5lib.py +++ b/bs4/builder/_html5lib.py @@ -8,6 +8,7 @@ from bs4.builder import ( HTML_5, HTMLTreeBuilder, ) +from bs4.element import NamespacedAttribute import html5lib from html5lib.constants import ( DataLossWarning, @@ -58,9 +59,6 @@ class TreeBuilderForHtml5lib(html5lib.treebuilders._base.TreeBuilder): def __init__(self, soup, namespaceHTMLElements): self.soup = soup - if namespaceHTMLElements: - warnings.warn("namespaceHTMLElements not supported yet", - DataLossWarning) super(TreeBuilderForHtml5lib, self).__init__(namespaceHTMLElements) def documentClass(self): @@ -76,9 +74,7 @@ class TreeBuilderForHtml5lib(html5lib.treebuilders._base.TreeBuilder): self.soup.object_was_parsed(doctype) def elementClass(self, name, namespace): - if namespace is not None: - warnings.warn("BeautifulSoup cannot represent elements in any namespace", DataLossWarning) - tag = self.soup.new_tag(name) + tag = self.soup.new_tag(name, namespace) return Element(tag, self.soup, namespace) def commentClass(self, data): @@ -144,6 +140,8 @@ class Element(html5lib.treebuilders._base.Node): def setAttributes(self, attributes): if attributes is not None and attributes != {}: for name, value in list(attributes.items()): + if isinstance(name, tuple): + name = NamespacedAttribute(*name) self.element[name] = value # The attributes may contain variables that need substitution. # Call set_up_substitutions manually. @@ -189,7 +187,7 @@ class Element(html5lib.treebuilders._base.Node): TextNode(child, self.soup)) def cloneNode(self): - tag = self.soup.new_tag(self.element.name) + tag = self.soup.new_tag(self.element.name, self.namespace) node = Element(tag, self.soup, self.namespace) for key,value in self.attributes: node.attributes[key] = value |