wml-extended-apis / xhtml / 1.x / std / toc / toc.wml

## 
##  wml::xhtml1::std::toc - Table of Conents Generator
##  Copyright (c) 2005 Shlomi Fish
##  Distributed under the MIT X11 License
##  http://www.opensource.org/licenses/mit-license.php

<:{
use HTML::TokeParser::Simple;
use vars qw($wml_xhtml_std_toc_section);
$wml_xhtml_std_toc_section = [];
}:>

<define-tag h2 whitespace="delete" endtag="required">
<preserve id />
<h2*<attributes-quote %attributes /> >%body</h2*>
<set-var %attributes />
<:{

my $id = <<'EOCMMFINVBOWVNIANFINLNGINWNOF';
<get-var id />
EOCMMFINVBOWVNIANFINLNGINWNOF

my $tag_body = <<'EOCMMFINVBOWVNIANFINLNGINWNOF';
%body
EOCMMFINVBOWVNIANFINLNGINWNOF

chomp($id);
chomp($tag_body);
my $parser = HTML::TokeParser::Simple->new(\$tag_body);
my $my_body;
while ($token = $parser->get_token())
{
    if ($token->is_start_tag("a") || $token->is_end_tag("a"))
    {
        # Do nothing - we throw away links.
    }
    else
    {
        $my_body .= $token->as_is();
    }
}
push @$wml_xhtml_std_toc_section, { 'id' => $id, 'body' => $my_body, 'subs' => [],};
}:>
<restore id />
</define-tag>

<define-tag h3 whitespace="delete" endtag="required">
<preserve id />
<h3*<attributes-quote %attributes /> >%body</h3*>
<set-var %attributes />
<:{

my $id = <<'EOCMMFINVBOWVNIANFINLNGINWNOF';
<get-var id />
EOCMMFINVBOWVNIANFINLNGINWNOF

my $tag_body = <<'EOCMMFINVBOWVNIANFINLNGINWNOF';
%body
EOCMMFINVBOWVNIANFINLNGINWNOF

chomp($id);
chomp($tag_body);

my $parser = HTML::TokeParser::Simple->new(\$tag_body);
my $my_body;
while ($token = $parser->get_token())
{
    if ($token->is_start_tag("a") || $token->is_end_tag("a"))
    {
        # Do nothing - we throw away links.
    }
    else
    {
        $my_body .= $token->as_is();
    }
}
push @{$wml_xhtml_std_toc_section->[-1]->{subs}}, { 'id' => $id, 'body' => $my_body, 'subs' => [],};
}:>
<restore id />
</define-tag>

<define-tag toc>
{#WML_XSTD_TOC_ToC#}
</define-tag>

<define-tag toc_finale>
<:{
sub myfunc
{
my $elem = shift;
return ("<li>", "<a href=\"#" . $elem->{id} . "\">", $elem->{body}, "</a>",
        (@{$_->{subs}} ? 
            ("<br />", "<ul>", 
                (map { myfunc($_)
                    }
                @{$_->{subs}}),
                "</ul>",
            ) :
            ()
        ),
        "</li>");
}
END 
{
my $text;
$text = join ("\n", 
    "<ul>",
    (map { myfunc($_) } @$wml_xhtml_std_toc_section),
    "</ul>",
    );
print "{#WML_XSTD_TOC_ToC#:$text:##}";
}
}:>
</define-tag>

<toc_finale />
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.