Commit | Line | Data |
---|---|---|
5e61bdb4 | 1 | #!/usr/bin/perl -i -p |
39411fa8 WD |
2 | |
3 | # Make some hyphens unbreakable. | |
5e61bdb4 WD |
4 | s{(--\w[-\w]+)}{ $x = $1; $x =~ s/-/\\-/g; $x }eg; |
5 | s/(?<!\\)-(['"\d*])/\\-$1/g; | |
b6855ddc | 6 | s#(['"(= /,])-(?!-)#$1\\-#g; |
5e61bdb4 WD |
7 | s/(\\fB)-/$1\\-/g; |
8 | s/(\[\w)-(\w\])/$1\\-$2/g; | |
9 | s{(\\f\(CW.*?\\fP)}{ $x = $1; $x =~ s/(?<!\\)-/\\-/g; $x }eg; | |
10 | s/(\.\w+)-/$1\\-/g; | |
39411fa8 WD |
11 | |
12 | # We only need to use "\&'" or "\&." at the start of a line. | |
13 | s/(?<=.)\\\&(['.])/$1$2/g; | |
14 | ||
15 | # Use an em-dash where appropriate. | |
16 | s/ \\?-{1,2} / \\(em /g; | |
17 | ||
18 | # Some quotes turn into open/close quotes. | |
19 | s/'(.)'/\\(oq$1\\(cq/g; | |
20 | s/(^|[ (])"(?!( |$))/$1\\(lq/gm; | |
21 | s/(?<! )"([.,:;! )]|$)/\\(rq$1/gm; | |
22 | s/(\\\(lq[^(]*) "( |$)/$1 \\(rq$2/gm; | |
23 | s/(^| )" ([^(]*\\\(rq)/$1\\(lq $2/gm; | |
24 | ||
25 | # And some don't. | |
26 | s/^([. ])(.*)/ $1 . realquotes($2) /egm; | |
27 | s/(\\f(B|\(CW).*?\\fP)/ realquotes($1) /egs; | |
28 | ||
29 | s/^\\\&(\\\(oq)/$1/gm; | |
30 | ||
31 | sub realquotes | |
32 | { | |
33 | my($txt) = @_; | |
34 | $txt =~ s/\\\([lr]q/"/g; | |
35 | $txt =~ s/\\\([oc]q/'/g; | |
36 | $txt; | |
37 | } |