`` tags.
There are options that affect output, and some of these are also applied to
links already found in the text. These are designed to allow you to set
attributes like ``rel="nofollow"`` or ``target``, or push outgoing links
through a redirection URL, and do this to links already in the text, as well.
``nofollow``
Add ``rel="nofollow"`` to non-relative links (both created by ``linkify()``
and those already present in the text). Defaults to ``True``.
``filter_url``
A callable through which the ``href`` attribute of links (both created by
``linkify()`` and already present in the text) will be passed. Must accept a
single argument and return a string.
``filter_text``
A callable through which the text of links (only those created by
``linkify``) will be passed. Must accept a single argument and return a
string.
``skip_pre``
Do not create new links inside ```` sections. Still follows
``nofollow``. Defaults to ``False``.
``parse_email``
Linkify email addresses with ``mailto:``. Defaults to ``False``.
``target``
Set a ``target`` attribute on links. Like ``nofollow``, if ``target`` is not
``None``, will set the attribute on links already in the text, as well.
Defaults to ``None``.
``delinkify()``
---------------
``bleach.delinkify()`` is basically the opposite of ``linkify()``. It strips
links out of text except, optionally, relative links, or links to domains
you've whitelisted.
``allow_domains``
Allow links to the domains in this list. Set to ``None`` or an empty list to
disallow all non-relative domains. See below for wildcards. Defaults to
``None``.
``allow_relative``
Allow relative links (i.e. those with no hostname). Defaults to ``False``.
Wildcards
^^^^^^^^^
To allow links to a domain and its subdomains, ``allow_domains`` accepts two
types of wildcard arguments in domains:
``*``
Allow a single level of subdomain. This can be anywhere in the hostname, even
the TLD. This allows you to, for example, allow links to ``example.*``.
``*.example.com`` will match both ``foo.example.com`` and ``example.com``.
::
>>> delinkify('bar', \
... allow_domains=['*.ex.*'])
u'bar'
>>> delinkify('bar', allow_domains=['*.ex.mp'])
u'bar
``**``
To allow any number of *preceding* subdomains, you can start a hostname with
``**``. Note that unlike ``*``, ``**`` may only appear once, and only at the
beginning of a hostname.
::
>>> delinkify('t', \
... allow_domains=['**.ex.mp'])
u't'
If ``**`` appears anywhere but the beginning of a hostname, ``delinkify``
will throw ``bleach.ValidationError`` (which is a ``ValueError`` subclass,
for easy catching).
.. _html5lib: http://code.google.com/p/html5lib/