[kramdown-users] Bug in list parsing

Shawn Van Ittersum svicalifornia at gmail.com
Tue Aug 17 13:43:24 EDT 2010


Hi Matt,

The contents of the input are not known in advance; it is only assumed to be valid Markdown.

I continue to advocate the use of white-space lines to separate blocks.  Contiguous lines of text, regardless of indentation, belong to the same block.  Thus:

    > ... but this is wrong!
    No, it is not!

is a single blockquote, while

    > ... but this is wrong!

    No, it is not!

results in one blockquote and one paragraph.

The primary exception I'd make to the above rule is for list items:

    1. One
    2. Two
lazy wrapped text ok
    3. Three

would yield
    <ol>
        <li>One</li>
        <li>Two lazy wrapped text ok</li>
        <li>Three</li>
    </ol>

kramdown would look for a list item marker /\d+\./ at the start of each line, to find new list item blocks.

By these rules, a nested list would need to be wrapped in white-space lines:

    1. One
	2. Two

         a. Hello
         b. Goodbye

    3. Three

A list block following a list block at the same indentation is converted to a single list block with paragraph list items:

    1. One
    2. Two

    3. Three

    <ol>
       <li><p>One</p></li>
       <li><p>Two</p></li>
       <li><p>Three</p></li>
    </ol>

Tables and math blocks have their own internal syntax, but tables must be bordered by white-space lines and/or file boundaries:

    Here is a paragraph
    | with | table code | too close |

    <p>Here is a paragraph | with | table code | too close |</p>


    Here is a paragraph

    | with | table code | properly separated |

	<p>Here is a paragraph</p>
	<table>
		...
	</table>
	

These rules are summarized simply as:

  * All blocks must be bordered top/bottom by white-space lines and/or file boundaries, with the following exceptions.

  * List items are started by line boundary, optional whitespace, and list item marker /(\*|-|\+|\d+\.)/.  The first item of a list must be at the start of the file or have a white-space line directly above it.  The last item of a list must be at the end of the file or have a white-space line directly below it.

  * Table rows are started by line boundary, optional whitespace, and pipe character /\|/.  The first row of a table must be at the start of the file or have a white-space line directly above it.  The last row of a table must be at the end of the file or have a white-space line directly below it.

  * Math blocks start and end with $$ and have their own internal syntax.

If you read the text/plain part of this email, you'll likely see that the preceding text has been wrapped.  kramdown should still be able to recognize it as a list.  This is a core feature of Markdown, and it needs to be supported for kramdown to be acceptable by mainstream end users, who do not have patience to indent lines as precisely as you have advocated.  Markdown was created for its simplicity, to be usable by regular people, and support for lazy-indentation is a key part of that simplicity.  If kramdown does not support such a key feature of Markdown, then it really can't be called a superset of Markdown anymore.

Shawn

On Tue, 17 Aug 2010 09:52:51 -0700, Matt Neuburg wrote:
> On or about 8/17/10 7:14 AM, thus spake "Thomas Leitner" <t_leitner at gmx.at>:
> 
>> So if we change the behaviour for lists, we should probably also change
>> the behaviour for blockquotes, footnote definitions and all other
>> similar block level elements to remain consistent.
> 
> Well, I hope you don't change it. I find kramdown's behavior rational and
> deterministic (i.e. predictable and consistent), as opposed to Markdown
> where you never quite knew what would happen with a list, how your indenting
> would be interpreted, etc. And I find the documentation's explanation of how
> kramdown will behave to be clear and correct.
> 
> In the one particular case in question, if it is known that the input
> represents a list, it is trivial to preprocess it before kramdown sees it.
> It is up to the user to prepare the input for kramdown; it is not up to
> kramdown to adapt itself to incorrect input.
> 
> m.
> 
> -- 
> matt neuburg, phd = matt at tidbits.com, http://www.tidbits.com/matt/
> pantes anthropoi tou eidenai oregontai phusei
> Among the 2007 MacTech Top 25, http://tinyurl.com/2rh4pf
> AppleScript: the Definitive Guide, 2nd edition
> http://www.tidbits.com/matt/default.html#applescriptthings
> Take Control of Exploring & Customizing Snow Leopard
> http://tinyurl.com/kufyy8
> RubyFrontier! http://www.apeth.com/RubyFrontierDocs/default.html
> TidBITS, Mac news and reviews since 1990, http://www.tidbits.com
> 
> 
> 
> _______________________________________________
> kramdown-users mailing list
> kramdown-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/kramdown-users


More information about the kramdown-users mailing list