Introduction de la doc en ligne de TeXgraph... pour tester :)
[geshi.git] / docs / texgraph / tex2html
1 #!/usr/bin/perl
2
3 use File::Basename;
4
5 our ($nom, $dir, $ext) = fileparse($ARGV[0],qr{\..*});
6 our $tex = qx{cat $ARGV[0]};
7
8 ## === Filtres amont -----------------------------------------------------------
9 $tex =~ s{\\util\s+}{}g;
10 $tex =~ s/\\label\{.+?\}//g;
11 $tex =~ s/\\opt\s*\{/\\modifopt\{/g;
12 $tex =~ s{\\desc\s+}{§§desc§:}g;
13 $tex =~ s/\\textbf\s*\[(.+?)\]\s*(\{(?:[^\{\}]++|(?2))*\})/§§textbf§$1§$2§:/g;
14 $tex =~ s/\\centerline\s*(\{(?:[^\{\}]++|(?1))*\})/§§centerline§$1§:/g;
15
16 ## === Fichier temporaire et transformation ------------------------------------
17 open  TMP, ">temp.tex";
18 print TMP &pretex();
19 print TMP $tex;
20 close TMP;
21 qx{pandoc --ascii temp.tex -o temp.html};
22
23 our $html = qx{cat temp.html};
24 ## === Filtres aval ------------------------------------------------------------
25 $html =~ s/\&\#167\;/§/g;
26 $html =~ s/§§bks§:\s*/\&\#92\;/g;
27 $html =~ s{§§exem§:}{<u>Exemple(s)</u> : }g;
28 $html =~ s/§§textbf§(.*?)§\{(.*?)\}§:/<b>$2<\/b>/g;
29 $html =~ s/§§desc§:/<u>Description<\/u> : /g;
30 $html =~ s{§§opt§(.+?)§:}{<span style="color:blue">$1</span>}g;
31 $html =~ s{§§helpref§(.+?)§(.+?)§:}{&helpa($1,$2)}ge;
32 $html =~ s{§§span§co§(.+?)§:}{<span style="color:red">$1</span>}g;
33 $html =~ s{§§span§var§(.+?)§:}{<span style="font-style:italic;color:red">$1</span>}g;
34 $html =~ s{§§span§res§(.+?)§:}{<span style="color:magenta">$1</span>}g;
35 $html =~ s{§§textsl§(.+?)§:}{<span style="font-style:italic">$1</span>}g;
36 $html =~ s{§§centerline§\{(.+?)\}§:}{<div style="text-align:center">$1</div>}g;
37 $html =~ s{<h3 id="(.+?)">(.+?)</h3>}{&modh3($1,$2)}ge;
38 $html =~ s{<h2 id="(.+?)">(.+?)</h2>}{&modh2($1,$2)}ge;
39
40
41 ## === Fichier final -----------------------------------------------------------
42 open  HTM, ">$nom.html";
43 print HTM $html;
44 close HTM;
45
46
47 sub pretex {
48   return << "eop";
49 \\newcommand{\\argu}[1]{<\\textit{#1}>}
50 \\newcommand{\\exem}{§§exem§:}
51 \\newcommand{\\Nil}{\\textit{Nil}}
52 \\newcommand{\\jump}{\\textit{jump}}
53 \\newcommand{\\var}[1]{§§span§var§#1§:}
54 \\newcommand{\\co}[1]{§§span§co§#1§:}
55 \\newcommand{\\res}[1]{§§span§res§#1§:}
56 \\newcommand{\\Mytextbf}[1]{\\textbf{#1}}
57 \\newcommand{\\textsl}[1]{§§textsl§#1§:}
58 \\newcommand{\\modifopt}[2]{§§opt§#1 := < #2 >§:}
59 \\newcommand{\\Helpref}[2]{§§helpref§#1§#2§:}
60 \\newcommand{\\bks}{§§bks§:}
61 eop
62 }
63
64 sub modh3 {
65   my ($i, $c) = @_;
66   if ("\U$i" eq "\U$c") {
67     return qq{<h3 id="$c">$c</h3>};
68   } else {
69     return qq{<h3 id="$i">$c</h3>};
70   }
71 }
72
73 sub modh2 {
74   my ($i, $c) = @_;
75   if ("\U$i" eq "\U$c") {
76     return qq{<h2 id="$c">$c</h3>};
77   } else {
78     return qq{<h2 id="$i">$c</h3>};
79   }
80 }
81
82 sub helpa {
83   my ($a, $b) =@_;
84   $a =~ s/^\{|\}$//g;
85   $b =~ s/^cmd|^mac//;
86   return qq{<a href="#$b">$a</a>};
87 }

Licence Creative Commons Les fichiers de Syracuse sont mis à disposition (sauf mention contraire) selon les termes de la
Licence Creative Commons Attribution - Pas d’Utilisation Commerciale - Partage dans les Mêmes Conditions 4.0 International.