Re: Formal Grammar — some thoughts

Michel Fortin michel.fortin at michelf.com
Tue Aug 1 19:44:03 EDT 2006


Le 1 août 2006 à 11:16, Allan Odgaard a écrit :


> From the syntax I get that I can do `> block quote` and `* list

> item` and from the cheat sheet that I can nest things like:

>

> * > list item with quoted text

>

> Ignoring here that the HTML produced for that is:

>

> <ul>

> <li>> list item with quoting</li>

> </ul>


That's perfectly understandable: list item content can contain either
block-level elements, or span level elements + sublists. For an item
to contain block-level content, it must be separated by a blank line
from the previous or the next item (it must not be the sole item in
the list), or it must contain one or more blank line.

So your list item has span-level content and thus cannot have a
blockquote. But try this instead and it will work as you expect:

* > list item with quoted text

* > another list item with quoted text



> Let’s continue with the syntax which further says that I can be

> lazy and leave out the indent for list items and `>` for block

> quotes. So what should this convert to:

>

> * > list item with quoting

> more text here


Idem: span-level content.



> Does the additional line belong to the block quote or the list

> item? I’m inclined to say block quote, since a block quote is not

> terminated before there is a blank line, at least from how I read

> the syntax. But then what about this:

>

> * > list item with quoting

> more text here

> * another list item

>

> There is no blank line after the block quote, so does `* another

> list item` also belong to the block quote?


Idem: span-level content. Put a blank line between the items if you
want a blockquote, and then you won't have a problem with the next
list item.



> This particular example does not parse as a block quote, but if we

> make one that does, we will see that Markdown does indeed make the

> list item part of the block quote, for example this example:

>

> * leading text as block quote can’t be first

> > some block quoted text

> * another list item

>

> Turns into this (wrongly nested, but at least it got the block

> quote) HTML:

>

> <p><ul>

> <li>leading text as block quote can’t be first</p>

>

> <blockquote>

> <p>some block quoted text</li>

> <li>another list item</li>

> </ul></p>

> </blockquote>


There is obviously a bug there. Try it on the [PHP Markdown dingus]
[1] and select PHP Markdown Extra: span-level content and no
blockquote, as it should.

[1]: http://www.michelf.com/projects/php-markdown/dingus/

This bug arise because Markdown does not hash the `<ul>` HTML block
it just produced before looking for blockquotes in the text.



> This however raises two questions:

>

> 1. Should it actually be a list item in the block quote? for

> example take this example:

>

> > block quote

> * more block quote

>

> Which turns into this markup (i.e. there is no list item):

>

> <blockquote>

> <p>block quote

> * more block quote</p>

> </blockquote>


There is no list item because when not inside a list item triggering
a list requires a blank line prior the first item. So you should
really use this:

> block quote

> * more block quote

or this:

> block quote

* more block quote

depending on what you want.

But, when inside a list item this question makes sense. So I'll
reformulate your code sample like this:

* list item interpreted as a block as the next line is blank

> block quote
* list item

And I get a list item inside the blockquote just as you expected.
This result seems logical to me and you can always insert a blank
line if you don't want the item to be part of the blockquote.



> 2. If `* another list item` gets nested into the block quote, we

> need a blank line in front of that item to make it part of the root

> list. But then, will we get the “spaced out” version of the list

> where each item is wrapped in `<p>…</p>` (which is normal for such

> “spaced out” lists.)?


Yes, list items when separated by a blank line have block-level
content. Sorry, I know I'm repeating myself.



> These are the problems I want to have addressed/fixed! And this is

> where I think the syntax needs revising. I have shown above the

> problems with the ambiguity of nesting, but lazy mode for block

> quoting I think should not be a feature at all, take this example:

>

> > > I wrote something

> > you replied

> and now here is my reply to your reply.

>

> This turns into the following markup:

>

> <blockquote>

> <blockquote>

> <p>I wrote something

> you replied

> and now here is my combat.</p>

> </blockquote>

> </blockquote>

>

> Would people actually expect that?


Pretty interesting observation. I have no answer to that question. I
suppose it's either that or we remove support for "lazy" blockquotes.



> Anyway, this thread was just to learn the interest in a more strict

> (but potentially revised) syntax and Johns future direction and

> thoughts on this.


Everyting you've pointed out seems to be working as it should, or at
least as I think it should. Do you still see something that need to
be fixed, or something wrong in my analysis? If so, please tell what
and why, and don't forget examples.

If something can be fixed or improved, it's the document about the
syntax. The syntax seems pretty clear to me -- probably because I've
been working on PHP Markdown for so long -- and is probably suffisent
for someone who wish to understand how to use Markdown (the tool),
but it cannot be the sole reference for building a new implementation.


Michel Fortin
michel.fortin at michelf.com
http://www.michelf.com/




More information about the Markdown-Discuss mailing list