#!/bin/bash

Convert_html () {
	sed -e 's/<p>//gi' \
	-e 's/<\/p>//gi' \
	-e 's/^[ \t]*<h5>/===== /gi' \
	-e 's/<\/h5>/ =====/gi' \
	-e 's/^[ \t]*<h4>/==== /gi' \
	-e 's/<\/h4>/ ====/gi' \
	-e 's/^[ \t]*<h3>/=== /gi' \
	-e 's/<\/h3>/ ===/gi' \
	-e 's/^[ \t]*<h2>/== /gi' \
	-e 's/<\/h2>/ ==/gi' \
	-e 's/^[ \t]*<h1>/= /gi' \
	-e 's/<\/h1>/ =/gi' \
	-e "s/<b>/\'\'\'/gi" \
	-e "s/<\/b>/\'\'\'/gi" \
	-e "s/<i><b>/\'\'\'\'\'/gi" \
	-e "s/<\/b><\/i>/\'\'\'\'\'/gi" \
	-e 's/<pre>/{{{/gi' \
	-e 's/<\/pre>/}}}/gi' \
	-e 's/<xmp>/{{{/gi' \
	-e 's/<\/xmp>/}}}/gi' \
	-e '/<a name=/d' \
	-e '/<A NAME=/d' \
	-e 's/<br>/\n/gi' \
	-e 's/<verbatim>/{{{/gi' \
	-e 's/<\/verbatim>/}}}/gi' \
	-e 's/<li>/ \* /gi' \
	-e 's/<\/li>//gi' \
	-e 's/<ul>//gi' \
	-e 's/<\/ul>//gi' \
	-e 's/<tt>/`/gi' \
	-e 's/<\/tt>/`/gi' \
	-e 's/<strike>/--(/gi' \
	-e 's/<\/strike>/)--/gi' \
	-e 's/<u>/__/gi' \
	-e 's/<\/u>/__/gi' \
	-e 's/<html>//gi' \
	-e 's/<\/html>//gi' \
	-e 's/<body>//gi' \
	-e 's/<\/body>//gi' \
	-e "s/<i>/\'\'/gi" \
	-e "s/<\/i>/''/gi" \
	-e 's/<a href=//gi' \
	-e 's/>.*<\/a>//gi' \
	-e 's/<\/a>//gi' \
	-e "s/<cite>/\'\'/gi" \
	-e "s/<\/cite>/\'\'/gi" \
	-e 's/<ol>//g' \
	-e 's/<\/ol>//g'
}


#### uncomment this if you want to just do a one off on a single page
#cat $1 | Convert_html > $1.new;
#rm $1;
#mv $1.new $1;

#### this is to plow through all the pages.  comment out if you don't want it.
for i in  /usr/www/moin/data/pages/*/revisions/*;
	do cat $i|Convert_html > $i.new;
		mv $i $i.old;
		mv $i.new $i;
	done;

#### D'Arcy MacIsaac  (macisaac AT andrew.cmu.edu)
