Peng-YM / LeetCode-Anki

Beat LeetCode with the Power of Anki.
GNU General Public License v3.0
226 stars 31 forks source link

solution中的图片显示出错, 代码样式出错 #16

Open guxiyuesi opened 5 months ago

guxiyuesi commented 5 months ago

os: win10 python: 3.8 chromedriver: 125 anki: QT5

工程为默认位置: [DB_CN] path = ./data_cn debug = False

[Anki_CN] front = ./templates/front-side.html back = ./templates/back-side.html css = ./templates/style.css output = ./data_cn/LeetCode.apkg


问题描述如下:

导入anki后, 在问题页中, 图片可以正常显示: image

但回答页中, 图片不显示, 行内公式不渲染, 代码格式化不正确: image

image

windli93 commented 2 months ago

` def markdown_to_html(content: str):

replace the math symbol "$x$" to "[$]x[/$]" to make it compatible with mathjax

content = re.sub(
    pattern=r"\$(.*?)\$",
    repl=r"[$]\1[/$]",
    string=content
)

# Only matches the contents of the Markdown image format ![]() enclosed by angle brackets < and >, without affecting other contents
content = re.sub(
    pattern=r'<(!\[.*?\]\(.*?\))>',
    repl=r'\1',
    string=content
)

#Add line breaks before and after code blocks
content = re.sub(
    pattern=r'(```\w*)',
    repl=r'\n\1',
    string=content
)
content = re.sub(
    pattern=r'(\w*```)',
    repl=r'\1\n',
    string=content
)

# also need to load the mathjax and toc extensions
return markdown(content, extensions=['mdx_math', 'toc', 'fenced_code', 'tables'])

` 试一下下载源码,然后替换这个方法的内容,只能解决你的部分问题,不能解决全部问题。