Annotation of loncom/xml/style.pm, revision 1.18
1.1 sakharuk 1: # The LearningOnline Network with CAPA
1.7 sakharuk 2: # Style Parser Module (new version)
3: #
1.18 ! sakharuk 4: # $Id: style.pm,v 1.17 2003/06/09 21:46:11 albertel Exp $
1.13 www 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: # Copyright for TtHfunc and TtMfunc by Ian Hutchinson.
29: # TtHfunc and TtMfunc (the "Code") may be compiled and linked into
30: # binary executable programs or libraries distributed by the
31: # Michigan State University (the "Licensee"), but any binaries so
32: # distributed are hereby licensed only for use in the context
33: # of a program or computational system for which the Licensee is the
34: # primary author or distributor, and which performs substantial
35: # additional tasks beyond the translation of (La)TeX into HTML.
36: # The C source of the Code may not be distributed by the Licensee
37: # to any other parties under any circumstances.
38: #
1.7 sakharuk 39: # written 01/08/01 by Alexander Sakharuk
1.1 sakharuk 40: #
41:
1.7 sakharuk 42: package Apache::style;
1.1 sakharuk 43:
44: use strict;
45: use HTML::TokeParser;
46:
47: sub styleparser {
48:
1.18 ! sakharuk 49: my ($target,$content_style_string)=@_;
1.7 sakharuk 50: my @keys = ();
51: my @values = ();
52: my @style_array = ();
1.18 ! sakharuk 53: my $current_value;
! 54: my $allow=0;
! 55: my $pstyle = HTML::TokeParser->new(\$content_style_string);
! 56: while (my $stoken = $pstyle->get_token) {
! 57: if (($stoken->[0] eq 'S') && ($stoken->[1] eq 'definetag')) {
! 58: push @keys,$stoken->[2]->{'name'};
! 59: $current_value='';
! 60: $allow=0;
! 61: } elsif (($stoken->[0] eq 'E') && ($stoken->[1] eq 'definetag')) {
! 62: $current_value =~ s/(\s)+/$1/g;
! 63: $current_value =~ s/\n//g;
! 64: push(@values,$current_value);
! 65: } elsif (($target eq 'meta') && ($stoken->[0] eq 'S') && ($stoken->[1] eq 'meta')) {
! 66: $allow=1;
! 67: } elsif (($target eq 'meta') && ($stoken->[0] eq 'E') && ($stoken->[1] eq 'meta')) {
! 68: $allow=0;
! 69: } elsif (($target ne 'meta') && ($stoken->[0] eq 'S') && ($stoken->[1] eq 'render')) {
! 70: $allow=1;
! 71: } elsif (($target ne 'meta') && ($stoken->[0] eq 'E') && ($stoken->[1] eq 'render')) {
! 72: $allow=0;
! 73: } elsif (($target ne 'meta') && ($target ne 'web') && ($stoken->[0] eq 'S') && ($stoken->[1] eq 'web')) {
! 74: $allow=0;
! 75: } elsif (($target ne 'meta') && ($target ne 'web') && ($stoken->[0] eq 'E') && ($stoken->[1] eq 'web')) {
! 76: $allow=1;
! 77: } elsif (($target ne 'meta') && ($target ne 'tex') && ($stoken->[0] eq 'S') && ($stoken->[1] eq 'tex')) {
! 78: $allow=0;
! 79: } elsif (($target ne 'meta') && ($target ne 'tex') && ($stoken->[0] eq 'E') && ($stoken->[1] eq 'tex')) {
! 80: $allow=1;
! 81: } elsif (($stoken->[0] eq 'S') && ($stoken->[1] eq 'target') && ($stoken->[2]->{'name'} ne $target)) {
! 82: $allow=0;
! 83: } elsif (($stoken->[0] eq 'E') && ($stoken->[1] eq 'target')) {
! 84: $allow=1;
! 85: } elsif (($target ne 'meta') && ($stoken->[0] eq 'S') && ($stoken->[1] eq $target)) {
! 86: $allow=1;
! 87: } elsif (($target ne 'meta') && ($stoken->[0] eq 'E') && ($stoken->[1] eq $target)) {
! 88: } elsif (($stoken->[0] eq 'S') && ($stoken->[1] eq 'target') && ($stoken->[2]->{'name'} eq $target)) {
! 89: $allow=1;
! 90: } elsif ($allow) {
! 91: if ($stoken->[0] eq 'T') {
! 92: $current_value .= $stoken->[1];
! 93: } elsif ($stoken->[0] eq 'S') {
! 94: my $number=-1;
! 95: if ($stoken->[1] ne $keys[-1]) {
! 96: $number = &testkey($stoken->[0],$stoken->[1],@keys);
! 97: }
! 98: if ($number != -1) {
! 99: $current_value .= &testvalue($number,$stoken->[0],$stoken->[2],@values);
! 100: } else {
! 101: $current_value .= $stoken->[4];
! 102: }
! 103: } elsif ($stoken->[0] eq 'E') {
! 104: my $number=-1;
! 105: if (('/'.$stoken->[1]) ne $keys[-1]) {
! 106: $number = &testkey($stoken->[0],$stoken->[1],@keys);
! 107: }
! 108: if ($number != -1) {
! 109: $current_value .= &testvalue($number,$stoken->[0],$stoken->[2],@values);
! 110: } else {
! 111: $current_value .= $stoken->[2];
! 112: }
1.14 albertel 113: }
1.4 sakharuk 114: }
1.7 sakharuk 115: }
116: for (my $i=0; $i<=$#keys; $i++) {
1.11 sakharuk 117: push @style_array,$keys[$i],$values[$i];
1.7 sakharuk 118: }
1.9 sakharuk 119: my %style_for_target = @style_array;
1.18 ! sakharuk 120: return %style_for_target;
! 121: }
1.7 sakharuk 122:
1.4 sakharuk 123:
1.7 sakharuk 124: sub testkey {
1.4 sakharuk 125:
1.7 sakharuk 126: my ($zeroth,$first,@keys) = @_;
127: my $number = -1;
128: if ($zeroth eq 'S') {
129: for (my $i=$#keys; $i>=0; $i=$i-1) {
130: if ($first eq lc($keys[$i])) {
131: $number = $i;
132: last;
1.4 sakharuk 133: }
1.7 sakharuk 134: }
135: } elsif ($zeroth eq 'E') {
136: for (my $i=$#keys; $i>=0; $i=$i-1) {
137: if ('/'.$first eq lc($keys[$i])) {
138: $number = $i;
139: last;
1.4 sakharuk 140: }
1.7 sakharuk 141: }
142: }
143: return $number;
144: }
145:
146: sub testvalue {
147:
148: my ($number,$zeroth,$second,@values) = @_;
149: my $current_content = $values[$number];
150: if ($zeroth eq 'S') {
1.14 albertel 151: my %tempo_hash = %$second;
152: while ((my $current_k,my $current_v) = each %tempo_hash) {
153: $current_content =~ s/\$$current_k/$current_v/g;
154: }
1.7 sakharuk 155: } elsif ($zeroth eq 'E') {
1.14 albertel 156: $current_content = $values[$number];
1.7 sakharuk 157: }
158: return $current_content;
1.1 sakharuk 159: }
160:
161: 1;
1.7 sakharuk 162:
1.1 sakharuk 163: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>