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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
#! /usr/bin/env perl
use warnings;
undef $/;
$_=<>;
# Undo Windows newlines.
s/\r\n/\n/sg;
# URLs have damn inconsistent handling in reST.
s|:http: ``(.+)``|$1|g;
s|:telnet: ``(.+)``|telnet: $1|g;
s|:ssh: ``(.+)``|ssh: $1|g;
s|:tiles: ``(.+)``|tiles: $1|g;
# Notes.
s/\.\. note::/Note: /g;
# Local references.
s/`(.)\.\s+(.*?)`_/$1. "$2"/sg; # added "" for a nicer look
# HTML and reST escapes.
s/</</g;
s/>/>/g;
s/"/"/g;
s/�*39;/'/g;
s/&/&/g;
s/\\(.)/$1/g;
# Table of contents.
my $contents = "Contents\n--------\n";
for (/\*{9,}\n(.\. .+)\n\*{9,}/g)
{
/(.)\. (.+)/;
$contents .= "\nAppendices\n" if $1 eq "1";
$contents .= "$1. $2\n";
}
s/\.\. contents::\n :depth: 5/$contents/;
# Main headers.
my $DCSShead = <<END;
DUNGEON CRAWL Stone Soup
- the manual -
END
s/\+{9,}\nDungeon Crawl Stone Soup manual\n\+{9,}\n/$DCSShead/;
s/#{9,}\nManual\n#{9,}\n\n//;
# Make section headers nice and centered.
my $dashes = "-"x72;
my $spaces = " "x36;
s/\*{9,}\n(.)\. (.*)\n\*{9,}/$dashes\n$1.$spaces\ca$2\cb\U$2\n$dashes/g;
1 while s/ \ca[^\cb]{2}/\ca/g;
s/\ca[^\cb]?\cb//g;
# Rewrap overlong lines.
my $ls = "";
my $rem = "";
for (/^.*$/mg)
{
s/\s*$//;
/^( *)(.*)/;
my ($s, $line) = ($1, $2);
if ($s ne $ls || $line eq "")
{
# Different indentation -- needs a separate line.
$_ = "$ls$rem";
s/\s+$//;
print "$_\n" unless $_ eq "";
$rem = "";
}
$ls = $s;
$_ = "$s$rem$line";
/(.{0,75})(?:$|\s+)(.*)/;
($_, $rem) = ($1, "$2 ");
s/\s+$//;
print "$_\n";
$rem =~ s/^\s+//;
}
|