diff options
-rwxr-xr-x | htwrap | 56 |
1 files changed, 56 insertions, 0 deletions
@@ -0,0 +1,56 @@ +#!/bin/rc -e + +# htwrap -- create standalone HTML document + +flagfmt='t, 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) + echo '<meta http-equiv="Content-Type" content="text/html; charset='^$flagc^'">' + +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>' |