Python-Markdown / markdown

A Python implementation of John Gruber’s Markdown with Extension support.
https://python-markdown.github.io/
BSD 3-Clause "New" or "Revised" License
3.79k stars 863 forks source link

Code Blocks not converting properly. #1265

Closed ghost closed 2 years ago

ghost commented 2 years ago

I have a code block that is not converting properly. The code block becomes this

<p>```yml</p>
<p>version: "2.4"
services:
    api:
        image: radiopanel/radiopanel-api:1.0.0-rc.28
        container_name: radiopanel-api
        volumes:
            - ./uploads:/home/node/uploads:delegated
        env_file:
            - .env
        depends_on:
            database:
                condition: service_healthy</p>
<pre><code>app:
    image: radiopanel/radiopanel-app:1.0.0-rc.28
    container_name: radiopanel-app
    volumes:
        - ./certbot/conf:/etc/letsencrypt
    ports:
        - 80:80
        - 443:443
    env_file:
        - .env
    depends_on:
        - api

database:
    image: postgres:12.3-alpine
    container_name: radiopanel-postgres
    environment:
        POSTGRES_DB: radiopanel
        POSTGRES_USER: localuser
        POSTGRES_PASSWORD: CHANGE_ME
        PGDATA: /data/db
    volumes:
        - ./data:/data/db
    healthcheck:
        test: ["CMD-SHELL", "pg_isready -U localuser -d radiopanel"]
        interval: 10s
        timeout: 5s
        retries: 5

redis:
    image: redis:6.0.6-alpine
    container_name: redis
    command: ["redis-server", "--appendonly", "yes"]
    volumes:
        - redis-data:/data
</code></pre>
<p>volumes:
    redis-data:</p>
<p>```</p>

I think all the code should be in the

 and the backticks removed

facelessuser commented 2 years ago

Can you post a minimal reproducible example? It looks like you posted some results, but I can only guess as to how we got there if I don't have the source before it was parsed, and the minimal extensions required to cause the issue.

waylan commented 2 years ago

Have you enabled the fenced_code extension? Without the the source, its hard to tell for sure, but the output looks like something you might get if the extension is not enabled.

andmis commented 2 years ago

On my end, a simple fenced code block gets converted to HTML under a <p><code>...</code>, instead of <pre>...</pre>, which seems wrong. Turning on fenced_code does "fix" it, but it results in the code-block contents being placed in a <pre><code>...</code></pre>, and I am pretty sure that <code> is superfluous.

IMO, with or without an extension, a fenced code block should go into <pre> (or perhaps not be treated specially at all – but putting it into <code> seems to make very little sense), and if the extension is on, the <code> should not get added.

facelessuser commented 2 years ago

On my end, a simple fenced code block gets converted to HTML under a <p><code>...</code>, instead of <pre>...</pre>, which seems wrong. Turning on fenced_code does "fix" it, but it results in the code-block contents being placed in a <pre><code>...</code></pre>, and I am pretty sure that <code> is superfluous.

This is inline with how things are described in the HTML5 spec, so this won't be changing: https://www.w3.org/TR/2011/WD-html5-author-20110809/the-pre-element.html.

IMO, with or without an extension, a fenced code block should go into <pre> (or perhaps not be treated specially at all – but putting it into <code> seems to make very little sense), and if the extension is on, the <code> should not get added.

Standard Markdown, as described here, does not include fenced code blocks, that is non-standard; therefore, it is included via extensions, that also is not changing.

Also, this issue seems to be stale and can probably be closed at this point.

andmis commented 2 years ago

I see. Thanks for the references – I wasn't aware. Makes sense.