Nested brackets
Michel Fortin
michel.fortin at michelf.com
Fri Sep 2 09:18:43 EDT 2005
Le 2005-09-02 à 0:57, Yuri T. a écrit :
> I ironed out most of the remaining issues, it seems, except for the
> nested brackets (still looking for a non-ugly solution)
About nested brackets, unless your language support recursive regular
expressions, I don't think there is much other choice than doing what
I did in PHP: support a limited number of nested brackets. I don't
find it uglier than other solutions, and I've keept that number
configurable and easy to change:
# Regex to match balanced [brackets].
# Needed to insert a maximum bracked depth while converting to PHP.
$md_nested_brackets_depth = 6;
$md_nested_brackets =
str_repeat('(?>[^\[\]]+|\[', $md_nested_brackets_depth).
str_repeat('\])*', $md_nested_brackets_depth);
Of course it isn't as great as true nested brackets, but -- assuming
Python regex can't do recursive patterns -- the only other choice
would be to build our own nested bracket parser and change every
regular expression that need nested brackets to use the parser. That
would probably mean re-writing each of these regular expressions as a
custom parser function, a tedious task at least.
If I where you I would go with the fixed solution on the basis that a
fixed number is better than nothing and that it keeps things easy to
update. I can't even think of a real-life case where six level
wouldn't be enough. I can say I never go this reported as a problem,
yet.
Michel Fortin
michel.fortin at michelf.com
http://www.michelf.com/
More information about the Markdown-Discuss
mailing list