Multiline code block within a list
Waylan Limberg
waylan at gmail.com
Mon Nov 7 16:24:43 EST 2011
On Mon, Nov 7, 2011 at 3:55 PM, Thomas Leitner <t_leitner at gmx.at> wrote:
> On 2011-11-08 01:08 +0800 Ryan Chan wrote:
>> Actually this is one of the limitation that I went to reST...sad to
>> hear the suitation is still the same..
>
> Not with every implementation. You can do this easily with kramdown:
>
> ~~~~~~~~~~~~~~~~~~~~
> * for
> * bar
> *
> Code 1 (8 spaces)
> Code 2
> Code 3
> * Another list item
> ~~~~~~~~~~~~~~~~~~~~
>
> will produce
>
> ~~~~~~~~~~~~~~~~~~~~
> <ul>
> <li>for</li>
> <li>bar</li>
> <li>
> <pre><code>Code 1
> Code 2
> Code 3
> </code></pre>
> </li>
> <li>Another list item</li>
> </ul>
> ~~~~~~~~~~~~~~~~~~~~
>
> The line with the `* ` (after `* bar`) is needed to tell kramdown that
> this is a list item and not just an asterisk.
This works with Python-Markdown, peg markdown and perhaps a few others as well.
We need the blank line (line with an asterisk and space only) because,
per the syntax rules, any whitespace after the asterisk is ignored
until the first non-whitespace char. That means it is impossible to
indent the first line of a list item.
Perhaps not the best rule, but it is a clear rule. All sorts of
existing documents would break if we changed it. Besides, in this
case, the indentation would be off. See this example (with dots in
place of spaces):
*.....Code with one space for list and four for code
........Code with 8 spaces.
Notice our those two lines of code don't line up vertically. Ugly. In contrast,
*.
........Code with 8 spaces
........More code with 8 spaces
Looks much better and is easier to read. Unfortunately not all
implementations support it. I think they should.
--
----
\X/ /-\ `/ |_ /-\ |\|
Waylan Limberg
More information about the Markdown-Discuss
mailing list