Multiline code block within a list
John MacFarlane
jgm at berkeley.edu
Mon Nov 7 19:01:04 EST 2011
+++ Waylan Limberg [Nov 07 11 16:24 ]:
> 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.
The alternate rule (described in my last email) seems equally reasonable to me,
and the official markdown syntax description doesn't distinguish between
them. (It never says explicitly that all spaces after the asterisk are
ignored -- correct me if I'm wrong.)
Note that the alternate rule, when properly implemented, also allows vertically
aligned input.
~~~~
% discount
* code
code
<ul>
<li><pre><code>code
code
</code></pre>
</li>
</ul>
~~~~
It gets more complicated still when you have space *before* the list
marker, which markdown allows. Here discount gets it wrong, I think:
~~~~
% discount
* code
code
<ul>
<li><pre><code>code
code
</code></pre>
</li>
</ul>
~~~~
lunamark does better, if you care about vertical alignment:
~~~~
% lunamark
* code
code
<ul>
<li><pre><code>code
code
</code></pre></li>
</ul>
~~~~
lunamark also allows the python-markdown/kramdown way:
~~~~
% lunamark
*
hi
<ul>
<li><pre><code>hi
</code></pre></li>
</ul>
~~~~
I'm not saying any of these ways is right or even best, but this is another
good illustration of the vagueness of the markdown syntax spec.
John
More information about the Markdown-Discuss
mailing list