Skip to content
Myr

update the Docstring of do_truncate, add useful examples

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by AquarHEAD L · committed by AquarHEAD L · parent 21a2010 · Browse files · 1 file+6 added−5 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+6 added−5 removed

  • other:+6 added−5 removed

1 file+6 added−5 removed

modified:jinja2/filters.py+6 added-5 removed
441 unmodified lines
442def do_truncate(s, length=255, killwords=False, end='...'):443 """Return a truncated copy of the string. The length is specified444 with the first parameter which defaults to ``255``. If the second445 parameter is ``true`` the filter will cut the text at length. Otherwise446 it will try to save the last word. If the text was in fact446 it will discard the last word. If the text was in fact447 truncated it will append an ellipsis sign (``"..."``). If you want a448 different ellipsis sign than ``"..."`` you can specify it using the449 third parameter.450451 .. sourcecode jinja::451 .. sourcecode:: jinja452453 {{ mytext|truncate(300, false, '&raquo;') }}454 truncate mytext to 300 chars, don't split up words, use a455 right pointing double arrow as ellipsis sign.453 {{ "foo bar"|truncate(5) }}454 -> "foo ..."455 {{ "foo bar"|truncate(5, True) }}456 -> "foo b..."457 """458 if len(s) <= length:459 return s460 elif killwords:
369 unmodified lines