aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2021-01-30 16:06:41 +0000
committerJohn Ankarström <john@ankarstrom.se>2021-01-30 16:06:41 +0000
commit93abbf2b97b0c102de67586c3db8f87b845b43f2 (patch)
treecd60d087820912b076b7a572bf3017944f8b1e11
parent34edc530941a6195dd93bf8c8c87c609e2fb39db (diff)
downloadem-93abbf2b97b0c102de67586c3db8f87b845b43f2.tar.gz
Add htwrap
-rwxr-xr-xhtwrap56
1 files changed, 56 insertions, 0 deletions
diff --git a/htwrap b/htwrap
new file mode 100755
index 0000000..4b7de46
--- /dev/null
+++ b/htwrap
@@ -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>'