From ce1c7a3eab5fb2a0bcf639171a4f2dd2ef981963 Mon Sep 17 00:00:00 2001
From: Simon McVittie <smcv@debian.org>
Date: Fri, 29 Jul 2011 20:46:42 +0100
Subject: Revert "map: don't create useless </ul><ul> sequences"

This reverts commit 2d5c2f301c04a3daa3164a2df70899fa2c1aaa38.
---
 IkiWiki/Plugin/map.pm | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

(limited to 'IkiWiki')

diff --git a/IkiWiki/Plugin/map.pm b/IkiWiki/Plugin/map.pm
index 38f090ff7..ce3ac1d24 100644
--- a/IkiWiki/Plugin/map.pm
+++ b/IkiWiki/Plugin/map.pm
@@ -94,9 +94,8 @@ sub preprocess (@) {
 			if defined $common_prefix && length $common_prefix;
 		my $depth = ($item =~ tr/\//\//) + 1;
 		my $baseitem=IkiWiki::dirname($item);
-		my $parentbase=IkiWiki::dirname($parent);
-		while (length $parentbase && length $baseitem && $baseitem !~ /^\Q$parentbase\E(\/|$)/) {
-			$parentbase=IkiWiki::dirname($parentbase);
+		while (length $parent && length $baseitem && $baseitem !~ /^\Q$parent\E(\/|$)/) {
+			$parent=IkiWiki::dirname($parent);
 			last if length $addparent && $baseitem =~ /^\Q$addparent\E(\/|$)/;
 			$addparent="";
 			$indent--;
@@ -114,10 +113,14 @@ sub preprocess (@) {
 		}
 		my @bits=split("/", $item);
 		my $p="";
-		$indent++  unless length $parent;
 		$p.="/".shift(@bits) for 1..$indent;
 		while ($depth > $indent) {
-			if (@bits && !(length $parent && "/$parent" eq $p)) {
+			$indent++;
+			if ($indent > 1) {
+				$map .= "<ul>\n";
+			}
+			if ($depth > $indent) {
+				$p.="/".shift(@bits);
 				$addparent=$p;
 				$addparent=~s/^\///;
 				$map .= "<li>"
@@ -130,11 +133,6 @@ sub preprocess (@) {
 			else {
 				$openli=0;
 			}
-			$indent++;
-			$p.="/".shift(@bits) if @bits;
-			if ($indent > 1) {
-				$map .= "<ul>\n";
-			}
 		}
 		$map .= "</li>\n" if $openli;
 		$map .= "<li>"
-- 
cgit v1.2.3


From 3f27a9733660c811c6b8d640ddadbd811979e24c Mon Sep 17 00:00:00 2001
From: Simon McVittie <smcv@debian.org>
Date: Fri, 3 Aug 2012 12:48:46 +0100
Subject: Optionally add indentation to maps

This makes them easier to debug by showing the structure. Sample output
when $spaces is set to 4 spaces:

<div class='map'>
<ul>
    <li>
    <a href="../alpha" class="mapparent">alpha</a>
        <ul>
        <li>
        <a href="../alpha/1" class="mapitem">1</a>
        </li>
        </ul>
    </li>
    <li>
    <a href="../beta" class="mapitem">beta</a>
    </li>
</ul>
</div>
---
 IkiWiki/Plugin/map.pm | 32 +++++++++++++++++++-------------
 1 file changed, 19 insertions(+), 13 deletions(-)

(limited to 'IkiWiki')

diff --git a/IkiWiki/Plugin/map.pm b/IkiWiki/Plugin/map.pm
index ce3ac1d24..6567331fa 100644
--- a/IkiWiki/Plugin/map.pm
+++ b/IkiWiki/Plugin/map.pm
@@ -72,6 +72,9 @@ sub preprocess (@) {
 		$common_prefix=IkiWiki::dirname($common_prefix);
 	}
 
+	# Set this to 1 or more spaces to pretty-print maps for debugging
+	my $spaces = "";
+
 	# Create the map.
 	my $parent="";
 	my $indent=0;
@@ -98,18 +101,18 @@ sub preprocess (@) {
 			$parent=IkiWiki::dirname($parent);
 			last if length $addparent && $baseitem =~ /^\Q$addparent\E(\/|$)/;
 			$addparent="";
-			$indent--;
-			$map .= "</li>\n";
-			if ($indent > 0) {
-				$map .= "</ul>\n";
+			$map .= ($spaces x $indent) . "</li>\n";
+			if ($indent > 1) {
+				$map .= ($spaces x $indent) . "</ul>\n";
 			}
+			$indent--;
 		}
 		while ($depth < $indent) {
-			$indent--;
-			$map .= "</li>\n";
-			if ($indent > 0) {
-				$map .= "</ul>\n";
+			$map .= ($spaces x $indent) . "</li>\n";
+			if ($indent > 1) {
+				$map .= ($spaces x $indent) . "</ul>\n";
 			}
+			$indent--;
 		}
 		my @bits=split("/", $item);
 		my $p="";
@@ -117,13 +120,14 @@ sub preprocess (@) {
 		while ($depth > $indent) {
 			$indent++;
 			if ($indent > 1) {
-				$map .= "<ul>\n";
+				$map .= ($spaces x $indent) . "<ul>\n";
 			}
 			if ($depth > $indent) {
 				$p.="/".shift(@bits);
 				$addparent=$p;
 				$addparent=~s/^\///;
-				$map .= "<li>"
+				$map .= ($spaces x $indent) . "<li>\n";
+				$map .= ($spaces x $indent)
 					.htmllink($params{page}, $params{destpage},
 						 "/".$common_prefix.$p, class => "mapparent",
 						 noimageinline => 1)
@@ -134,8 +138,9 @@ sub preprocess (@) {
 				$openli=0;
 			}
 		}
-		$map .= "</li>\n" if $openli;
-		$map .= "<li>"
+		$map .= ($spaces x $indent) . "</li>\n" if $openli;
+		$map .= ($spaces x $indent) . "<li>\n";
+		$map .= ($spaces x $indent)
 			.htmllink($params{page}, $params{destpage}, 
 				"/".$common_prefix."/".$item,
 				@linktext,
@@ -145,8 +150,9 @@ sub preprocess (@) {
 		$parent=$item;
 	}
 	while ($indent > 0) {
+		$map .= ($spaces x $indent) . "</li>\n";
 		$indent--;
-		$map .= "</li>\n</ul>\n";
+		$map .= ($spaces x $indent) . "</ul>\n";
 	}
 	$map .= "</div>\n";
 	return $map;
-- 
cgit v1.2.3


From af8712cfac73d7668e509abf97eeabb5e824c29b Mon Sep 17 00:00:00 2001
From: Simon McVittie <smcv@debian.org>
Date: Fri, 3 Aug 2012 12:53:25 +0100
Subject: map: postprocess to collapse useless </ul><ul> sequences

This re-fixes the same bug as 2d5c2f30, but without introducing
malformed HTML in some situations. This is not a very elegant
solution, but it has the advantage of passing more tests.
---
 IkiWiki/Plugin/map.pm | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

(limited to 'IkiWiki')

diff --git a/IkiWiki/Plugin/map.pm b/IkiWiki/Plugin/map.pm
index 6567331fa..4a9bf58db 100644
--- a/IkiWiki/Plugin/map.pm
+++ b/IkiWiki/Plugin/map.pm
@@ -103,7 +103,7 @@ sub preprocess (@) {
 			$addparent="";
 			$map .= ($spaces x $indent) . "</li>\n";
 			if ($indent > 1) {
-				$map .= ($spaces x $indent) . "</ul>\n";
+				$map .= ($spaces x $indent) . "</ul><map:collapse>\n";
 			}
 			$indent--;
 		}
@@ -120,7 +120,7 @@ sub preprocess (@) {
 		while ($depth > $indent) {
 			$indent++;
 			if ($indent > 1) {
-				$map .= ($spaces x $indent) . "<ul>\n";
+				$map .= ($spaces x $indent) . "<ul><map:collapse>\n";
 			}
 			if ($depth > $indent) {
 				$p.="/".shift(@bits);
@@ -154,6 +154,8 @@ sub preprocess (@) {
 		$indent--;
 		$map .= ($spaces x $indent) . "</ul>\n";
 	}
+	$map =~ s{\n *</ul><map:collapse>\n *<ul><map:collapse>\n}{\n}gs;
+	$map =~ s{<map:collapse>}{}g;
 	$map .= "</div>\n";
 	return $map;
 }
-- 
cgit v1.2.3