-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.tx2html
executable file
·40 lines (32 loc) · 1.21 KB
/
.tx2html
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
#!/bin/sh
set -xe
sed_minus_i()
{
# sed -i is not in posix, so emulate it for convenience
TMPFILE=temp
cp $2 "$TMPFILE"
sed "$1" "$TMPFILE" > $2
rm "$TMPFILE"
}
text2htmlsh()
{
FILE=$1
printf '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"> <pre>\n' > ${FILE}.html
cat $FILE >> ${FILE}.html
printf '</pre>\n' >> ${FILE}.html
# mark up directories
sed_minus_i 's/\([a-Z,0-9,/,-,.,_]*\/\)$/<a href="&">&<\/a>/g' ${FILE}.html
# mark up hyper links
sed_minus_i 's/\(http.*\)/<a href="&">&<\/a>/g' ${FILE}.html
# mark up mailing links
sed_minus_i 's/\([a-Z,0-9,.,-]*@.*\)/<a href="mailto:&">&<\/a>/g' ${FILE}.html
# If the title occurs on the first line then make it attr strong
sed_minus_i 's/\(^[^\t][a-Z].*\)/<br clear="left"\/><\/pre><dl><strong>&<\/strong><\/dl><pre>/' ${FILE}.html
# mark up anything that does not begin with a tab
sed_minus_i 's/\(^[^\t][a-Z].*\)/<br clear="left"\/><\/pre><dl>&<\/dl><pre>/g' ${FILE}.html
# mark up underlines
sed_minus_i 's/\(^[^\t]-.*\)/<\/pre><dd><hr\/><\/dd><pre>/g' ${FILE}.html
# mark up images
sed_minus_i 's/\([a-Z,0-9,\/,.,-]*.png\)/<\/pre><dl><img src="&" style="float:left;height:15em;margin-right:1em"><\/img><pre><\/dl>/g' ${FILE}.html
}
text2htmlsh $1