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
291b5da2
Commit
291b5da2
authored
Jan 27, 2026
by
水玉婷
Browse files
feat:修复markdown 有序无序列表序号问题
parent
a7ebb5e5
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/views/components/utils/markdownTemplate.ts
View file @
291b5da2
...
...
@@ -195,8 +195,10 @@ export const parseMarkdown = (text: string): string => {
flushList
();
currentListType
=
'
ol
'
;
}
const
originalNumber
=
parseInt
(
orderedMatch
[
1
]);
const
content
=
parseMarkdown
(
orderedMatch
[
2
]);
listItems
.
push
(
`<li>
${
content
}
</li>`
);
// 使用原始序号作为value属性
listItems
.
push
(
`<li value="
${
originalNumber
}
">
${
content
}
</li>`
);
continue
;
}
...
...
@@ -306,7 +308,7 @@ export const isMarkdownBlock = (contentBlock: any): boolean => {
* @returns 是否是表格行
*/
export
const
isTableRow
=
(
text
:
string
):
boolean
=>
{
if
(
!
text
||
typeof
text
!==
'
string
'
)
{
if
(
!
text
||
typeof
text
!==
'
string
'
)
{
return
false
;
}
const
trimmedText
=
text
.
trim
();
...
...
@@ -607,10 +609,20 @@ class StreamingListProcessor {
// 处理每个列表项的内容
const
processedItems
=
this
.
listItems
.
map
((
item
,
index
)
=>
{
if
(
this
.
listType
===
'
ordered
'
)
{
// 有序列表:移除数字标记,保留内容,但保持正确的序号
const
content
=
item
.
replace
(
/^
\d
+
\.\s
+/
,
''
).
trim
();
const
processedContent
=
parseMarkdown
(
content
);
return
`<li value="
${
this
.
orderedListStartNumber
+
index
}
">
${
processedContent
}
</li>`
;
// 有序列表:提取数字标记,保留原始序号
const
orderedMatch
=
item
.
match
(
/^
(\d
+
)\.\s
+
(
.*
)
$/
);
if
(
orderedMatch
)
{
const
originalNumber
=
parseInt
(
orderedMatch
[
1
]);
const
content
=
orderedMatch
[
2
].
trim
();
const
processedContent
=
parseMarkdown
(
content
);
// 使用原始序号作为value属性,确保正确显示
return
`<li value="
${
originalNumber
}
">
${
processedContent
}
</li>`
;
}
else
{
// 如果没有匹配到数字标记,使用默认处理
const
content
=
item
.
replace
(
/^
\d
+
\.\s
+/
,
''
).
trim
();
const
processedContent
=
parseMarkdown
(
content
);
return
`<li>
${
processedContent
}
</li>`
;
}
}
else
{
// 无序列表:移除标记,保留内容
const
content
=
item
.
replace
(
/^
[
-*+
]\s
+/
,
''
).
trim
();
...
...
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