Skip to content

Make urlize filter support mailto: scheme #1172

@septatrix

Description

@septatrix

Expected Behavior

The urlize filter should recognize the mailto: URI scheme and create a corresponding link.

>>> env.from_string('{{ "mailto:[email protected]"|urlize }}').render()
'<a href="mailto:[email protected]" rel="noopener">[email protected]</a>'

Actual Behavior

Instead the mail address does not get recognized as an address suitable for an anchor and is not modified by the filter.

>>> env.from_string('{{ "mailto:[email protected]"|urlize }}').render()
'mailto:[email protected]'

I already looked into the source code and noticed that urlize is only supported for http(s):// and not other protocols. However I think that albeit being rarer than normal web links mail links or other links should also be supported. E.g. ftp:// and also other schemes like tel:, data: or apt:.
As those would be hard to dynamically locate inside of a space separated string a better alternative would be to add an option to the filter so that it treats the whole passed string as one link naively.

Template Code

{{ "mailto:[email protected]"|urlize }}

Your Environment

  • Python version: 3.7
  • Jinja version: 2.10

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions