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/languages.php | 1 + h-source/Application/Include/myFunctions.php | 95 +++++++++++++++++++--------- h-source/Public/Css/main.css | 13 ++++ 3 files changed, 79 insertions(+), 30 deletions(-) diff --git a/h-source/Application/Include/languages.php b/h-source/Application/Include/languages.php index ad67f4d..4df9ee8 100644 --- a/h-source/Application/Include/languages.php +++ b/h-source/Application/Include/languages.php @@ -316,6 +316,7 @@ class Lang /*0268*/"No modems found" => "Non รจ stato trovato alcun modem", /*0269*/"Download the xml file of all the modems in the database" => "Scarica il file xml di tutti i modem presenti nel database", /*0270*/"Modems and ADSL cards" => "Modem e schede ADSL", + /*0271*/"Table of contents" => "Indice dei contenuti", ), 'es' => array ( 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) diff --git a/h-source/Public/Css/main.css b/h-source/Public/Css/main.css index 1f6e597..0ffd46c 100644 --- a/h-source/Public/Css/main.css +++ b/h-source/Public/Css/main.css @@ -687,6 +687,17 @@ ins { margin-bottom:10px; } +.tables_of_contents +{ + margin:10px 0; + padding:5px; + background-color:#C7DAEF; +} +.tables_of_contents_title +{ + margin:5px; + font-weight:bold; +} /*wiki code*/ .code_pre { @@ -712,11 +723,13 @@ ins { font:bold 17px/1 sans-serif,arial; color:gray; + padding:2px 0; } .div_h3 { font:bold 16px/1 sans-serif,arial; color:gray; + padding:2px 0; } .div_lang { -- cgit v1.2.3