-
Notifications
You must be signed in to change notification settings - Fork 4
/
clean_blockquotes.pl
executable file
·51 lines (31 loc) · 1.04 KB
/
clean_blockquotes.pl
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
#!/usr/local/bin/perl
# for moving with [tomd ](https://github.com/blog/2115-upgrading-your-textile-posts-to-markdown)
# from textile to markdown
# must run BEFORE the tomd scripts
# deals with multiline blockquotes and citations
my @file = `grep -lR 'bq..' /Users/peter/Branches/stmgrts/_posts/2017/*.textile`;
foreach my $file (@file) {
open (FILE, $file) || die "Can't open $file";
my ($FLAG_on, $output) = "";
while (<FILE>) {
if (/(p. |\?\?)/ && $FLAG_on) {
# end of block quote area
$FLAG_on = 0;
$output =~ s/> \n$/\n/; # remove last "> \n"
print STDERR qq |end bq. with '$_'\n|;
}
if (/bq\.\./ || $FLAG_on) {
$FLAG_on = 1;
s/bq\.\.//; # remove bq..
$_ = "bq. $_"; # add markdown blockquote >
print STDERR qq |bq. now: '$_'\n|;
}
s/\?\?(.*)\?\?/<cite>$1<\/cite>/;
$output .= $_;
}
close (FILE);
open (OUT, ">$file") || die "Can't open $file";
print OUT $output;
close (OUT);
print STDERR qq |output of $file now:\n $output\n|;
}