summaryrefslogtreecommitdiff
path: root/bs4/builder/_html5lib.py
diff options
context:
space:
mode:
authorLeonard Richardson <leonardr@segfault.org>2015-06-24 17:03:40 -0400
committerLeonard Richardson <leonardr@segfault.org>2015-06-24 17:03:40 -0400
commit905f3b0bb450d9304810c712d6d1280b449af041 (patch)
tree84e3e6be11f1a980458e83d41747fe61dd98f0a3 /bs4/builder/_html5lib.py
parent8fb4389df679d38add64014f5a1b71d6d4820e1f (diff)
If the initial <html> tag contains a CDATA list attribute such as
'class', the html5lib tree builder will now turn its value into a list, as it would with any other tag. [bug=1296481]
Diffstat (limited to 'bs4/builder/_html5lib.py')
-rw-r--r--bs4/builder/_html5lib.py14
1 files changed, 12 insertions, 2 deletions
diff --git a/bs4/builder/_html5lib.py b/bs4/builder/_html5lib.py
index ea8ff43..ad3c6ef 100644
--- a/bs4/builder/_html5lib.py
+++ b/bs4/builder/_html5lib.py
@@ -9,7 +9,10 @@ from bs4.builder import (
HTML_5,
HTMLTreeBuilder,
)
-from bs4.element import NamespacedAttribute
+from bs4.element import (
+ NamespacedAttribute,
+ whitespace_re,
+)
import html5lib
from html5lib.constants import namespaces
from bs4.element import (
@@ -103,7 +106,13 @@ class AttrList(object):
def __iter__(self):
return list(self.attrs.items()).__iter__()
def __setitem__(self, name, value):
- "set attr", name, value
+ # If this attribute is a multi-valued attribute for this element,
+ # turn its value into a list.
+ list_attr = HTML5TreeBuilder.cdata_list_attributes
+ if (name in list_attr['*']
+ or (self.element.name in list_attr
+ and name in list_attr[self.element.name])):
+ value = whitespace_re.split(value)
self.element[name] = value
def items(self):
return list(self.attrs.items())
@@ -180,6 +189,7 @@ class Element(html5lib.treebuilders._base.Node):
return AttrList(self.element)
def setAttributes(self, attributes):
+
if attributes is not None and len(attributes) > 0:
converted_attributes = []