Properly escape LaTeX commands in test samples.
[docutils.git] / prest / tbin / rehtml
blobde10fed0f5e1409140a1397f95cb3e23027198f1
1 #!/usr/local/bin/perl -p
3 # $Id: rehtml 776 2006-01-30 00:42:36Z marknodine $
5 # Converts an HTML file to a regular-expression HTML
7 # Protect regular expression characters (do this FIRST)
8 s/([\(\)\[\]\{\}\.\+\*\?\|\\\^\$\@\%])/\\$1/g;
10 # Don't require match on id numbers
11 s/id\d+/id\\d+/g;
12 # Handle line numbers in error messages
13 s!\S+(/\S+\\\.(?:pm|wrt),? line )(\d+)(, <\w+> line \d+)?!.*$1($2|\\d+)(, <\\w+> line \\d+)?!g;
14 # Handle the "Generated on" date
15 s/(Generated on:\s*).*/$1.*/;
16 # Handle the "Generated by" description
17 s/(Generated by ).*Docutils.*/$1.*/;
18 # Accommodate different date formats
19 BEGIN {
20 $time = '(\s+\d+:\d+:\d+(\s+[-+]\d+(\s+\(.+?\))?)?)?';
21 ($timere = $time) =~ s/\\([()])/\\\\\\$1/g;
23 s!(\d{4})([-/])(\d{2})\2(\d{2})$timere!\\d{4}[-/\]\\d{2}\[-/\]\\d{2}$time!go;
24 # Handle the docutils string
25 s/"Docutils[^\"]+"/".*"/g;
26 # Handle the prest string
27 s/"prest(\\.prl)?[^\"]+"/".*"/g;
28 # Handle the prest version
29 s/(prest)(\\.prl)?( release )\S+/${1}(${2})?${3}\\S+/g;
30 # Accommodate different stylesheets
31 s|(<link rel="stylesheet" href=")[^\"]*(" type="text/css" />)|$1.*$2|;
32 # Get rid of junque characters in generated section numbers
33 s/   /.*/;
34 # Deal with revisions that may change
35 if ($AFTER_REVISION) {
36 s/\d+(\\\.\d+)+/\\d+(\\.\\d+)+/;
37 $AFTER_REVISION = 0;
39 $AFTER_REVISION = m|<th class="docinfo-name">Revision:</th>|;
41 # Now, handle things I wasn't able to reproduce perfectly
43 # Be tolerant of lists that may or may not be simple
44 s/(<[ou]l)( class="simple")?(>)/$1( class="simple")?$3/;
45 s/(<[ou]l) class="(?!simple)([a-s][^\"]+) simple"(>)/$1 class="$2( simple)?"$3/;
46 s/(<[ou]l) class="(?!simple)([t-z][^\"]+) simple"(>)/$1 class="(simple )?$2"$3/;
47 s/(<[ou]l) class="(?!simple)([^\"]+)"(>)/$1 class="$2( simple)?"$3/;
48 s/(<[ou]l) class="(?!simple)([a-s][^\"]+)"(>)/$1 class="$2( simple)?"$3/;
49 s/(<[ou]l) class="(?!simple)([t-z][^\"]+)"(>)/$1 class="(simple )?$2"$3/;
51 # Deal with perl eval numbers that may change in error messages
52 s/\\\((eval )(\d+)\\\)(\\\[.+\\\])?/\\($1\\d+\\).*/;