Home | History | Annotate | Line # | Download | only in mantools
      1 #!/bin/sh
      2 
      3 # Crude script to convert formatted manpages to HTML. Requires GROFF_NO_SGR.
      4 
      5 while :
      6 do
      7     case $1 in
      8     -t) title=$2; shift; shift;;
      9     -*) echo "Usage: $0 [-t title] [file(s)]" 1>&2; exit 1;;
     10      *) break;;
     11     esac
     12 done
     13 
     14 echo "<!doctype html public \"-//W3C//DTD HTML 4.01 Transitional//EN\"
     15         \"https://www.w3.org/TR/html4/loose.dtd\">
     16 <html> <head>
     17 <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">
     18 <link rel='stylesheet' type='text/css' href='postfix-doc.css'>
     19 <title> $title </title>
     20 </head> <body> <pre>"
     21 
     22 #ESC=`echo x | tr '[x]' '[\033]'`
     23 
     24 sed '
     25 	s/\([<>&]\)\1/\1/g
     26 	s/&/\&amp;/g
     27 	s/_</\&lt;/g
     28 	s/<</\&lt;/g
     29 	s/</\&lt;/g
     30 	s/_>/\&gt;/g
     31 	s/>>/\&gt;/g
     32 	s/>/\&gt;/g
     33 	s;_\([^_]\);<i>\1</i>;g
     34 	s;.\(.\);<b>\1</b>;g
     35 
     36 	s;</i>\( *\)<i>;\1;g
     37 	s;</b>\( *\)<b>;\1;g
     38 
     39 	# Skip the redundant readme/html_directory blurb. The
     40 	# document names that follow will be hyperlinked.
     41 	/^<b>README FILES/{
     42 		h
     43 		N
     44 		N
     45 		g
     46 	}
     47 
     48 	# Generate anchors for sections.
     49 	/^<b>\([A-Z][-_A-Z0-9 ]*\)<\/b>/{
     50 		s//\1/
     51 		s/[ 	]*$//
     52 		h
     53 		y/ABCDEFGHIJKLMNOPQRSTUVWXYZ /abcdefghijklmnopqrstuvwxyz_/
     54 		s/^/<b><a name="/
     55 		s/$/">/
     56 		G
     57 		s/\n//
     58 		s;$;</a></b>;
     59 	}
     60 ' "$@"
     61 
     62 echo '</pre> </body> </html>'
     63