#!/bin/rc
# para - add paragraph tags to text
# (if a paragraph begins with an HTML tag, skip it
awk '
/^<[^\/]/ { html += 1; }
/./ { line(); if(last_line) print last_line; last_line = $0 }
/^$/ { newpara(); last_line = $0; print "" }
END { newpara() }
/^<\// { html -= 1; }
function newpara() {
printf("%s", last_line);
if(!html && inpara) print "</p>";
else print "";
inpara = 0;
}
function line() {
if(!html && !inpara) {
printf("<p>");
inpara = 1;
}
}
' $*
|