File: tohtml.pl

package info (click to toggle)
debian-zh-faq 1.13
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, stretch, wheezy
  • size: 188 kB
  • sloc: perl: 179; makefile: 170
file content (64 lines) | stat: -rwxr-xr-x 1,523 bytes parent folder | download | duplicates (5)
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
#!/usr/bin/perl -p

BEGIN {
    $english = 0;
    $verbatim = 0;
}

s/^%LaTeX2HTMLonly%//;

next if /^%/;

# Work around a LaTeX2HTML bug that ignores \/ or \textcompwordmark{}
# for breaking up "---" and "--" ligatures.

s%(-\\/-\\/-)%\\latexhtml\{$1\}\{\\begin\{rawhtml\}---\\end\{rawhtml\}\}%g;
s%(-\\/-(?!\\/-))%\\latexhtml\{$1\}\{\\begin\{rawhtml\}--\\end\{rawhtml\}\}%g;


# Isolate the areas where CJKtilde is in effect.

if (/\\end\{englishtext\}/) { $english  = 0; next; }
if (/\\end\{lyxcode\}/)     { $verbatim = 0; next; }
if (/\\begin\{englishtext\}/) { $english  = 1; next; } 
if (/\\begin\{lyxcode\}/)     { $verbatim = 1; next; }
next if ($english == 1) or ($verbatim == 1);

chomp;

if (/\\texttt\{/) {
    my $pos = 0;
    my $level = 0;
    my $line = '';
    while (/\\texttt\{/) {
	$pos = index($_, '\texttt{') + 8;
	$str = substr($_, 0, $pos, "");
	while ($str =~ s/^((?:[\x00-\x7f]|[\x80-\xff].)*)~/$1 /) {}
	$line .= $str;

	$level = 1;
	while ($level > 0) {
	    $pos = index($_, '}') + 1;
	    last if $pos == -1;
	    $str = substr($_, 0, $pos, "");
	    $line .= $str;
	    if ($str =~ /\{/) {
		$level++;
	    } else {
		$level--;
	    }
	}
    }
    1 while (s/^((?:[\x00-\x7f]|[\x80-\xff].)*)~/$1 /);
    $line .= $_;
    $_ = $line;
}
else {
#    1 while (s/^((?:[\x00-\x7f]|[\x80-\xff].)*)~/$1 /);
     1 while (s/^((?:[\x00-\x2e\x30-\x7f]|[\x80-\xff].)*)~/$1 /);
}

s/\\nbs(?:\{\}|\s*)/~/g;
s/\s+(B|A|C|G|I|H|]|^|u|v)/$1/g;
s/(B|A|C|G|I|H|]|^|u|v)\s+/$1/g;
$_ .= "\n";