-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathmd2pod.pl
executable file
·58 lines (43 loc) · 1.18 KB
/
md2pod.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
52
53
54
55
56
57
58
#!/pro/bin/perl
use 5.12.0;
use warnings;
our $VERSION = "0.05 - 20201001";
-d ".git" or exit 0;
my $fmd = "Checklist.md";
my $fpod = $fmd =~ s/md$/pod/r;
my %c = map { $_ => (stat $_)[9] } $fmd, $fpod;
$c{$fmd} && $c{$fpod} && $c{$fpod} - $c{$fmd} > 2 and
die "Did you edit $fpod instead of $fmd\n";
my @m = stat $fmd;
my @p = stat $fpod;
my @t = stat $0;
$m[9] && $p[9] && $p[9] >= $m[9] && $p[9] >= $t[9] and exit 0;
my $mdp = eval { require Markdown::Pod; 1; };
unless ($mdp) {
warn "Markdown::Pod cannot be loaded\n$fpod cannot be generated\n";
exit (0);
}
say "Converting $fmd to $fpod";
open my $fh, "<", $fmd;
my $md = do { local $/; <$fh> };
close $fh;
# Prepare MD to prevent md2pod errors
$md =~ s/^```\K .*//gm;
$md =~ s/(-{20,})/"\xFF" x length $1/ge;
my $mp = Markdown::Pod->new;
my $pod = $mp->markdown_to_pod (
# encoding => "utf8", # don't!
dialect => "Standard",
markdown => $md,
);
# And fix misformatted pod
$pod =~ s{\xFF}{-}g;
$pod =~ s{=item -\K\n\n}{ }g;
$pod =~ s{[ \t]+\n}{\n}g;
$pod =~ s{\n\n\K\n+}{}g;
open my $ph, ">", $fpod;
print $ph "=encoding utf-8\n\n";
print $ph $pod;
close $ph;
my $t = (stat $fmd)[9] + 1;
utime $t, $t, $fpod;