| | 1 | truncate_tests = """ |
| | 2 | >>> from django.utils.text import truncate_words, truncate_html_words |
| | 3 | |
| | 4 | >>> text = \"\"\"modo suscipit seacula molestie legere |
| | 5 | ... duis odio in demonstraverunt eu |
| | 6 | ... iusto eum elit ea anteposuerit\"\"\" |
| | 7 | >>> |
| | 8 | >>> html = \"\"\"<p>modo suscipit <a href="/somelink/">seacula</a> molestie legere |
| | 9 | ... duis odio in demonstraverunt <strong>eu</strong> |
| | 10 | ... iusto eum elit ea anteposuerit\"\"\" |
| | 11 | >>> |
| | 12 | |
| | 13 | # truncate_words normalizes line endings to a single space |
| | 14 | >>> print truncate_words(text, 10) |
| | 15 | modo suscipit seacula molestie legere duis odio in demonstraverunt eu ... |
| | 16 | |
| | 17 | # truncate_words uses the space to determine word count |
| | 18 | # and doesn't deal with html. |
| | 19 | >>> print truncate_words(html, 10) |
| | 20 | <p>modo suscipit <a href="/somelink/">seacula</a> molestie legere duis odio in demonstraverunt ... |
| | 21 | |
| | 22 | # tuncate_html_words preserves line endings and html. Tags |
| | 23 | # are closed at the end of the newly tuncated text. |
| | 24 | >>> print truncate_html_words(text, 10) |
| | 25 | modo suscipit seacula molestie legere |
| | 26 | duis odio in demonstraverunt eu ... |
| | 27 | >>> |
| | 28 | >>> print truncate_html_words(html, 10) |
| | 29 | <p>modo suscipit <a href="/somelink/">seacula</a> molestie legere |
| | 30 | duis odio in demonstraverunt <strong>eu ...</strong></p> |
| | 31 | >>> |
| | 32 | """ |