showdownjs / showdown

A bidirectional Markdown to HTML to Markdown converter written in Javascript
http://www.showdownjs.com/
MIT License
14.23k stars 1.56k forks source link

Issue with code blocks inside of a list #832

Open JohnPeel opened 3 years ago

JohnPeel commented 3 years ago

Description: Code blocks inside of a list render weirdly with a code block inside a code block.

Input:

1. test:
    ```python
    # coding: utf-8
    class TestClass:
        def __init__():
            pass

        def test():
            pass

**Expected output:**
```html
<ol>
<li><p>test:</p>
<pre><code class="python language-python"># coding: utf-8
class TestClass:
    def __init__():
        pass

   def test():
    pass</code></pre></li></ol>

Actual Output:

<ol>
<li><p>test:</p>
<pre><code class="python language-python"># coding: utf-8
class TestClass:
    def __init__():
        pass<pre><code>def test():
    pass&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;</code></pre></ol>
JohnPeel commented 3 years ago

For more context,

I'm using github flavor, and my example program is below.

const content = `
1. test:
    \`\`\`python
    # coding: utf-8
    class TestClass:
        def __init__():
            pass

        def test():
            pass
    \`\`\``;

const showdown = require("showdown");
const converter = new showdown.Converter();
converter.setFlavor("github");

console.log(converter.makeHtml(content));
aote777 commented 2 years ago

大哥Have you solved this problem?

JohnPeel commented 2 years ago

大哥Have you solved this problem?

Nope. I don't remember exactly what I did, but I think I moved away from showdown.

aote777 commented 2 years ago

大哥Have you solved this problem?

Nope. I don't remember exactly what I did, but I think I moved away from showdown.

Thank you for your reply. I have found the reason for the problem

aote777 commented 2 years ago

核心问题就是pre里的<> 会被转义为字符实体。showdown只接受<>才会正常工作 The core problem is that < > in pre will be escaped into character entities. Showdown works only if it accepts < > https://github.com/aote777/anki-md-template

AvikChakraborty18 commented 2 months ago

大哥Have you solved this problem?

Nope. I don't remember exactly what I did, but I think I moved away from showdown.

Can you suggest an alternative to showdown?

JohnPeel commented 2 months ago

大哥Have you solved this problem?

Nope. I don't remember exactly what I did, but I think I moved away from showdown.

Can you suggest an alternative to showdown?

Oof, It's been so long, I don't actually remember what I moved to. Sorry.