Introduction de la doc en ligne de TeXgraph... pour tester :)
[geshi.git] / docs / texgraph / tex2html
diff --git a/docs/texgraph/tex2html b/docs/texgraph/tex2html
new file mode 100755 (executable)
index 0000000..d9d45e1
--- /dev/null
@@ -0,0 +1,87 @@
+#!/usr/bin/perl
+
+use File::Basename;
+
+our ($nom, $dir, $ext) = fileparse($ARGV[0],qr{\..*});
+our $tex = qx{cat $ARGV[0]};
+
+## === Filtres amont -----------------------------------------------------------
+$tex =~ s{\\util\s+}{}g;
+$tex =~ s/\\label\{.+?\}//g;
+$tex =~ s/\\opt\s*\{/\\modifopt\{/g;
+$tex =~ s{\\desc\s+}{§§desc§:}g;
+$tex =~ s/\\textbf\s*\[(.+?)\]\s*(\{(?:[^\{\}]++|(?2))*\})/§§textbf§$1§$2§:/g;
+$tex =~ s/\\centerline\s*(\{(?:[^\{\}]++|(?1))*\})/§§centerline§$1§:/g;
+
+## === Fichier temporaire et transformation ------------------------------------
+open  TMP, ">temp.tex";
+print TMP &pretex();
+print TMP $tex;
+close TMP;
+qx{pandoc --ascii temp.tex -o temp.html};
+
+our $html = qx{cat temp.html};
+## === Filtres aval ------------------------------------------------------------
+$html =~ s/\&\#167\;/§/g;
+$html =~ s/§§bks§:\s*/\&\#92\;/g;
+$html =~ s{§§exem§:}{<u>Exemple(s)</u> : }g;
+$html =~ s/§§textbf§(.*?)§\{(.*?)\}§:/<b>$2<\/b>/g;
+$html =~ s/§§desc§:/<u>Description<\/u> : /g;
+$html =~ s{§§opt§(.+?)§:}{<span style="color:blue">$1</span>}g;
+$html =~ s{§§helpref§(.+?)§(.+?)§:}{&helpa($1,$2)}ge;
+$html =~ s{§§span§co§(.+?)§:}{<span style="color:red">$1</span>}g;
+$html =~ s{§§span§var§(.+?)§:}{<span style="font-style:italic;color:red">$1</span>}g;
+$html =~ s{§§span§res§(.+?)§:}{<span style="color:magenta">$1</span>}g;
+$html =~ s{§§textsl§(.+?)§:}{<span style="font-style:italic">$1</span>}g;
+$html =~ s{§§centerline§\{(.+?)\}§:}{<div style="text-align:center">$1</div>}g;
+$html =~ s{<h3 id="(.+?)">(.+?)</h3>}{&modh3($1,$2)}ge;
+$html =~ s{<h2 id="(.+?)">(.+?)</h2>}{&modh2($1,$2)}ge;
+
+
+## === Fichier final -----------------------------------------------------------
+open  HTM, ">$nom.html";
+print HTM $html;
+close HTM;
+
+
+sub pretex {
+  return << "eop";
+\\newcommand{\\argu}[1]{<\\textit{#1}>}
+\\newcommand{\\exem}{§§exem§:}
+\\newcommand{\\Nil}{\\textit{Nil}}
+\\newcommand{\\jump}{\\textit{jump}}
+\\newcommand{\\var}[1]{§§span§var§#1§:}
+\\newcommand{\\co}[1]{§§span§co§#1§:}
+\\newcommand{\\res}[1]{§§span§res§#1§:}
+\\newcommand{\\Mytextbf}[1]{\\textbf{#1}}
+\\newcommand{\\textsl}[1]{§§textsl§#1§:}
+\\newcommand{\\modifopt}[2]{§§opt§#1 := < #2 >§:}
+\\newcommand{\\Helpref}[2]{§§helpref§#1§#2§:}
+\\newcommand{\\bks}{§§bks§:}
+eop
+}
+
+sub modh3 {
+  my ($i, $c) = @_;
+  if ("\U$i" eq "\U$c") {
+    return qq{<h3 id="$c">$c</h3>};
+  } else {
+    return qq{<h3 id="$i">$c</h3>};
+  }
+}
+
+sub modh2 {
+  my ($i, $c) = @_;
+  if ("\U$i" eq "\U$c") {
+    return qq{<h2 id="$c">$c</h3>};
+  } else {
+    return qq{<h2 id="$i">$c</h3>};
+  }
+}
+
+sub helpa {
+  my ($a, $b) =@_;
+  $a =~ s/^\{|\}$//g;
+  $b =~ s/^cmd|^mac//;
+  return qq{<a href="#$b">$a</a>};
+}
\ No newline at end of file

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.