Skip to content

Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.

fix(frontend): add null checks for markdown code block text parameter

chenrui78daecd346c47
diff --git a/frontend/src/components/doc-content.vue b/frontend/src/components/doc-content.vue
index bb0a6131d..04e77adfd 100644
--- a/frontend/src/components/doc-content.vue
+++ b/frontend/src/components/doc-content.vue
@@ -186,6 +186,11 @@ renderer.image = function ({href, title, text}) {
// 自定义代码块渲染器,只显示语言标签
renderer.code = function ({text, lang}) {
+ // 空值校验:防止 text 为 undefined 或 null
+ if (!text || typeof text !== 'string') {
+ text = '';
+ }
+
// Mermaid 图表处理
if (lang === 'mermaid') {
// 生成唯一ID
diff --git a/frontend/src/components/document-preview.vue b/frontend/src/components/document-preview.vue
index b06a8a8ae..6e4b84e06 100644
--- a/frontend/src/components/document-preview.vue
+++ b/frontend/src/components/document-preview.vue
@@ -192,12 +192,24 @@ async function renderText(blob: Blob, fileType: string) {
async function renderMarkdown(blob: Blob) {
const { marked } = await import('marked');
const text = await blob.text();
+
+ // 校验文本内容是否有效
+ if (!text || typeof text !== 'string') {
+ markdownHtml.value = '<p style="color: var(--td-text-color-disabled); text-align: center; padding: 20px;">文档内容为空</p>';
+ return;
+ }
+
marked.use({
breaks: true,
gfm: true,
});
const renderer = new marked.Renderer();
renderer.code = function ({text, lang}) {
+ // 空值校验:防止 text 为 undefined 或 null
+ if (!text || typeof text !== 'string') {
+ text = '';
+ }
+
let highlighted = '';
if (lang && hljs.getLanguage(lang)) {
try { highlighted = hljs.highlight(text, { language: lang }).value; }