From 645323155b3d3d952f9633446e6697247dfb1b88 Mon Sep 17 00:00:00 2001 From: Gabriel Hurley Date: Tue, 28 Dec 2010 22:53:28 +0000 Subject: [PATCH] Fixed #14912 -- Expanded documentation for the urlize template filter. Thanks to adamv for the draft patch. git-svn-id: http://code.djangoproject.com/svn/django/trunk@15086 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- docs/ref/templates/builtins.txt | 40 +++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/docs/ref/templates/builtins.txt b/docs/ref/templates/builtins.txt index 1086328681c..5dea1532824 100644 --- a/docs/ref/templates/builtins.txt +++ b/docs/ref/templates/builtins.txt @@ -2072,38 +2072,54 @@ If ``value`` is ``"http://www.example.org/"``, the output will be urlize ~~~~~~ -Converts URLs in plain text into clickable links. +Converts URLs in text into clickable links. -Note that if ``urlize`` is applied to text that already contains HTML markup, -things won't work as expected. Apply this filter only to *plain* text. +Works on links beginning with ``http://``, ``https://``, or ``www.`` and +ending with ``.org``, ``.net`` or ``.com``. Links can have trailing punctuation +(periods, commas, close-parens) and leading punctuation (opening parens) and +``urlize`` will still do the right thing. + +Links generated by ``urlize`` have a ``rel="nofollow"`` attribute added +to them. For example:: {{ value|urlize }} If ``value`` is ``"Check out www.djangoproject.com"``, the output will be -``"Check out www.djangoproject.com"``. +``"Check out www.djangoproject.com"``. + +The ``urlize`` filter also takes an optional parameter ``autoescape``. If +``autoescape`` is ``True``, the link text and URLs will be escaped using +Django's built-in :tfilter:`escape` filter. The default value for +``autoescape`` is ``True``. + +.. note:: + + If ``urlize`` is applied to text that already contains HTML markup, + things won't work as expected. Apply this filter only to plain text. .. templatefilter:: urlizetrunc urlizetrunc ~~~~~~~~~~~ -Converts URLs into clickable links, truncating URLs longer than the given -character limit. +Converts URLs into clickable links just like urlize_, but truncates URLs +longer than the given character limit. -As with urlize_, this filter should only be applied to *plain* text. - -**Argument:** Length to truncate URLs to +**Argument:** Number of characters that link text should be truncated to, +including the ellipsis that's added if truncation is necessary. For example:: {{ value|urlizetrunc:15 }} If ``value`` is ``"Check out www.djangoproject.com"``, the output would be -``'Check out www.djangopr...'``. +``'Check out www.djangopr...'``. + +As with urlize_, this filter should only be applied to plain text. .. templatefilter:: wordcount