feat: 修改为服务端渲染、解决跳转问题

This commit is contained in:
Tim
2025-08-08 13:22:42 +08:00
parent 6554e66a4e
commit 65ae660486
4 changed files with 36 additions and 28 deletions

View File

@@ -86,9 +86,15 @@ export function handleMarkdownClick(e) {
export function stripMarkdown(text) {
const html = md.render(text || '')
const el = document.createElement('div')
el.innerHTML = html
return el.textContent || el.innerText || ''
// SSR 环境下没有 document
if (typeof window === 'undefined') {
// 用正则去除 HTML 标签
return html.replace(/<[^>]+>/g, '').replace(/\s+/g, ' ').trim()
} else {
const el = document.createElement('div')
el.innerHTML = html
return el.textContent || el.innerText || ''
}
}
export function stripMarkdownLength(text, length) {