fix(template): make anki equation render normal, first line no <pre>

When there's space leading the first line, it'll be parsed to be a codeblock. use `.trim` to prevent this.
Make html render to `true` in case of anki equation needed.
This commit is contained in:
Saphir Gu 2024-03-09 21:07:40 +08:00 committed by GitHub
parent 6ef27ee8ff
commit 9bceaad978
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 2 additions and 2 deletions

View File

@ -141,7 +141,7 @@ console.log('hello world')
// 解析入口main方法 // 解析入口main方法
var parseMarkDownFn = () => { var parseMarkDownFn = () => {
const md = markdownit({ const md = markdownit({
html: false, html: true, // 若为 false 将导致 anki 自带的公式渲染失效。
linkify: true, linkify: true,
typographer: true, typographer: true,
breaks: true, breaks: true,
@ -158,7 +158,7 @@ console.log('hello world')
document.querySelectorAll('.md-content').forEach((div, index) => { document.querySelectorAll('.md-content').forEach((div, index) => {
console.log('查找到的容器元素', div) console.log('查找到的容器元素', div)
// 需要去除首尾空格 不然markdown-it会解析错误 // 需要去除首尾空格 不然markdown-it会解析错误
var text = unescapeHTMLEntities(div.innerHTML) var text = unescapeHTMLEntities(div.innerHTML).trim()
console.log('text', text) console.log('text', text)
// 清除br标签 // 清除br标签
text = clearBR(text) text = clearBR(text)