getpelican / pelican

Static site generator that supports Markdown and reST syntax. Powered by Python.
https://getpelican.com
GNU Affero General Public License v3.0
12.58k stars 1.81k forks source link

Markdown code highlighting after list doesn't work #1286

Closed s9w closed 10 years ago

s9w commented 10 years ago

If a code block directly comes after a list, it doesn't seem to work:

- list item

    :::python
    a=42

it does however if there's some normal text seperating them like this:

- list item

normal text

    :::python
    a=42
mwcz commented 10 years ago

AFAIK that's just how Markdown behaves. I just tried it in two different (non-Pelican) Markdown libraries.

s9w commented 10 years ago

strapdown.js can handle it.

mwcz commented 10 years ago

Hmm, after looking into it, this behavior is decribed in this document, which describes the differences between Python-Markdown and other Markdown implementations.

The syntax rules clearly state that when a list item consists of multiple paragraphs, “each subsequent paragraph in a list item must be indented by either 4 spaces or one tab” (emphasis added). However, many implementations do not enforce this rule and allow less than 4 spaces of indentation. The implementers of Python-Markdown consider it a bug to not enforce this rule.

So the four spaces that you're using to indent your code are instead interpreted as a paragraph of the list item. Python-Markdown is following the spec, so I don't expect you'll be able to get this changed.

My suggestion would be to succumb to Markdown and put some text between the list and the code, but if you really don't want to, you can get away with this hack:

- list item

 

    :::python
    a=42
mwcz commented 10 years ago

Either way, this isn't a Pelican issue, so this can be closed. :)

justinmayer commented 10 years ago

Very well explained, @mwcz. Many thanks for the assistance!

swasher commented 10 years ago

Works like a charm in pursuance of Makrdown specification. All you need its a place eight spaces before code block. Best regards!

zhao-ji commented 9 years ago

@swasher good job! thank you !