import { getIcon } from 'obsidian' import { useEffect, useRef } from 'react' import { t } from '../../lang/helpers' import { PreviewViewState } from '../../PreviewView' export default function PreviewViewRoot({ state, close, }: { state: PreviewViewState close: () => void }) { const closeIcon = getIcon('x') const contentRef = useRef(null) // 显示原始文本内容 useEffect(() => { if (contentRef.current && state.content) { // 清空现有内容 contentRef.current.empty() // 创建预格式化文本元素 const preElement = document.createElement('pre') preElement.className = 'infio-raw-content' preElement.textContent = state.content // 添加到容器 contentRef.current.appendChild(preElement) } }, [state.content, state.file]) return (
{state.title || (state.file ? state.file.name : 'Markdown Preview')}
{state.title || (state.file ? state.file.name.replace(/\.[^/.]+$/, '') : '')}
) }