diff -r 616d046e3bd9 -r 88265c8715d0 Wikulator.php --- a/Wikulator.php Wed Dec 24 11:04:18 2008 -0500 +++ b/Wikulator.php Fri May 29 14:32:47 2009 -0400 @@ -16,7 +16,7 @@ * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for details. */ -$plugins->attachHook('render_wikiformat_pre', 'mediafier_draw_toc($text);'); +$plugins->attachHook('render_wikiformat_posttemplates', 'mediafier_draw_toc($text);'); $plugins->attachHook('render_wikiformat_post', 'mediafy($result);'); $plugins->attachHook('compile_template', 'mediafier_add_headers();'); $plugins->attachHook('html_attribute_whitelist', '$whitelist["ref"] = array(); $whitelist["references"] = array("/");'); @@ -66,7 +66,8 @@ unset($treenum[count($treenum)-1]); } } - $treenum[count($treenum)-1]++; + if ( isset($treenum[count($treenum)-1]) ) + $treenum[count($treenum)-1]++; if ( $i > 0 ) $toc .= ''; $toc .= '
' . implode('.', $treenum) . ' ' . htmlspecialchars($matches[2][$i]) . ''; @@ -81,11 +82,20 @@
Contents [hide]
$toc
"; - + if ( strstr($text, '__TOC__') ) + { $text = str_replace_once('__TOC__', $toc_body, $text); - else if ( ($text = preg_replace('/^=/', "$toc_body\n\n=", $text)) === $text ) + } + else if ( $text === ($rtext = preg_replace('/^=/', "$toc_body\n\n=", $text)) ) + { $text = str_replace_once("\n=", "\n$toc_body\n=", $text); + } + else + { + $text = $rtext; + unset($rtext); + } } function mediafier_add_headers() @@ -202,7 +212,7 @@ // highlight matches foreach ( $words as $word ) { - $result = preg_replace('/([\W]|^)(' . preg_quote($word) . ')([\W])/i', "\\1\\2\\3", $result); + $result = preg_replace('/([\W]|^)(' . str_replace('/', '\/', preg_quote($word)) . ')([\W])/i', "\\1\\2\\3", $result); } // restore HTML @@ -256,6 +266,7 @@ foreach ( $refs as $i => $ref ) { $reflink = '^ '; + $ref = trim($ref); $refsdiv .= "
$reflink $i. $ref
"; if ( $i == $count ) $refsdiv .= '';