showdown icon indicating copy to clipboard operation
showdown copied to clipboard

Issue with code blocks inside of a list

Open JohnPeel opened this issue 5 years ago • 7 comments

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:

<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 avatar Oct 06 '20 20:10 JohnPeel

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));

JohnPeel avatar Oct 06 '20 20:10 JohnPeel

大哥Have you solved this problem?

aote777 avatar Nov 22 '21 15:11 aote777

大哥Have you solved this problem?

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

JohnPeel avatar Nov 23 '21 03:11 JohnPeel

大哥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 avatar Nov 23 '21 03:11 aote777

核心问题就是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

aote777 avatar Nov 23 '21 03:11 aote777