commit code crimes for better footnote formatting
This commit is contained in:
parent
c6fd874bc5
commit
c38561f9a9
58
build.pl
58
build.pl
|
@ -42,31 +42,59 @@ sub post_to_meta {
|
|||
my %metadata;
|
||||
|
||||
open(MDIN, '<', $fname) or die "Unable to open $fname: " . $!;
|
||||
|
||||
# "parsing" loop
|
||||
my $contentlevel = "";
|
||||
my %content;
|
||||
while (<MDIN>) {
|
||||
chomp;
|
||||
if (/^(.+)?=(.*)$/) {
|
||||
$metadata{$1} = $2;
|
||||
} elsif (/^---$/) {
|
||||
last;
|
||||
if (/^--(.+)?--$/) {
|
||||
$contentlevel = $1;
|
||||
$content{$contentlevel} = "";
|
||||
} elsif ($contentlevel eq "") {
|
||||
if (/^(.+)?=(.*)$/) {
|
||||
$metadata{$1} = $2;
|
||||
} else {
|
||||
warn basename($fname) . ":" . $. . ": malformed line; ignored"
|
||||
}
|
||||
} else {
|
||||
warn basename($fname) . ":" . $. . ": malformed line; ignored"
|
||||
$content{$contentlevel} .= "$_\n";
|
||||
}
|
||||
}
|
||||
|
||||
my $body = do { local $/; <MDIN> };
|
||||
close(MDIN);
|
||||
|
||||
if (exists $content{"body"}) {
|
||||
my $ifn = 0;
|
||||
my %fn;
|
||||
my $parser = Markdent::Simple::Fragment->new;
|
||||
|
||||
# perl regexes give people like me too much power
|
||||
$content{"body"} =~ s{\$fn:(.+)\$}{
|
||||
$fn{$1} = ++$ifn;
|
||||
"<a class=\"fn\" name=\"fn-$1\" href=\"#fn-$1-text\">[" . $ifn . "]</a>"
|
||||
}egm;
|
||||
|
||||
$metadata{content} = $parser->markdown_to_html(
|
||||
dialects => 'GitHub',
|
||||
markdown => $content{"body"}
|
||||
);
|
||||
|
||||
# oh also, parse the footnotes
|
||||
if (exists $content{"footnotes"}) {
|
||||
$metadata{content} .= "\n<hr />\n";
|
||||
$content{"footnotes"} =~ s{^fn:(.+):}{
|
||||
"<a name=\"fn-$1-text\" href=\"#fn-$1\">^</a>" . $fn{$1} . ":"
|
||||
}egm;
|
||||
$metadata{content} .= $parser->markdown_to_html(
|
||||
dialects => 'GitHub',
|
||||
markdown => $content{"footnotes"}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
# HACK: Stuffing the basename in the metadata because I don't want
|
||||
# to deal with hashes of hashes
|
||||
$metadata{fname} = basename($fname) unless exists($metadata{"fname"});
|
||||
if ($body ne "") {
|
||||
my $parser = Markdent::Simple::Fragment->new;
|
||||
|
||||
$metadata{content} = $parser->markdown_to_html(
|
||||
dialects => 'GitHub',
|
||||
markdown => $body
|
||||
);
|
||||
}
|
||||
|
||||
%metadata;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue