Class TextSerializer
object --+
|
TextSerializer
Produces plain text from an event stream.
Only text events are included in the output. Unlike the other serializer,
special XML characters are not escaped:
>>> from genshi.builder import tag
>>> elem = tag.div(tag.a('<Hello!>', href='foo'), tag.br)
>>> print elem
<div><a href="foo"><Hello!></a><br/></div>
>>> print ''.join(TextSerializer()(elem.generate()))
<Hello!>
If text events contain literal markup (instances of the Markup class),
that markup is by default passed through unchanged:
>>> elem = tag.div(Markup('<a href="foo">Hello & Bye!</a><br/>'))
>>> print elem.generate().render(TextSerializer)
<a href="foo">Hello & Bye!</a><br/>
You can use the strip_markup to change this behavior, so that tags and
entities are stripped from the output (or in the case of entities,
replaced with the equivalent character):
>>> print elem.generate().render(TextSerializer, strip_markup=True)
Hello & Bye!
|
__init__(self,
strip_markup=False)
Create the serializer. |
|
|
|
|
Inherited from object :
__delattr__ ,
__getattribute__ ,
__hash__ ,
__new__ ,
__reduce__ ,
__reduce_ex__ ,
__repr__ ,
__setattr__ ,
__str__
|
Inherited from object :
__class__
|
__init__(self,
strip_markup=False)
(Constructor)
|
|
Create the serializer.
- Parameters:
strip_markup - whether markup (tags and encoded characters) found
in the text should be removed
- Overrides:
object.__init__
|