]> matita.cs.unibo.it Git - helm.git/blob - helm/cgi/webeqp.pl
e38fe510421202c33212fb297f01c31449431bf9
[helm.git] / helm / cgi / webeqp.pl
1 #!/usr/bin/perl
2
3 require HTTP::Request;
4 require LWP::UserAgent;
5 use CGI;
6
7 $url = $ENV{"REQUEST_URI"};
8 $url =~ s/.*mmlurl=(.*)/$1/;
9
10 $content = "";
11
12 $ua = LWP::UserAgent->new;
13 $request = HTTP::Request->new(GET => "$url");
14 $response = $ua->request($request, \&callback);
15
16 $content =~ s/\r//sg;
17 $content =~ s/\n/ /sg;
18 $content =~ s/<!DOCTYPE[^>]*>//sg;
19 $content =~ s/<\?xml[^?]*\?>//sg;
20 $content =~ s/"/'/g;
21 $content =~ s/&/&amp;/g;
22 $content =~ s/<m:/</g;
23 $content =~ s/<\/m:/<\//g;
24 $content =~ s/<math[^>]*>/<math>/sg;
25 $content =~ s/(<\/?semantics[^>]*>)/<!-- $1 -->/sg;
26 $content =~ s/(<annotation-xml)/<!-- $1/sg;
27 $content =~ s/(<\/annotation-xml>)/$1 -->/sg;
28 $content =~ s/<mo helm:xref='[^']*' xlink:href='([^']*)'>([^<]*)<\/mo>/<maction actiontype='href' other='$use_webeqp_url?uri=$1'><mo>$2<\/mo><\/maction>/sg;
29 $content =~ s/<mi helm:xref='[^']*' xlink:href='([^']*)'>([^<]*)<\/mi>/<maction actiontype='href' other='$use_webeqp_url?uri=$1'><mi>$2<\/mi><\/maction>/sg;
30 $content =~ s/helm:xref='[^']*'//sg;
31 $content =~ s/xmlns:helm='[^']*'//sg;
32 $content =~ s/xlink:href='[^']*'//sg;
33 $content =~ s/xmlns:xlink='[^']*'//sg;
34 $content =~ s/<mchar name='([^']*)' \/>/&$1;/sg;
35
36 print <<EOT;
37 Content-type: text/html
38
39 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
40 "http://www.w3.org/TR/REC-html40/loose.dtd">
41 <html>
42 <head>
43 <title>Generato in automatico a partire da $url</title>
44 </head>
45 <body bgcolor="#ffffff" text="#000000">
46 <applet codebase="http://www.webeq.com/WebEQ/2.2/classes" code="webeq.Main"
47 +width=600 height=2000 align=middle>
48 <param name=eq value="$content">
49 <param name=color value="#cccccc">
50 <param name=parser value="mathml">
51 <param name=size value="14">
52 </applet>
53 </body>
54 </html>
55 EOT
56
57 #=========================
58
59 sub callback
60
61  my ($data) = @_;
62  $content .= $data;
63 }