Mercurial > genshi > mirror
diff genshi/util.py @ 433:bc430fd7c54d trunk
More API docs.
author | cmlenz |
---|---|
date | Thu, 22 Mar 2007 21:12:03 +0000 |
parents | 073640758a42 |
children | 678278fa92e7 acf7c5ee36e7 |
line wrap: on
line diff
--- a/genshi/util.py +++ b/genshi/util.py @@ -139,7 +139,9 @@ def flatten(items): - """Flattens a potentially nested sequence into a flat list: + """Flattens a potentially nested sequence into a flat list. + + :param items: the sequence to flatten >>> flatten((1, 2)) [1, 2] @@ -159,6 +161,21 @@ def plaintext(text, keeplinebreaks=True): """Returns the text as a `unicode` string with all entities and tags removed. + + >>> plaintext('<b>1 < 2</b>') + u'1 < 2' + + The `keeplinebreaks` parameter can be set to ``False`` to replace any line + breaks by simple spaces: + + >>> plaintext('''<b>1 + ... < + ... 2</b>''', keeplinebreaks=False) + u'1 < 2' + + :param text: the text to convert to plain text + :param keeplinebreaks: whether line breaks in the text should be kept intact + :return: the text with tags and entities removed """ text = stripentities(striptags(text)) if not keeplinebreaks: @@ -208,7 +225,7 @@ _STRIPTAGS_RE = re.compile(r'<[^>]*?>') def striptags(text): - """Return a copy of the text with all XML/HTML tags removed. + """Return a copy of the text with any XML/HTML tags removed. >>> striptags('<span>Foo</span> bar') 'Foo bar' @@ -216,5 +233,8 @@ 'Foo' >>> striptags('Foo<br />') 'Foo' + + :param text: the string to remove tags from + :return: the text with tags removed """ return _STRIPTAGS_RE.sub('', text)