aboutsummaryrefslogtreecommitdiff
path: root/htwrap
blob: 32f38aa655b4ca9802b13d1a3b814ef868fe72b0 (plain)
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
#!/bin/rc -e
rfork E

# htwrap -- create standalone HTML document

flagfmt='t,C, c charset, d dir, l lang, v doctype'
args='[file ...]'

if(! ifs=() eval `{aux/getflags $*}){
	aux/usage
	exit usage
}

switch($flagv){
case 5
	echo '<!DOCTYPE html>'
case 4
	echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">'
case 4s
	echo '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">'
case x xhtml
	echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
case xs xhtmls
	echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'
case ''
	echo '<!DOCTYPE html>'
case *
	echo error: unknown doctype $flagv >[1=2]
	aux/usage
	exit usage
}

echo -n '<html'
if(! ~ $#flagl 0) echo -n ' lang="'^$flagl^'"'
if(! ~ $#flagd 0) echo -n ' dir="'^$flagd^'"'
echo '>'

if(~ $#flagC 0){
	if(! ~ $#flagc 0)
		echo '<meta http-equiv="Content-Type" content="text/html; charset='^$flagc^'">'
	if not
		echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">'
}

fn source{
	if(! ~ $#* 0)
		cat $*
	if not
		cat
}

if(! ~ $#flagt 0) # try to retrieve title from <h1> on first line
	source $* | sed '1s/^<h1>(.*)<\/h1>/<title>\1<\/title>\n&/'
if not
	source $*

echo '</html>'