# Plugin name: atconv
# Author: Shinra Kawasemi as Mitsuki
# Version: 1.0 19-Feb-2005
# Documentation: none :(

package atconv;
use strict;

# --- Configurable variables -----

# --- Plug-in package variables --------

# --------------------------------


sub start {
  1;
}


sub story {
  my ($pkg, $path, $filename, $story_ref, $title_ref, $body_ref) = @_;
  
  if ($$body_ref =~ m/^\@autoindex$/m){
    my $autoindex = "<h3>Index</h3>\n";
    
    $autoindex .= "<table>\n";
    foreach my $line (split("\n", $$body_ref)){
      if ($line =~ m/^\@sec\t(.*)\t(.*)$/){
        $autoindex .= "<tr><th><a href=\"\#$2\">$1</a><td>";
      }
      if ($line =~ m/^\@part\t(.*)\t(.*)$/){
        $autoindex .= "<a href=\"\#$2\">$1</a>\n";
      }
    }
    $autoindex .= "</table>\n";
    
    $$body_ref =~ s|^\@autoindex$|$autoindex|mg;
    $$body_ref =~ s|^\@sec\t(.*)\t(.*)$|<h3><a name=\"$2\">$1</a></h3>|mg;
    $$body_ref =~ s|^\@sec\t(.*)$|<h3>$1</h3>|mg;
    $$body_ref =~ s|^\@part\t(.*)\t(.*)$|<h4><a name=\"$2\">$1</a></h4>|mg;
    $$body_ref =~ s|^\@part\t(.*)$|<h4>$1</h4>|mg;
    $$body_ref =~ s|^\@link\t(.*)\t(.*)\t(.*)$|<li><a href=\"$2\">$1</a>F$3|mg;
    $$body_ref =~ s|^\@link\t(.*)\t(.*)$|<li><a href=\"$2\">$1</a>|mg;
  }
  $$body_ref =~ s|^\@link\t(.*)\t(.*)$|<a href=\"$2\">$1</a>|mg;
  $$body_ref =~ s|^\@comment$|<p class=\"comment\">|mg;
  $$body_ref =~ s|^\@plink\t(.*)$|<p><a name=\"$1\" href=\"$blosxom::url$path/$filename.$blosxom::flavour#$1\">*</a><br>|mg;
  $$body_ref =~ s|^\@amazon\t(.*)\t(.*)$|<a href=\"http://www.amazon.co.jp/exec/obidos/ASIN/$1\">$2</a>|mg;
  
  $$body_ref =~ s|^\@time\t(..)(..)\t(.*)$|<p><span class="para"><a name=\"$1$2\" href=\"$blosxom::url$path/$filename.$blosxom::flavour#$1$2\">*</a> $1:$2 $3</span><br>|mg;
  $$body_ref =~ s|^\@time\t(..)(..)$|<p><span class="para"><a name=\"$1$2\" href=\"$blosxom::url$path/$filename.$blosxom::flavour#$1$2\">*</a> $1:$2</span><br>|mg;
  
  return 1;
}


1;

