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;
|
my %metadata;
|
||||||
|
|
||||||
open(MDIN, '<', $fname) or die "Unable to open $fname: " . $!;
|
open(MDIN, '<', $fname) or die "Unable to open $fname: " . $!;
|
||||||
|
|
||||||
|
# "parsing" loop
|
||||||
|
my $contentlevel = "";
|
||||||
|
my %content;
|
||||||
while (<MDIN>) {
|
while (<MDIN>) {
|
||||||
chomp;
|
chomp;
|
||||||
if (/^(.+)?=(.*)$/) {
|
if (/^--(.+)?--$/) {
|
||||||
$metadata{$1} = $2;
|
$contentlevel = $1;
|
||||||
} elsif (/^---$/) {
|
$content{$contentlevel} = "";
|
||||||
last;
|
} elsif ($contentlevel eq "") {
|
||||||
|
if (/^(.+)?=(.*)$/) {
|
||||||
|
$metadata{$1} = $2;
|
||||||
|
} else {
|
||||||
|
warn basename($fname) . ":" . $. . ": malformed line; ignored"
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
warn basename($fname) . ":" . $. . ": malformed line; ignored"
|
$content{$contentlevel} .= "$_\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
my $body = do { local $/; <MDIN> };
|
|
||||||
close(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
|
# HACK: Stuffing the basename in the metadata because I don't want
|
||||||
# to deal with hashes of hashes
|
# to deal with hashes of hashes
|
||||||
$metadata{fname} = basename($fname) unless exists($metadata{"fname"});
|
$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;
|
%metadata;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ for (@fharr) {
|
||||||
print "$fname:$.: Overwriting existing \`$metavar\'\n";
|
print "$fname:$.: Overwriting existing \`$metavar\'\n";
|
||||||
$done++;
|
$done++;
|
||||||
}
|
}
|
||||||
if (s/^(---)$/$metavar=$timestamp\n$1/) {
|
if (s/^(--.+?--)$/$metavar=$timestamp\n$1/) {
|
||||||
print "$fname:$.: Inserting new \`$metavar\'\n";
|
print "$fname:$.: Inserting new \`$metavar\'\n";
|
||||||
$done++;
|
$done++;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue