| 1 | """ |
| 2 | >>> from django.utils.text import truncate_html_words |
| 3 | |
| 4 | >>> a = "It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout." |
| 5 | >>> truncate_html_words(a, 8) |
| 6 | u'It is a long established fact that a ...' |
| 7 | |
| 8 | >>> a = "It is a long \\nestablished fact that a reader will be distracted by the readable content of a page when looking at its layout." |
| 9 | >>> truncate_html_words(a, 8) |
| 10 | u'It is a long \\nestablished fact that a ...' |
| 11 | |
| 12 | >>> a = 'It is a <a href="xyz.html"\\nid="xyz">long established fact that a reader will be distracted by the readable content</a> of a page when looking at its layout.' |
| 13 | >>> truncate_html_words(a, 8) |
| 14 | u'It is a <a href="xyz.html"\\nid="xyz">long established fact that a ...</a>' |
| 15 | |
| 16 | >>> a = 'Fact: Python > Ruby. It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout.' |
| 17 | >>> truncate_html_words(a, 8) |
| 18 | u'Fact: Python > Ruby. It is a long established ...' |
| 19 | |
| 20 | >>> a = 'Fact: Ruby < <strong>Python</strong>.<br /> <a href="xyz.html" id="xyz">It <em>is</em> a long established fact that a reader will be distracted</a> bythe readable content of a page when looking at its layout.' |
| 21 | >>> truncate_html_words(a, 8) |
| 22 | u'Fact: Ruby < <strong>Python</strong>.<br /> <a href="xyz.html" id="xyz">It <em>is</em> a long established ...</a>' |
| 23 | |
| 24 | >>> a = 'Fact: Ruby < <strong>Python</strong>.<br /> <a href="xyz.html"\\nid="xyz">It <em>is</em> a long established fact that a reader will be distracted</a> by the readable content of a page when looking at its layout.' |
| 25 | >>> truncate_html_words(a, 8) |
| 26 | u'Fact: Ruby < <strong>Python</strong>.<br /> <a href="xyz.html"\\nid="xyz">It <em>is</em> a long established ...</a>' |
| 27 | |
| 28 | >>> a = 'Fact: Ruby < <strong>Python</strong>.<br /> <a href="xyz.html"\\nid="xyz">It > <em>is</em> a long established fact that a reader will be distracted</a> by the readable content of a page when looking at its layout.' |
| 29 | >>> truncate_html_words(a, 8) |
| 30 | u'Fact: Ruby < <strong>Python</strong>.<br /> <a href="xyz.html"\\nid="xyz">It > <em>is</em> a long established ...</a>' |
| 31 | |
| 32 | # Oops. Not smart enough after all. But proper behavior according to code. |
| 33 | >>> a = 'It is a <long established fact> that a reader will be distracted by the readable content of a page when looking at its layout.' |
| 34 | >>> truncate_html_words(a, 8) |
| 35 | u'It is a <long established fact> that a reader will be ...</long>' |
| 36 | """ |
| 37 | |
| 38 | if __name__ == "__main__": |
| 39 | import doctest |
| 40 | doctest.testmod() |