Ticket #11021: truncate-doc.diff

File truncate-doc.diff, 2.3 KB (added by Ben Spaulding, 16 years ago)

Documentation of truncatewords behavior re newlines.

  • django/template/defaultfilters.py

    diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py
    index 47e116c..531e6ab 100644
    a b def truncatewords(value, arg):  
    258258    Truncates a string after a certain number of words.
    259259
    260260    Argument: Number of words to truncate after.
     261
     262    Note that newlines within the string are removed.
    261263    """
    262264    from django.utils.text import truncate_words
    263265    try:
    def truncatewords_html(value, arg):  
    273275    Truncates HTML after a certain number of words.
    274276
    275277    Argument: Number of words to truncate after.
     278
     279    Note that newlines are preserved, unlike `truncatewords`.
    276280    """
    277281    from django.utils.text import truncate_html_words
    278282    try:
  • django/utils/text.py

    diff --git a/django/utils/text.py b/django/utils/text.py
    index fe46e26..0e03bd5 100644
    a b def wrap(text, width):  
    3838wrap = allow_lazy(wrap, unicode)
    3939
    4040def truncate_words(s, num):
    41     "Truncates a string after a certain number of words."
     41    """
     42    Truncates a string after a certain number of words.
     43
     44    Note that newlines within the string are removed.
     45    """
    4246    s = force_unicode(s)
    4347    length = int(num)
    4448    words = s.split()
    def truncate_html_words(s, num):  
    5458    Truncates html to a certain number of words (not counting tags and
    5559    comments). Closes opened tags if they were correctly closed in the given
    5660    html.
     61
     62    Note that newlines are preserved, unlike `truncate_words`.
    5763    """
    5864    s = force_unicode(s)
    5965    length = int(num)
  • docs/ref/templates/builtins.txt

    diff --git a/docs/ref/templates/builtins.txt b/docs/ref/templates/builtins.txt
    index f4e49a9..4dd5416 100644
    a b For example::  
    15101510
    15111511If ``value`` is ``"Joel is a slug"``, the output will be ``"Joel is ..."``.
    15121512
     1513Note that newlines within the string are removed.
     1514
    15131515.. templatefilter:: truncatewords_html
    15141516
    15151517truncatewords_html
    closed immediately after the truncation.  
    15221524This is less efficient than ``truncatewords``, so should only be used when it
    15231525is being passed HTML text.
    15241526
     1527Note that newlines are preserved, unlike the `truncatewords`_ filter.
     1528
    15251529.. templatefilter:: unordered_list
    15261530
    15271531unordered_list
Back to Top