Skip to main content

urlize

Converts URLs and email addresses in text into clickable links, optionally trimming long URLs and adding nofollow attributes.

def urlize(
text: string,
trim_url_limit: integer = None,
nofollow: boolean = False,
autoescape: boolean = False
) - > string

Converts URLs and email addresses in text into clickable HTML links.

Parameters

NameTypeDescription
textstringThe raw text containing URLs or email addresses to be converted into links.
trim_url_limitinteger = NoneThe maximum character length for displayed link text; URLs longer than this will be truncated.
nofollowboolean = FalseIf true, adds the 'rel="nofollow"' attribute to generated links to instruct search engines not to follow them.
autoescapeboolean = FalseIf true, escapes the input text and generated URLs to prevent XSS attacks by converting special characters to HTML entities.

Returns

TypeDescription
stringThe input text with URLs and email addresses wrapped in HTML anchor tags.