From 0cc7100dcf9abbab90cd49930074e3b9eaf15095 Mon Sep 17 00:00:00 2001 From: Antonio Gallo Date: Sun, 23 Oct 2011 12:34:06 +0000 Subject: improved wiki formatting: added TOC - part 2 --- h-source/Application/Include/myFunctions.php | 95 +++++++++++++++++++--------- 1 file changed, 65 insertions(+), 30 deletions(-) (limited to 'h-source/Application/Include/myFunctions.php') diff --git a/h-source/Application/Include/myFunctions.php b/h-source/Application/Include/myFunctions.php index 1356281..5cceaea 100644 --- a/h-source/Application/Include/myFunctions.php +++ b/h-source/Application/Include/myFunctions.php @@ -178,9 +178,6 @@ function htmlDiff($old, $new) $old = str_replace("\r\n"," \r\n ",$old); $new = str_replace("\r\n"," \r\n ",$new); -// $old = str_replace("\n"," \n ",$old); -// $new = str_replace("\n"," \n ",$new); - $ret = null; $diff = diff(removeEmptyStrings(explode(' ', $old)),removeEmptyStrings(explode(' ', $new))); foreach($diff as $k) @@ -272,6 +269,8 @@ function decodeWikiText($string) $string = preg_replace_callback('/(\[tab )(lang=)([^\s]+)(\s*\])(.*?)(\[\/tab\])/s', 'createTabs',$string); + $string = preg_replace_callback('/(__TOC__)/s', 'createToc',$string); + $string = preg_replace('/(\[lang\])(.*?)(\[\/lang\])/s', '
${2}
',$string); $string = preg_replace('/(\{\{)/s', '[',$string); @@ -280,11 +279,11 @@ function decodeWikiText($string) if ($decodeAnotherTime and $decodeCounter<=30) { - return decodeWikiText(Tabs::render().$string); + return decodeWikiText(Toc::render().Tabs::render().$string); } else { - return Tabs::render().$string; + return Toc::render().Tabs::render().$string; } } @@ -382,6 +381,12 @@ function createNode($match,$hnodeTag,$htmlTagBegin,$htmlTagEng) } } +function createToc($match) +{ + Toc::create(); + return null; +} + //table of contents class Toc { @@ -389,41 +394,71 @@ class Toc public static $links = array(); public static $level = 1; - public function render($array = null, $useSelf = true) + private static $html = null; + + public function create() { - if (!isset($array) and $useSelf) + $c=0; + foreach (self::$links as $link) { - $array = self::$links; - } - - $count = 0; - $str = ""; self::$links = array(); - return $str; + self::$html = implode('',$res); + } + + public function render() + { + echo self::$html; } - } //create h1, h2, h3 ($level=1,2,3) -- cgit v1.2.3