mirror of
https://github.com/nagisa77/OpenIsle.git
synced 2026-05-08 03:37:28 +08:00
feat: 修改为服务端渲染、解决跳转问题
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user