Revision [793]

This is an old revision of TableOfContentsPseudoAction made by AndreaRossato on 2004-07-28 11:58:48.

 

Table of Contents



This patch against formatters/wakka.php will provide a table of contents pseudo action.
You also need to remove, from actions/header.php, this line:
<base href="<?php echo $site_base ?>" />

To use it insert in your page {{toc}} or {toc nr}} for a numbered toc.
You can also change the toc name (Index is the default):
{{toc nr Table of Contents}}
The biggest header ======Header======, to be used only for the page title, will not be included in the toc.

That's it.
Have fun.
--AndreaRossato

The code:

--- wakka.php.orig	2004-05-29 13:20:24.000000000 +0000
+++ wakka.php	2004-07-28 13:51:19.000000000 +0000
@@ -121,36 +121,68 @@
 			if (preg_match("/^(.*)\.(gif|jpg|png)/si", $url)) return "<img src=\"$url\" />".$matches[2]; 
 			return $wakka->Link($url).$matches[2]; 
 		}
-		// header level 5
-		else if ($thing == "==")
-		{
+		//headers with toc pseudo action
+		else if (preg_match("/^======(.*)======$/s", $thing, $matches))
+			{
 				$br = 0;
-				return (++$trigger_l[5] % 2 ? "<h5>" : "</h5>\n");
-		}
-		// header level 4
-		else if ($thing == "===")
-		{
+				return "<h1>".str_replace("\n","<br />",htmlspecialchars($matches[1]))."</h1>";
+			}
+		
+		else if (preg_match("/^=====(.*)=====$/s", $thing, $matches))
+			{
+				if ($_SESSION['tocnr'] == "yep")
+					{
+						$_SESSION["hr5"]++;
+						$_SESSION["hr4"] = 0;
+						$_SESSION["hr3"] = 0;
+						$_SESSION["hr2"] = 0;
+						$_SESSION["toccount"] = $_SESSION["hr5"].". ";
+					}
+				$_SESSION["headercount"]++;
+				$_SESSION['toc'] .= "<a style=\"padding-left:10px\" href=\"#titelanker".$_SESSION["headercount"]."\">".$_SESSION["toccount"].trim(htmlspecialchars($matches[1]))."</a><br />";
 				$br = 0;
-				return (++$trigger_l[4] % 2 ? "<h4>" : "</h4>\n");
-		}
-		// header level 3
-		else if ($thing == "====")
-		{
+				return "<a id=\"titelanker".$_SESSION["headercount"]."\"></a><h2>".$_SESSION["toccount"].trim(htmlspecialchars($matches[1]))."</h2>";
+			}
+		else if (preg_match("/^====(.*)====$/s", $thing, $matches))
+			{
+				if ($_SESSION['tocnr'] == "yep")
+					{
+						$_SESSION["hr4"]++;
+						$_SESSION["hr3"] = 0;
+						$_SESSION["hr2"] = 0;
+						$_SESSION["toccount"] = (($_SESSION["hr5"]) ? $_SESSION["hr5"].". " : "").$_SESSION["hr4"].". ";
+						
+					}
+				$_SESSION["headercount"]++;
+				$_SESSION['toc'] .= "<a style=\"padding-left:25px\" href=\"#titelanker".$_SESSION["headercount"]."\">".$_SESSION["toccount"].trim(htmlspecialchars($matches[1]))."</a><br />";
 				$br = 0;
-				return (++$trigger_l[3] % 2 ? "<h3>" : "</h3>\n");
-		}
-		// header level 2
-		else if ($thing == "=====")
-		{
+				return "<a id=\"titelanker".$_SESSION["headercount"]."\"></a><h3>".$_SESSION["toccount"].trim(htmlspecialchars($matches[1]))."</h3>";
+			}
+		else if (preg_match("/^===(.*)===$/s", $thing, $matches))
+			{
+				if ($_SESSION['tocnr'] == "yep")
+					{
+						$_SESSION["hr3"]++;
+						$_SESSION["hr2"] = 0;
+						$_SESSION["toccount"] = (($_SESSION["hr5"]) ? $_SESSION["hr5"].". " : "").(($_SESSION["hr4"]) ? $_SESSION["hr4"].". " : "").$_SESSION["hr3"].". ";
+					}
+				$_SESSION["headercount"]++;
+				$_SESSION['toc'] .= "<a style=\"padding-left:40px\" href=\"#titelanker".$_SESSION["headercount"]."\">".$_SESSION["toccount"].trim(htmlspecialchars($matches[1]))."</a><br />";
 				$br = 0;
-				return (++$trigger_l[2] % 2 ? "<h2>" : "</h2>\n");
-		}
-		// header level 1
-		else if ($thing == "======")
-		{
+				return "<a id=\"titelanker".$_SESSION["headercount"]."\"></a><h4>".$_SESSION["toccount"].trim(htmlspecialchars($matches[1]))."</h4>";
+			}
+		else if (preg_match("/^==(.*)==$/s", $thing, $matches))
+			{
+				if ($_SESSION['tocnr'] == "yep")
+					{
+						$_SESSION["hr2"]++;
+						$_SESSION["toccount"] = (($_SESSION["hr5"]) ? $_SESSION["hr5"].". " : "").(($_SESSION["hr4"]) ? $_SESSION["hr4"].". " : "").(($_SESSION["hr3"]) ? $_SESSION["hr3"].". " : "").$_SESSION["hr2"].". ";
+					}
+				$_SESSION["headercount"]++;
+				$_SESSION['toc'] .= "<a style=\"padding-left:55px\" href=\"#titelanker".$_SESSION["headercount"]."\">".$_SESSION["toccount"].trim(htmlspecialchars($matches[1]))."</a><br />";
 				$br = 0;
-				return (++$trigger_l[1] % 2 ? "<h1>" : "</h1>\n");
-		}
+				return "<a id=\"titelanker".$_SESSION["headercount"]."\"></a><h5>".$_SESSION["toccount"].trim(htmlspecialchars($matches[1]))."</h5>";
+			}
 		// forced line breaks
 		else if ($thing == "---")
 		{
@@ -319,6 +351,28 @@
 $text = str_replace("\r", "", $text);
 $text = chop($text)."\n";
 
+//pseudotocaction durch phantasiewort ersetzen, um es nachher wieder mit dem tocinhalt zu ersetzen
+if (preg_match("/{{toc nr ([A-Za-z0-9 ]*)}}/is", $text, $toctitle))
+		{
+		$text = preg_replace("/{{toc ([A-Za-z0-9 ]*)}}/", "{{toc nr}}", $text);
+		}
+else if (preg_match("/{{toc ([^nr][A-Za-z0-9 ]*)}}/is", $text, $toctitle))
+		{
+		$text = preg_replace("/{{toc ([^nr][A-Za-z0-9 ]*)}}/", "{{toc}}", $text);
+		}
+
+if ($toctitle[1] == "") 
+	 $toctitle[1] = "Index";
+
+
+if (strpos($text, "{toc nr}}"))
+   $_SESSION['tocnr'] = "yep";
+
+
+$text = preg_replace("/{{toc}}/", "tocactionplaceboding", $text);
+$text = preg_replace("/{{toc nr}}/", "tocactionplaceboding", $text);
+
+
 $text = preg_replace_callback(
 	"/(\%\%.*?\%\%|".
 	"\"\".*?\"\"|".
@@ -326,7 +380,7 @@
 	"-{4,}|---|".
 	"\b[a-z]+:\/\/\S+|".
 	"\*\*|\'\'|\#\#|\#\%|@@|::c::|\>\>|\<\<|&pound;&pound;|\+\+|__|<|>|\/\/|".
-	"======|=====|====|===|==|".
+	"======.*?======|=====.*?=====|====.*?====|===.*?===|==.*?==|".
 	"\n([\t,~]+)(-|[0-9,a-z,A-Z]+\))?|".
 	"\{\{.*?\}\}|".
 	"\b[A-Z,ÄÖÜ][A-Z,a-z,ÄÖÜ,ßäöü]+[:]([A-Z,a-z,0-9,ÄÖÜ,ßäöü]*)\b|".
@@ -344,8 +398,18 @@
 $replace3 = "\n";
 $text=preg_replace($pattern3,$replace3,$text);
 
+$text = preg_replace("/tocactionplaceboding/", "<fieldset><legend>&#160;<b>".$toctitle[1]."&#160;</b></legend>".$_SESSION['toc']."</fieldset>", $text);
+
 // we're cutting the last <br />
 $text = preg_replace("/<br \/>$/","", trim($text));
 echo ($text);
 wakka2callback('closetags');
+$_SESSION['toc'] = "";
+$_SESSION['tocnr'] = "nope";
+$_SESSION["headercount"] = 0;
+$_SESSION["hr5"] = 0;
+$_SESSION["hr4"] = 0;
+$_SESSION["hr3"] = 0;
+$_SESSION["hr2"] = 0;
+$_SESSION["toccount"] = "";
 ?>
There are no comments on this page.
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki