forked from erlang/eep
-
Notifications
You must be signed in to change notification settings - Fork 0
/
eep-pre.pl
executable file
·59 lines (55 loc) · 1.3 KB
/
eep-pre.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
59
#! /usr/bin/perl
##
## Preprocess EEP to correct links to self and index.
## Markdown preprocessor.
##
## Copyright 2010: Erlang/OTP, Raimo Niskanen
## This document has been placed in the public domain.
#
#
# Process <>
#
# Rewrite these Markdown constructs:
#
# [EEP n]: eep-NNNN.md => [EEP n]: eep-NNNN.html
#
# [EEP]: ./ => [EEP]: eep-0000.html
#
# ****
# EEP N: Title
# ----
# =>
# ****
# [EEP](eep-0000.html "EEP Index") N: [Title](eep-NNNN.md "EEP Source")
# ----
#
require 5.008_000;
use strict;
use warnings;
my ($p, $pp);
$\ = "\n";
while (<>) {
chomp;
#
s{^(\[ EEP \s+ \d+ \] : \s+ eep- \d+) \. md (?= \s*)}|$1.html|x; # EEP link
s{^(\[ EEP \] : \s+) \./ (?= \s*)}|${1}eep-0000.html|x; # Index link
if ($_ =~ m{\s* - \s* - \s* - [-\s]*|}
&& defined $pp && $pp =~ m{\s* \* \s* \* \s* \* [\s\*]*}x
&& $p =~ m{^EEP \s+ (\d+) : (.*)}x) # EEP *: Title
{
my ($num, $title) = ($1, $2);
$title =~ s|([\[\]\(\)\"])|\\$1|g;
$p = sprintf '[EEP](eep-0000.html "EEP Index") %d: '
.'[%s](eep-%04d.md "EEP Source")', $num, $title, $num;
}
} continue {
if (defined $pp) {
print $pp or die "can't print: $!\n";
}
$pp = $p;
$p = $_;
}
if (defined $pp) {
print $pp or die "can't print: $!\n";
}
print $p or die "can't print: $!\n";