blob: 1c70f362d828996f68b5a72ed18cb7b7d8f758a3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
#!/usr/bin/perl
# postconffix - add HTML paragraphs
# Basic operation:
#
# - Process input as text blocks separated by one or more empty
# (or all whitespace) lines.
#
# - Don't touch blocks that start with `<' in column zero.
#
# The only changes made are:
#
# - Put <p>..</p> around text blocks that start in column zero.
#
# - Put <pre>..</pre> around text blocks that start elsewhere.
#use Getopt::Std;
#$opt_h = undef;
#$opt_v = undef;
#getopts("hv");
#die "Usage: $0 [-hv]\n" if ($opt_h);
#push @ARGV, "/dev/null"; # XXX
while(<>) {
# Pass through comments and blank linkes before a text block.
if (/^(#|\s*$)/) {
print;
next;
}
# Gobble up the next text block.
$block = "";
do {
$_ =~ s/\s+\n$/\n/;
$block .= $_;
} while(($_ = <>) && /\S/);
# Don't touch a text block starting with < in column zero.
if ($block =~ /^</) {
print "$block\n";
}
# Meta block.
elsif ($block =~ /^%/) {
print "$block\n";
}
# Example block.
elsif ($block =~ /^\S+\s=/) {
print "<pre>\n$block</pre>\n\n";
}
# Pre-formatted block.
elsif ($block =~ /^\s/) {
print "<pre>\n$block</pre>\n\n";
}
# Paragraph block.
elsif ($block =~ /^\S/) {
print "<p>\n$block</p>\n\n";
}
# Can't happen.
else {
die "Unrecognized text block:\n$block";
}
}
|