#!/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§:}{Exemple(s) : }g; $html =~ s/§§textbf§(.*?)§\{(.*?)\}§:/$2<\/b>/g; $html =~ s/§§desc§:/Description<\/u> : /g; $html =~ s{§§opt§(.+?)§:}{$1}g; $html =~ s{§§helpref§(.+?)§(.+?)§:}{&helpa($1,$2)}ge; $html =~ s{§§span§co§(.+?)§:}{$1}g; $html =~ s{§§span§var§(.+?)§:}{$1}g; $html =~ s{§§span§res§(.+?)§:}{$1}g; $html =~ s{§§textsl§(.+?)§:}{$1}g; $html =~ s{§§centerline§\{(.+?)\}§:}{
$1
}g; $html =~ s{

(.+?)

}{&modh3($1,$2)}ge; $html =~ s{

(.+?)

}{&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{

$c

}; } else { return qq{

$c

}; } } sub modh2 { my ($i, $c) = @_; if ("\U$i" eq "\U$c") { return qq{

$c

}; } else { return qq{

$c

}; } } sub helpa { my ($a, $b) =@_; $a =~ s/^\{|\}$//g; $b =~ s/^cmd|^mac//; return qq{$a}; }