Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
水玉婷
ai-wechat
Commits
eaf62b20
Commit
eaf62b20
authored
Dec 05, 2025
by
水玉婷
Browse files
feat:修复md中有序列表后图片不渲染bug
parent
f5683e1f
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/views/components/utils/markdownTemplate.ts
View file @
eaf62b20
...
@@ -346,7 +346,7 @@ class StreamingTableProcessor {
...
@@ -346,7 +346,7 @@ class StreamingTableProcessor {
// 检查是否是表格行
// 检查是否是表格行
if
(
isTableRow
(
trimmedText
))
{
if
(
isTableRow
(
trimmedText
))
{
if
(
!
this
.
isInTable
)
{
if
(
!
this
.
isInTable
)
{
// 开始新的表格
// 开始新的表格
this
.
isInTable
=
true
;
this
.
isInTable
=
true
;
this
.
tableData
=
[
trimmedText
];
this
.
tableData
=
[
trimmedText
];
return
null
;
// 表格开始,不立即渲染
return
null
;
// 表格开始,不立即渲染
...
@@ -639,9 +639,10 @@ const streamingListProcessor = new StreamingListProcessor();
...
@@ -639,9 +639,10 @@ const streamingListProcessor = new StreamingListProcessor();
* @returns 处理后的HTML内容
* @returns 处理后的HTML内容
*/
*/
export
const
processStreamingMarkdown
=
(
text
:
string
):
string
=>
{
export
const
processStreamingMarkdown
=
(
text
:
string
):
string
=>
{
// 清理HTML标签,防止XSS攻击
// 清理
危险的
HTML标签,防止XSS攻击
,但保留图片和必要的容器标签
text
=
text
.
replace
(
/<script
\b[^
<
]
*
(?:(?!
<
\/
script>
)
<
[^
<
]
*
)
*<
\/
script>/gi
,
''
);
text
=
text
.
replace
(
/<script
\b[^
<
]
*
(?:(?!
<
\/
script>
)
<
[^
<
]
*
)
*<
\/
script>/gi
,
''
);
text
=
text
.
replace
(
/<
[^
>
]
*>/g
,
''
);
// 移除其他危险标签,但保留img、div、span等安全标签
text
=
text
.
replace
(
/<
(?!\/?(
img|div|span|p|br|ol|ul|li|table|tr|td|th|blockquote|pre|code|strong|em|a|h
[
1-6
])(\s
+
[^
>
]
*
)?
>
)[^
>
]
*>/gi
,
''
);
// 使用流式列表处理器处理文本
// 使用流式列表处理器处理文本
const
listResult
=
streamingListProcessor
.
processText
(
text
);
const
listResult
=
streamingListProcessor
.
processText
(
text
);
...
@@ -651,8 +652,15 @@ export const processStreamingMarkdown = (text: string): string => {
...
@@ -651,8 +652,15 @@ export const processStreamingMarkdown = (text: string): string => {
return
''
;
return
''
;
}
}
// 如果列表处理器返回了完整列表,
直接返回
// 如果列表处理器返回了完整列表,
需要检查是否有剩余内容需要处理
if
(
listResult
&&
(
listResult
.
includes
(
'
<ol>
'
)
||
listResult
.
includes
(
'
<ul>
'
)))
{
if
(
listResult
&&
(
listResult
.
includes
(
'
<ol>
'
)
||
listResult
.
includes
(
'
<ul>
'
)))
{
// 检查是否有非列表内容需要处理
const
remainingText
=
text
.
trim
();
if
(
remainingText
&&
!
isListItem
(
remainingText
))
{
// 有剩余的非列表内容(如图片),需要继续处理
const
remainingResult
=
parseMarkdown
(
remainingText
);
return
listResult
+
remainingResult
;
}
return
listResult
;
return
listResult
;
}
}
...
...
src/views/components/utils/sseService.ts
View file @
eaf62b20
...
@@ -63,7 +63,6 @@ export class SSEService {
...
@@ -63,7 +63,6 @@ export class SSEService {
this
.
eventSource
.
addEventListener
(
'
message
'
,
(
event
)
=>
{
this
.
eventSource
.
addEventListener
(
'
message
'
,
(
event
)
=>
{
try
{
try
{
console
.
log
(
'
Received message:
'
,
event
);
const
data
:
SSEData
=
JSON
.
parse
(
event
.
data
);
const
data
:
SSEData
=
JSON
.
parse
(
event
.
data
);
// 只传递原始数据,模板处理在外部进行
// 只传递原始数据,模板处理在外部进行
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment