nested links

Stephen Haberman stephenh at chase3000.com
Sun Dec 19 16:49:37 EST 2004


> The rule is that each new level of indentation for nested lists
> should be 4 spaces or a tab. Change your list to this:

Ah...I see what is going on. I got confused because I've been using
two-space indentation the whole time and it worked great until I got to
doing 3 levels.

I tracked the 'problem' down to _Outdent, which does:

	$text =~ s/^(\t|[ ]{1,$g_tab_width})//gm;

My interpretation is that the range of {1,$g_tab_width} was letting me be
lazy and only use two spaces. But then when I started doing 3rd-level nested
lists, _Outdent would get:

  * 2nd level
    * 3rd level

And outdent /both/ my 2nd and 3rd levels during the same call. The 2nd level
having a 2 space prefix and 3rd level having a 4 space prefix, both of which
are within that {1, $g_tab_width} range, and hence both prefixes were
outdented during the same call to _Outdent.

The fact that _Outdent was outdenting by both 2 and 4 spaces within the same
call seemed odd to me, so I changed _Outdent to do:

	my $outdentLength = $g_tab_width;

	foreach my $line (split /\n/, $text) {
		if ($line =~ /^([ ]+)/) {
			if (length($1) < $outdentLength) {
				$outdentLength = length($1);
			}
		}
	}

	$text =~ s/^(\t|[ ]{$outdentLength})//gm;


So, it defaults $outdentLength to $g_tab_width but then it goes through and
looks for any prefixes of 1-3 spaces, and changes $outdentLength to that
amount.

This lets me use 2 spaces, have $outdentLength set to 2, and then the entire
$text is outdented by the 2 and only 2 spaces I want taken out. And then
nested lists work like a charm.

I really like how my lists line up in a fixed-width font with 2 space
indentation, though I'll admit that up until now, I've just been
lucky/sloppy. But since I've found a pretty simple way to support them,
could lists be officially changed from "4 space or tab" to "1-4 space or
tab" with this change to _Outdent, or is that too liberal of a spec for your
tastes?

Thanks,
Stephen






More information about the Markdown-Discuss mailing list