[LON-CAPA-cvs] cvs: modules /gerd/python convert.pl

www www at source.lon-capa.org
Wed Feb 8 21:29:47 EST 2012


www		Thu Feb  9 02:29:47 2012 EDT

  Modified files:              
    /modules/gerd/python	convert.pl 
  Log:
  More work on python <externalresponse> translator for MIT 6.01
  
  
Index: modules/gerd/python/convert.pl
diff -u modules/gerd/python/convert.pl:1.1 modules/gerd/python/convert.pl:1.2
--- modules/gerd/python/convert.pl:1.1	Thu Feb  9 01:47:38 2012
+++ modules/gerd/python/convert.pl	Thu Feb  9 02:29:47 2012
@@ -7,13 +7,44 @@
 $input=~s/\"\"\"\"\"\"/\"\"\"\n\"\"\"/gs;
 my @lines=split(/\n/,$input);
 
-my $output="<problem>\n<startouttext />\n";
-my $mode='outtext';
+my $output="<problem>\n";
+my $mode='';
+my $submode='';
+my $initialdisp='';
 foreach my $line (@lines) {
-   if ($mode eq 'outtext') {
+   if ($line=~/\{\% block problem \%\}/) {
+      $mode='outtext';
+      $output.="<startouttext />\n";
+   } elsif ($line=~/\{\% processor \%\}/) {
+      $mode='script';
+      $submode='';
+      $output.="<endouttext />\n<script type='loncapa/perl'>\n";
+   } elsif ($line=~/\{\% endprocessor \%\}/) {
+      $output.="\n".'</script>'."\n";
+      $mode='';
+   } elsif ($mode eq 'outtext') {
       $line=~s/<br>/<br \/>\n/gs;
       $line=~s/\{\% math eq=\"([^\"]+)\".*\}/ <m>\$$1\$<\/m>/gs;
       $output.=$line."\n";
+   } elsif ($mode eq 'script') {
+      if ($line=~/^(initial\_display|answer|preamble|test\_program)/) {
+         my $vari=$1;
+         $submode=uc($vari);
+         $submode=~s/\_//gs;
+         unless ($submode eq 'INITIALDISPLAY') {
+             $output.="\n\$$vari=(<<'$submode');\n";
+         }
+      } elsif ($line=~/^\"\"\"/) {
+          unless ($submode eq 'INITIALDISPLAY') {
+             $output.=$submode."\n";
+          }
+      } else {
+          if ($submode eq 'INITIALDISPLAY') {
+             $initialdisp.=$line."\n";
+          } else {
+             $output.=$line."\n";
+          }
+      }
    }
 }
 $output.="</problem>\n";




More information about the LON-CAPA-cvs mailing list