testing python-markdown
John Gruber
gruber at fedora.net
Sun Aug 14 02:28:41 EDT 2005
Yuri T. <qaramazov at gmail.com> wrote on 08/13/05 at 7:42 pm:
> 1. Lack of support for nested braces ([[braces]](url)) - I can't think
> of an easy way of adding this for the lack of python equivalent of
> perl's recursive regexps. I am not sure it's worth it.
That's a shame. Does it help if you look at Michel's PHP
implementation? PHP doesn't have recursive patterns the same way
Perl does, but Michel has worked around it. I just glanced at the
source for an older version of PHP Markdown, and it looks like he's
just doing it by looking for nested `[]` pairs up to 6 levels deep
-- which for all practical purposes is deep enough.
> 2. <p> tags in "loose" lists - I missed this rule earlier and now
> figured out that I my current design makes it hard to implement it.
> (When I am processing a list item I don't know what kind of a list
> it's a part of.) This does seem like an important feature, so I will
> think about it more when I am in a procrastination mode.
So your lists never add <p> tags?
> 3. Markdown.pl converts "+\tText" to "+ Text", i.e. it uses THREE
> tabs. What is the actual rule there? I can see that Markdown.pl
> handles tabs via $text =~ s{(.*?)\t}{$1.(' ' x ($g_tab_width -
> length($1) % $g_tab_width))}ge; but this looks like line noise to
> me... Can someone provide pseudo-code for this?
Tab stops aren't "four spaces", they're "move to the next column
that's a multiple of 4". Although instead of hard-coding 4,
Markdown.pl uses a global, $g_tab_width.
So what we have is the regex:
(.*?)\t
which says to lazily capture everything up to the first tab
character, saving it in group $1.
Then we have the substitution:
{$1.(' ' x ($g_tab_width - length($1) % $g_tab_width))}ge;
which, because of the /e option, isn't just a pattern, but is Perl code.
$1 is the text before the tab, and we put it back in the replacement.
Then we replace the tab with the right number of spaces. The right
number of spaces is
4 - length($1) % 4
In Perl, the x operator is like a multiplicative concatenator for
strings.
'j' x 4
returns
jjjj
Hope this helps,
-J.G.
More information about the Markdown-Discuss
mailing list