Worktime, New Tag

Adding a New Tag

We will add the tag <blue> to the XML handler. It will change all text inside of it to be blue when viewing a webpage.

  1. First you will need to add the author role to domcc
    Use the CUSR button on the remote, type in the username 'domcc' and then add the author role. Logout, and log back in. (You will also need to let the webserver have permission to enter domcc's home directory, do this by having domcc do chmod a+x /home/domcc
  2. Next create a homework problem. Something simple. In the text section of the homework problem. Surround the text of the problem with the tag pair <blue> and </blue>
  3. When you view the problem you should see no change. (This is because by default browsers ignore tags they are unfamiliar with.)
  4. Next you will need to edit the londefdef.pm file in the xml subdriectory, and we will do the required actions to make a new tag handler.
  5. First we need to register the tag with the xml parser. Notice that at the top of the londefdef.pm file there is a call to register, right in front of the 'm' put 'blue',. Don't forget the comma.
  6. Next we need to create 2 functions. &start_blue() and &end_blue(). They will be called when the parser sees the start and end blue tags.
  7. Add 'Code Fragment 1' to the londefdef.pm file. Copy londefdef.pm to /home/httpd/lib/perl/Apache and restart the webserver. This is the last time I will tell you this.
  8. Go back and view your homework problem. You should see the two messages 'Starting the blue tag now!!!' and 'Ending the blue tag now!!!', notice that it appears a second time in the bottom section, that is because that is a parse of the answer target. We need to stop produicng oputput for any target other than web.
  9. Now change the code to be as in Code Fragment 2.
  10. Now it should only appear in the middle of the problem. Now lets make it turn the text blue.
  11. Change you code to look like Code Fragment 3
  12. Now when you view the problem the text should appear in blue.

Code fragment 1

sub start_blue {
  my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
  my $result='';
  $result='<br />Starting the blue tag now!!!<br />';
  return $result;
}

sub end_blue {
  my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
  my $result='';
  $result='<br />Ending the blue tag now!!!<br />';
  return $result;
}
    

Code fragment 2

sub start_blue {
  my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
  my $result='';
  if ($target eq 'web') {
      $result='<br />Starting the blue tag now!!!<br />';
  }
  return $result;
}

sub end_blue {
  my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
  my $result='';
  if ($target eq 'web') {
      $result='<br />Ending the blue tag now!!!<br />';
  }
  return $result;
}
    

Code fragment 2

sub start_blue {
  my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
  my $result='';
  if ($target eq 'web') {
      $result='<font color="blue">';
  }
  return $result;
}

sub end_blue {
  my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
  my $result='';
  if ($target eq 'web') {
      $result='</font>';
  }
  return $result;
}
    

Guy Albertelli
Last modified: Tue Jun 11 11:01:29 EDT 2002