wiki.pl: Port some fixes from upstream
[Orgmuse.git] / modules / fractions.pl
blob31cb4b7a3db6bf3951edaa3f56c956a0619c30c5
1 # Copyright (C) 2013 Alex Schroeder <alex@gnu.org>
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 $ModulesDescription .= '<p><a href="http://git.savannah.gnu.org/cgit/oddmuse.git/tree/modules/fractions.pl">fractions.pl</a>, see <a href="http://www.oddmuse.org/cgi-bin/oddmuse/Fractions">Fractions</a></p>';
18 push(@MyRules, \&FractionsRule);
20 # usage: ^1/32
21 sub FractionsRule {
22 if (/\G\^([0-9]+)\/([0-9]+)/cg) {
23 if ($1 == 1 and $2 == 4) { return "\&#x00bc;"; }
24 elsif ($1 == 1 and $2 == 2) { return "\&#x00bd;"; }
25 elsif ($1 == 3 and $2 == 4) { return "\&#x00be;"; }
26 elsif ($1 == 1 and $2 == 7) { return "\&#x2150;"; }
27 elsif ($1 == 1 and $2 == 9) { return "\&#x2151;"; }
28 elsif ($1 == 1 and $2 == 10) { return "\&#x2152;"; }
29 elsif ($1 == 1 and $2 == 3) { return "\&#x2153;"; }
30 elsif ($1 == 2 and $2 == 3) { return "\&#x2154;"; }
31 elsif ($1 == 1 and $2 == 5) { return "\&#x2155;"; }
32 elsif ($1 == 2 and $2 == 5) { return "\&#x2156;"; }
33 elsif ($1 == 3 and $2 == 5) { return "\&#x2157;"; }
34 elsif ($1 == 4 and $2 == 5) { return "\&#x2158;"; }
35 elsif ($1 == 1 and $2 == 6) { return "\&#x2159;"; }
36 elsif ($1 == 5 and $2 == 6) { return "\&#x215a;"; }
37 elsif ($1 == 1 and $2 == 8) { return "\&#x215b;"; }
38 elsif ($1 == 3 and $2 == 8) { return "\&#x215c;"; }
39 elsif ($1 == 5 and $2 == 8) { return "\&#x215d;"; }
40 elsif ($1 == 7 and $2 == 8) { return "\&#x215e;"; }
41 else {
42 my $html;
43 # superscripts
44 for my $char (split(//, $1)) {
45 if ($char eq '1') { $html .= "\&#x00b9;"; }
46 elsif ($char eq '2') { $html .= "\&#x00b2;"; }
47 elsif ($char eq '3') { $html .= "\&#x00b3;"; }
48 else { $html .= "\&#x207$char;"; }
50 # fraction slash
51 $html .= '&#x2044;';
52 # subscripts
53 for my $char (split(//, $2)) {
54 $html .= "\&#x208$char;";
56 return $html;
59 return undef;