Added ability to use hash marks in internal links
authorDan
Mon, 29 Sep 2008 08:26:49 -0400
changeset 715 29663506e85c
parent 714 2f1706c4231f
child 716 d9533bb07563
Added ability to use hash marks in internal links
includes/render.php
--- a/includes/render.php	Mon Sep 29 08:26:21 2008 -0400
+++ b/includes/render.php	Mon Sep 29 08:26:49 2008 -0400
@@ -271,6 +271,17 @@
       eval($cmd);
     }
     
+    //$template_regex = "/\{\{([^\]]+?)((\n([ ]*?)[A-z0-9]+([ ]*?)=([ ]*?)(.+?))*)\}\}/is";
+    $template_regex = "/\{\{(.+)((\n|\|[ ]*([A-z0-9]+)[ ]*=[ ]*(.+))*)\}\}/isU";
+    $i = 0;
+    while ( preg_match($template_regex, $text) )
+    {
+      $i++;
+      if ( $i == 5 )
+        break;
+      $text = RenderMan::include_templates($text);
+    }
+    
     if ( !$plaintext )
     {
       // Process images
@@ -287,17 +298,6 @@
       }
     }
     
-    //$template_regex = "/\{\{([^\]]+?)((\n([ ]*?)[A-z0-9]+([ ]*?)=([ ]*?)(.+?))*)\}\}/is";
-    $template_regex = "/\{\{(.+)((\n|\|[ ]*([A-z0-9]+)[ ]*=[ ]*(.+))*)\}\}/isU";
-    $i = 0;
-    while ( preg_match($template_regex, $text) )
-    {
-      $i++;
-      if ( $i == 5 )
-        break;
-      $text = RenderMan::include_templates($text);
-    }
-    
     // Before shipping it out to the renderer, replace spaces in between headings and paragraphs:
     $text = preg_replace('/<\/(h[0-9]|div|p)>([\s]+)<(h[0-9]|div|p)( .+?)?>/i', '</\\1><\\3\\4>', $text);
     
@@ -495,9 +495,18 @@
     foreach ( $matches[0] as $i => $match )
     {
       list($page_id, $namespace) = RenderMan::strToPageID($matches[1][$i]);
+      if ( ($pos = strrpos($page_id, '#')) !== false )
+      {
+        $hash = substr($page_id, $pos);
+        $page_id = substr($page_id, 0, $pos);
+      }
+      else
+      {
+        $hash = '';
+      }
       $pid_clean = $paths->nslist[$namespace] . sanitize_page_id($page_id);
       
-      $url = makeUrl($pid_clean, false, true);
+      $url = makeUrl($pid_clean, false, true) . $hash;
       $inner_text = $matches[2][$i];
       $quot = '"';
       $exists = ( isPage($pid_clean) ) ? '' : ' class="wikilink-nonexistent"';