Skip to content

出bug了。showdown.js无法渲染代码块 #293

@yang10560

Description

@yang10560

源代码

// ==UserScript==
// @name         showdown
// @namespace    https://bbs.tampermonkey.net.cn/
// @version      0.1.0
// @description  try to take over the world!
// @require    https://cdn.bootcdn.net/ajax/libs/showdown/2.1.0/showdown.min.js
// @author       You
// @match        *://*/*
// ==/UserScript==


let converter = new showdown.Converter();
let md = `\`\`\`python
def selection_sort(arr):
    n = len(arr)
    for i in range(n):
        min_idx = i
        # 遍历剩余元素寻找最小元素
        for j in range(i+1, n):
            if arr[j] < arr[min_idx]:
                min_idx = j
        # 将找到的最小元素与当前位置的元素交换
        if min_idx != i:
            arr[i], arr[min_idx] = arr[min_idx], arr[i]
    return arr

# 测试选择排序
my_list = [64, 25, 12, 22, 11]
print("原始列表:", my_list)
my_list = selection_sort(my_list)
print("排序后的列表:", my_list)
\`\`\``
console.log(converter.makeHtml(md))

含有代码块的markdown代码,在tampermonkey中测试正常。在脚本猫中测试异常

脚本猫报错:

showdown.user.js:5 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'codeblock')
    at showdown.user.js:5:60269
    at showdown.user.js:5:42248
    at x.Converter.makeHtml (showdown.user.js:5:36809)
    at showdown.user.js:39:23
    at window.KcZwZnFDXGHXbbcK (showdown.user.js:42:3)
    at Va.exec (<anonymous>:3:375608)
    at Ga.execScript (<anonymous>:3:376582)
    at set (<anonymous>:3:375988)
    at showdown.user.js:1:27

tampermonkey中正常输出

<pre><code class="python language-python">def selection_sort(arr):
    n = len(arr)
    for i in range(n):
        min_idx = i
        # 遍历剩余元素寻找最小元素
        for j in range(i+1, n):
            if arr[j] &lt; arr[min_idx]:
                min_idx = j
        # 将找到的最小元素与当前位置的元素交换
        if min_idx != i:
            arr[i], arr[min_idx] = arr[min_idx], arr[i]
    return arr

# 测试选择排序
my_list = [64, 25, 12, 22, 11]
print("原始列表:", my_list)
my_list = selection_sort(my_list)
print("排序后的列表:", my_list)
</code></pre>

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions