#!/bin/sh
# Indent /# (block quotes) and /p (intended poetry).
awk '\
/^\/[#p]$/ { in_indent=1; print; next; } \
/^[#p]\/$/ { in_indent=0; print; next; } \
/^\/[*$]$/ { print; next; } \
/^[*$]\/$/ { print; next; } \
{ if (in_indent) \
    print "    " $0; \
  else
    print; \
}' $1 > text-1.txt
# Strip notes and handle simple formatting:
#	<tb>
sed -e 's/<tb>/       *       *       *       *       */' \
  -e 's/<\/\?corr[^>]*>//g' -e '/^\[Blank [pP]age\]$/d' \
  -e 's/\[\*\*[^]]*\]//g' text-1.txt > text-2.txt
# Italics and bold; strip f & g
sed -e 's/<\/\?i>/_/g' -e 's/<\/\?b>/=/g' -e 's/\/\?[fg]>//' \
  text-2.txt > text-1.txt
# Small Caps
sed -e 's/<sc>//g' -e 's/<\/sc>//g' text-1.txt | awk '\
// { if (in_sc) $1 = "" $1; in_sc=0; } \
/[^]*$/ { in_sc=1; print $0 ""; next; } \
{ if (in_sc) \
    print "" $0 ""; \
  else
    print; \
}' | tee text2.txt | perl -e 'while(<>) { $_ =~ s/([^]*)/\U\1\E/g; print; }' > $2
