Mercurial > genshi > mirror
changeset 177:553866249cb0 trunk
* Minor fix for the XHTML serializer (the local namespace var got clobbered)
* Additional unit tests for empty element serialization, and using XHTML as non-default namespace (with a prefix)
author | cmlenz |
---|---|
date | Mon, 21 Aug 2006 15:00:35 +0000 |
parents | 00212b14903d |
children | ba7556e3a835 |
files | markup/output.py markup/tests/output.py |
diffstat | 2 files changed, 24 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/markup/output.py +++ b/markup/output.py @@ -208,14 +208,14 @@ tag, attrib = data tagname = tag.localname - namespace = tag.namespace - if namespace: - if namespace in ns_mapping: - prefix = ns_mapping[namespace] + tagns = tag.namespace + if tagns: + if tagns in ns_mapping: + prefix = ns_mapping[tagns] if prefix: tagname = '%s:%s' % (prefix, tagname) else: - ns_attrib.append((QName('xmlns'), namespace)) + ns_attrib.append((QName('xmlns'), tagns)) buf = ['<', tagname] for attr, value in attrib + ns_attrib: @@ -231,8 +231,7 @@ buf += [' ', attrname, '="', escape(value), '"'] ns_attrib = [] - if (tag.namespace and tag not in namespace) or \ - tagname in empty_elems: + if (tagns and tagns != namespace) or tagname in empty_elems: kind, data, pos = stream.next() if kind is END: buf += [' />'] @@ -250,7 +249,7 @@ if tag.namespace: prefix = ns_mapping.get(tag.namespace) if prefix: - tagname = '%s:%s' % (prefix, tag.localname) + tagname = '%s:%s' % (prefix, tagname) yield Markup('</%s>' % tagname) elif kind is TEXT:
--- a/markup/tests/output.py +++ b/markup/tests/output.py @@ -94,6 +94,11 @@ output = XML(text).render(XHTMLSerializer) self.assertEqual(text, output) + def test_empty_script(self): + text = '<script src="foo.js" />' + output = XML(text).render(XHTMLSerializer) + self.assertEqual('<script src="foo.js"></script>', output) + def test_script_escaping(self): text = """<script>/*<![CDATA[*/ if (1 < 2) { alert("Doh"); } @@ -121,6 +126,13 @@ output = XML(text).render(XHTMLSerializer) self.assertEqual(text, output) + def test_xhtml_namespace_prefix(self): + text = """<html:div xmlns:html="http://www.w3.org/1999/xhtml"> + <html:strong>Hello</html:strong> + </html:div>""" + output = XML(text).render(XHTMLSerializer) + self.assertEqual(text, output) + class HTMLSerializerTestCase(unittest.TestCase): @@ -129,6 +141,11 @@ output = XML(text).render(HTMLSerializer) self.assertEqual('<foo> Do not mess \n\n with me </foo>', output) + def test_empty_script(self): + text = '<script src="foo.js" />' + output = XML(text).render(XHTMLSerializer) + self.assertEqual('<script src="foo.js"></script>', output) + def test_script_escaping(self): text = '<script>if (1 < 2) { alert("Doh"); }</script>' output = XML(text).render(HTMLSerializer)