File: linking.lsed

package info (click to toggle)
stx2any 1.56-2.3
  • links: PTS
  • area: main
  • in suites: bookworm
  • size: 748 kB
  • sloc: sh: 312; python: 288; lisp: 137; makefile: 126; sed: 1
file content (63 lines) | stat: -rw-r--r-- 1,898 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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#^ ##
}}}