This file is copyright (c) 2004,2005,2006 by Panu Kalliokoski
and released under the license in ../LICENSE

This file has definitions for link abbreviations.  This is the second
phase of processing link abbreviations: the link data has (hopefully)
already been gathered by w_crosslink(s2aimpl.gatherlink).

The logic of this script is weird.  We have complicated rules for
deleting link data blocks.  The basic difficulty is that both the
blocks' beginning and end are marked with empty lines.  Whether it is a
link data block depends on the line that comes _after_ that.

Remove link data blocks.
{{{
/^$/,/./{
: del3
/^\[[A-Za-z0-9]\{1,\}\] /,/^$/d
/^%-%/b proceed
}
}}}

Generic link syntaces that can be confused with link data blocks.
Because labels have not yet been processed, protect against ''+'' as the
last character.
{{{
s#\[\([^][]*\)\]\[\([^][]*[^][`+]\)\]#`'w_generic_link(`\2', `\1')#g
s#^\[\([^][]*[^][`+]\)\]#w_generic_link(`\1')#g
}}}

Now we don't have anything that could be mistaken for beginning of link
data block, so we can jump and see whether this line was actually meant
to be deleted (because of the range it's in).
{{{
s#^#%-%#
b del3
: proceed
s#^%-%##
}}}

Labels.
{{{
s#\[+\([^][]*\)+\]#`'w_autolabel(`\1')#g
}}}

Rest of generic link syntaces.
{{{
s#\([^ ,.;:!?"'-]*[^[ ,.;:!?"'-]\)\[\([^][]*[^][`]\)\]#`'w_generic_link(`\2', `\1')#g
s#\([ ({<"'.:-]\)\[\([^][]*[^][`]\)\]#\1w_generic_link(`\2')#g
}}}

URLs.
{{{
s#^# #
s#\([ ([{<"'-]\)\(https*://[^ ]*[A-Za-z0-9_/]\)#\1w_url(`\2')#g
s#\([ ([{<"'-]\)\(ftps*://[^ ]*[A-Za-z0-9_/]\)#\1w_url(`\2')#g
s#\([ ([{<"'-]\)\(gopher://[^ ]*[A-Za-z0-9_/]\)#\1w_url(`\2')#g
s#\([ ([{<"'-]\)\(nntp://[^ ]*[A-Za-z0-9_/]\)#\1w_url(`\2')#g
s#\([ ([{<"'-]\)\(file:/[^ ]*[A-Za-z0-9_]\)#\1w_url(`\2')#g
s#\([ ([{<"'-]\)\(mailto:[^ ]*[A-Za-z0-9_]\)#\1w_url(`\2')#g
s#\([ ([{<"'-]\)\(news:[^ ]*[A-Za-z0-9_]\)#\1w_url(`\2')#g
s#^ ##
}}}

