The attached patch implements IRequestFilter methods. The idea behind that is being able to use the generated TOC within a .cs-template (where you can't call a macro). The TOC content is added to the template variable tracnavplugin.toc.
Example:
I use the following snippet in a test installation, template wiki.cs:
...
<div id="content" class="wiki">
<?cs if tracnavplugin.toc && wiki.action == "view" ?>
<div class="tracnav-toc"><?cs var:tracnavplugin.toc ?></div>
<?cs /if ?>
<?cs if wiki.action == "delete" =><?cs
...
The patch should apply cleanly against current trunk. The modification works for Trac 0.10 only, since IRequestFilter are not available in previous Trac releases afaik.