sirthias / pegdown

A pure-Java Markdown processor based on a parboiled PEG parser supporting a number of extensions
http://pegdown.org
Apache License 2.0
1.29k stars 218 forks source link

Allow lists without a leading blank line to be rendered as lists (GitHub flavored) #224

Open depryf opened 8 years ago

depryf commented 8 years ago

Maybe there is already a way to do this, but I didn't find it in the current extensions.

The regular markdown (not GitHub flavored) requires an empty line between a sentence and the start of a list:

This is a sentence

- list item 1
- list item 2

The following in regular markdown (and in pegdown) doesn't render the list items in a list:

This is a sentence
- list item 1
- list item 2

In GitHub it does.

Is there currently a way to achieve the same behavior as in GitHub?

vsch commented 7 years ago

@depryf, there is no way to do it in pegdown and no easy way without risking breaking a lot of parser rules.

The difficulty in maintaining and modifying pegdown parser was one of the reasons I rewrote commonmark-java to replace pegdown in my Markdown Navigator plugin for IntelliJ IDEs: https://github.com/vsch/idea-multimarkdown. The parser project is https://github.com/vsch/flexmark-java has very detailed source based AST with source offset for every part of the element. I need that for syntax highlighting and other plugin source reliant features.

It is CommonMark 0.27 (GitHub Comments) compliant but In the last release I added list parsing options to emulate list indentation rules used by: markdown.pl, MultiMarkdown (like pegdown 4 space indents) and kramdown (GitHub Docs). The only extensions that pegdown has that I did not yet implement are: typographic quotes, smarts and definition lists. The rest of the extensions are available, with some extra ones that pegdown does not have.

As an added bonus and what motivated me to switch the parsing is 30-50x faster than pegdown on average documents and several thousand times faster on pegdown's pathological input like [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[.

The AST offsets are bug free and regular. It is also fully modifiable unlike pegdown's with next, prev and parent links.

depryf commented 7 years ago

Thank you for the answer. I guess this issue can be closed then!