"fuzzy" links and emails (google.com, foo@bar.com).
schemas is an dict, where each key/value describes protocol/rule:
key - link prefix (usually, protocol name with : at the end, skype:
for example). linkify-it-py makes sure that prefix is not preceded with
alphanumeric char.
value - rule to check tail after link prefix
str
just alias to existing rule
dict
validate - either a re.Pattern (start with ^, and don't include the
link prefix itself), or a validator function which, given arguments
self, text and pos, returns the length of a match in text
starting at index pos. pos is the index right after the link prefix.
self can be used to access the linkify object to cache data.
normalize - optional function to normalize text & url of matched result
(for example, for twitter mentions).
options:
fuzzy_link - recognize URL-s without http(s):// head. Default True.
fuzzy_ip - allow IPs in fuzzy links above. Can conflict with some texts
like version numbers. Default False.
fuzzy_email - recognize emails without mailto: prefix. Default True.
--- - set True to terminate link with --- (if it's considered as long dash).
.test(text)
Searches linkifiable pattern and returns True on success or False on fail.
.pretest(text)
Quick check if link MAY BE can exist. Can be used to optimize more expensive
.test() calls. Return False if link can not be found, True - if .test()
call needed to know exactly.
.test_schema_at(text, name, position)
Similar to .test() but checks only specific protocol tail exactly at given
position. Returns length of found pattern (0 on fail).
.match(text)
Returns list of found link matches or null if nothing found.
Each match has:
schema - link schema, can be empty for fuzzy links, or // for
protocol-neutral links.
index - offset of matched text
last_index - index of next char after mathch end
raw - matched text
text - normalized text
url - link, generated from matched text
.matchAtStart(text)
Checks if a match exists at the start of the string. Returns Match
(see docs for match(text)) or null if no URL is at the start.
Doesn't work with fuzzy links.
.tlds(list_tlds, keep_old=False)
Load (or merge) new tlds list. Those are needed for fuzzy links (without schema)
to avoid false positives. By default:
2-letter root zones are ok.
biz|com|edu|gov|net|org|pro|web|xxx|aero|asia|coop|info|museum|name|shop|рф are ok.
encoded (xn--...) root zones are ok.
If that's not enough, you can reload defaults with more detailed zones list.
.add(key, value)
Add a new schema to the schemas object. As described in the constructor
definition, key is a link prefix (skype:, for example), and value
is a str to alias to another schema, or an dict with validate and
optionally normalize definitions. To disable an existing rule, use
.add(key, None).
.set(options)
Override default options. Missed properties will not be changed.