<?php

class Plugin_outline extends Plugin
{
	function do_block($pagename, $param1, $param2)
	{
		$page = Page::getinstance($pagename);
		$nest = max((int)trim($param1), 1);
		
		$body = parse_block($page->getsource(), $page->getpagename());
		$anchormaker = new SectionAnchorMaker;
		$list = array();
		foreach($body->getelements() as $e){
			if(get_class($e) == 'T_Heading'){
				$str = $e->getelem()->getsource();
				$id = $anchormaker->makeid($e->getlevel(), $str);
				if($e->getlevel() <= $nest){
					$list[] = str_repeat('-', $e->getlevel()) . "&anchor($id){{$str}}";
				}
			}
		}
		return convert_block(join("\n", $list), $page->getpagename());
	}
}

?>