changeset 105:71f3db26eecb trunk

Include processing instructions in serialized streams.
author cmlenz
date Fri, 28 Jul 2006 15:15:50 +0000
parents f12e7987d7f4
children f9473bdc93b2
files markup/output.py markup/tests/output.py
diffstat 2 files changed, 15 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/markup/output.py
+++ b/markup/output.py
@@ -22,7 +22,7 @@
 from itertools import chain
 
 from markup.core import escape, Markup, Namespace, QName
-from markup.core import DOCTYPE, START, END, START_NS, END_NS, TEXT, COMMENT
+from markup.core import DOCTYPE, START, END, START_NS, END_NS, TEXT, COMMENT, PI
 
 __all__ = ['Serializer', 'XMLSerializer', 'HTMLSerializer']
 
@@ -154,6 +154,9 @@
             elif kind is COMMENT:
                 yield Markup('<!--%s-->' % data)
 
+            elif kind is PI:
+                yield Markup('<?%s %s?>' % data)
+
 
 class XHTMLSerializer(XMLSerializer):
     """Produces XHTML text from an event stream.
@@ -238,6 +241,9 @@
             elif kind is COMMENT:
                 yield Markup('<!--%s-->' % data)
 
+            elif kind is PI:
+                yield Markup('<?%s %s?>' % data)
+
 
 class HTMLSerializer(XHTMLSerializer):
     """Produces HTML text from an event stream.
@@ -308,6 +314,9 @@
             elif kind is COMMENT:
                 yield Markup('<!--%s-->' % data)
 
+            elif kind is PI:
+                yield Markup('<?%s %s?>' % data)
+
 
 class _PushbackIterator(object):
     """A simple wrapper for iterators that allows pushing items back on the
--- a/markup/tests/output.py
+++ b/markup/tests/output.py
@@ -73,6 +73,11 @@
         output = stream.render(XMLSerializer)
         self.assertEqual('<!--foo bar-->', output)
 
+    def test_processing_instruction(self):
+        stream = Stream([(Stream.PI, ('python', 'x = 2'), ('?', -1, -1))])
+        output = stream.render(XMLSerializer)
+        self.assertEqual('<?python x = 2?>', output)
+
 
 def suite():
     suite = unittest.TestSuite()
Copyright (C) 2012-2017 Edgewall Software