forked from github/kensanata.oddmuse
66 lines
2.3 KiB
Perl
66 lines
2.3 KiB
Perl
# Copyright (C) 2013 Alex Schroeder <alex@gnu.org>
|
|
#
|
|
# This program is free software; you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation; either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
use strict;
|
|
use v5.10;
|
|
|
|
AddModuleDescription('fractions.pl', 'Fractions');
|
|
|
|
our (@MyRules);
|
|
|
|
push(@MyRules, \&FractionsRule);
|
|
|
|
# usage: ^1/32
|
|
sub FractionsRule {
|
|
if (/\G\^([0-9]+)\/([0-9]+)/cg) {
|
|
if ($1 == 1 and $2 == 4) { return "\¼"; }
|
|
elsif ($1 == 1 and $2 == 2) { return "\½"; }
|
|
elsif ($1 == 3 and $2 == 4) { return "\¾"; }
|
|
elsif ($1 == 1 and $2 == 7) { return "\⅐"; }
|
|
elsif ($1 == 1 and $2 == 9) { return "\⅑"; }
|
|
elsif ($1 == 1 and $2 == 10) { return "\⅒"; }
|
|
elsif ($1 == 1 and $2 == 3) { return "\⅓"; }
|
|
elsif ($1 == 2 and $2 == 3) { return "\⅔"; }
|
|
elsif ($1 == 1 and $2 == 5) { return "\⅕"; }
|
|
elsif ($1 == 2 and $2 == 5) { return "\⅖"; }
|
|
elsif ($1 == 3 and $2 == 5) { return "\⅗"; }
|
|
elsif ($1 == 4 and $2 == 5) { return "\⅘"; }
|
|
elsif ($1 == 1 and $2 == 6) { return "\⅙"; }
|
|
elsif ($1 == 5 and $2 == 6) { return "\⅚"; }
|
|
elsif ($1 == 1 and $2 == 8) { return "\⅛"; }
|
|
elsif ($1 == 3 and $2 == 8) { return "\⅜"; }
|
|
elsif ($1 == 5 and $2 == 8) { return "\⅝"; }
|
|
elsif ($1 == 7 and $2 == 8) { return "\⅞"; }
|
|
else {
|
|
my $html;
|
|
# superscripts
|
|
for my $char (split(//, $1)) {
|
|
if ($char eq '1') { $html .= "\¹"; }
|
|
elsif ($char eq '2') { $html .= "\²"; }
|
|
elsif ($char eq '3') { $html .= "\³"; }
|
|
else { $html .= "\ȇ$char;"; }
|
|
}
|
|
# fraction slash
|
|
$html .= '⁄';
|
|
# subscripts
|
|
for my $char (split(//, $2)) {
|
|
$html .= "\Ȉ$char;";
|
|
}
|
|
return $html;
|
|
}
|
|
}
|
|
return;
|
|
}
|