Skip to content

Commit a4076d7

Browse files
committed
A very crude first attempt at serializing namespaced attributes.
1 parent 65aa7e9 commit a4076d7

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

html5lib/serializer/htmlserializer.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
from ..constants import voidElements, booleanAttributes, spaceCharacters
1313
from ..constants import rcdataElements, entities, xmlEntities
14+
from ..constants import unadjustForeignAttributes
1415
from .. import utils
1516
from xml.sax.saxutils import escape
1617

@@ -233,8 +234,14 @@ def serialize(self, treewalker, encoding=None):
233234
elif in_cdata:
234235
self.serializeError(_("Unexpected child element of a CDATA element"))
235236
for (attr_namespace, attr_name), attr_value in token["data"].items():
236-
# TODO: Add namespace support here
237-
k = attr_name
237+
if (attr_namespace, attr_name) in unadjustForeignAttributes:
238+
k = unadjustForeignAttributes[(attr_namespace, attr_name)]
239+
elif attr_namespace is not None:
240+
self.serializeError(_("Cannot serialize attribute in %s namespace" % attr_namespace))
241+
continue
242+
else:
243+
k = attr_name
244+
238245
v = attr_value
239246
yield self.encodeStrict(' ')
240247

0 commit comments

Comments
 (0)