public static function renderTableOfContents(PhutilRemarkupEngine $engine)
 {
     $key = self::KEY_HEADER_TOC;
     $anchors = $engine->getTextMetadata($key, array());
     if (count($anchors) < 2) {
         // Don't generate a TOC if there are no headers, or if there's only
         // one header (since such a TOC would be silly).
         return null;
     }
     $depth = 0;
     $toc = array();
     foreach ($anchors as $anchor => $info) {
         list($level, $name) = $info;
         while ($depth < $level) {
             $toc[] = '<ul>';
             $depth++;
         }
         while ($depth > $level) {
             $toc[] = '</ul>';
             $depth--;
         }
         $toc[] = phutil_render_tag('li', array(), phutil_render_tag('a', array('href' => '#' . $anchor), phutil_escape_html($name)));
     }
     while ($depth > 0) {
         $toc[] = '</ul>';
         $depth--;
     }
     return implode("\n", $toc);
 }