On 18 Feb 2008, at 23:59, Andrea Censi wrote:

[...]
In a nutshell: given that Markdown.pl (and straight ports of it) do
processing using multiple passes of regex/replace, you cannot find a
syntax that captures Markdown.pl's behavior exactly.

I did a rule-based implementation which I have unfortunately since lost¹.

A rule had 4 elements to it:

1. A regexp that makes the parser enter the context the rule represents (e.g. block quote, list, raw, etc.).

2. A list of which rules are allowed in the context of this rule.

3. A regexp for leaving the context of this rule.

4. A regexp which is pushed onto a stack when entering the context of this rule, and popped again when leaving this rule.

The fourth item here is really the interesting part, because it is what made Markdown nesting work (99% of the time) despite this being 100% rule-driven.

The implementation of this did disagree with Markdown.pl on various edge cases, but the spirit of Markdown was definitely there and it felt way more predictable and flexible (e.g. you can have block quote go directly after starting a list item, etc.)

It does however take a “no look-ahead”-approach, so e.g. `_` will always enter emphasis, regardless of whether or not there is a closing `_` later in the document.




¹ My main machine broke so I was working on a spare laptop while waiting for a replacement, and it was on this machine I wrote the Markdown parser, but I am afraid that the laptop saw a clean install before I was able to copy the source to another machine :/

_______________________________________________
Markdown-Discuss mailing list
[email protected]
http://six.pairlist.net/mailman/listinfo/markdown-discuss

Reply via email to