#! /bin/sh

#	plistservices module for Python 2.3+
#	See the License.text file for permitted use and legal disclaimer
#
#	Use this to install.
#
#		python2.3 setup.py install
#
#   The HTML is pretty readable as a text file.
#   try reading that.
#
#   Sarwat.
#   http://sarwat.net

echo "Please wait..."

translate_utf8_to_ascii="
import sys, codecs
utf8, ascii = codecs.lookup('utf-8'), codecs.lookup('ascii')

sys.stdin = utf8[2](sys.stdin)
sys.stdout = ascii[3](sys.stdout, errors='replace')

line = sys.stdin.readline()
while line:
	sys.stdout.write(line)
	line = sys.stdin.readline()
"

boldface_headings='
/<h.>/ { 
	match($0, "^[^<]*")
	printf "%s", substr($0, RSTART, RLENGTH)

	match($0, ">[^<]*")
	var_command = sprintf("echo \"\\fB%s\" | groff -Tascii | head -n 1", substr($0, RSTART+1, RLENGTH-1))
	system(var_command)
}
!/<h.>/
'

cat ./Readme.html | python -c "$translate_utf8_to_ascii" | awk "$boldface_headings" | sed -e "s/<[^>]*>//g" -e "s/&lt;/</g" -e "s/&gt;/>/g" |  ${PAGER:-less}

