Added conflict resolution for wikitext heading names
authorDan Fuhry <dan@enanocms.org>
Fri, 19 Nov 2010 03:30:35 -0500
changeset 1329 61d87ee12e80
parent 1328 2a5845ef8c1d
child 1330 1649f687e69e
Added conflict resolution for wikitext heading names
includes/wikiengine/render_xhtml.php
--- a/includes/wikiengine/render_xhtml.php	Fri Nov 19 02:47:10 2010 -0500
+++ b/includes/wikiengine/render_xhtml.php	Fri Nov 19 03:30:35 2010 -0500
@@ -26,11 +26,23 @@
 	
 	public function heading($text, $pieces)
 	{
+		static $heading_names = array();
 		foreach ( $pieces as $i => $piece )
 		{
 			$tocid = sanitize_page_id(trim($piece['text']));
 			// (bad) workaround for links in headings
 			$tocid = str_replace(array('[', ']'), '', $tocid);
+			// conflict avoidance
+			if ( isset($heading_names[$tocid]) )
+			{
+				$id = 2;
+				while ( isset($heading_names["{$tocid}{$id}"]) )
+					$id++;
+				
+				$tocid .= $id;
+			}
+			$heading_names[$tocid] = true;
+			
 			$tag = '<h' . $piece['level'] . ' id="head:' . $tocid . '">';
 			$tag .= trim($piece['text']);
 			$tag .= '</h' . $piece['level'] . '>';