Commit 291b5da2 authored by 水玉婷's avatar 水玉婷
Browse files

feat:修复markdown 有序无序列表序号问题

parent a7ebb5e5
...@@ -195,8 +195,10 @@ export const parseMarkdown = (text: string): string => { ...@@ -195,8 +195,10 @@ export const parseMarkdown = (text: string): string => {
flushList(); flushList();
currentListType = 'ol'; currentListType = 'ol';
} }
const originalNumber = parseInt(orderedMatch[1]);
const content = parseMarkdown(orderedMatch[2]); const content = parseMarkdown(orderedMatch[2]);
listItems.push(`<li>${content}</li>`); // 使用原始序号作为value属性
listItems.push(`<li value="${originalNumber}">${content}</li>`);
continue; continue;
} }
...@@ -306,7 +308,7 @@ export const isMarkdownBlock = (contentBlock: any): boolean => { ...@@ -306,7 +308,7 @@ export const isMarkdownBlock = (contentBlock: any): boolean => {
* @returns 是否是表格行 * @returns 是否是表格行
*/ */
export const isTableRow = (text: string): boolean => { export const isTableRow = (text: string): boolean => {
if (!text || typeof text !== 'string') { if (!text || typeof text !== 'string') {
return false; return false;
} }
const trimmedText = text.trim(); const trimmedText = text.trim();
...@@ -607,10 +609,20 @@ class StreamingListProcessor { ...@@ -607,10 +609,20 @@ class StreamingListProcessor {
// 处理每个列表项的内容 // 处理每个列表项的内容
const processedItems = this.listItems.map((item, index) => { const processedItems = this.listItems.map((item, index) => {
if (this.listType === 'ordered') { if (this.listType === 'ordered') {
// 有序列表:移除数字标记,保留内容,但保持正确的序号 // 有序列表:提取数字标记,保留原始序号
const content = item.replace(/^\d+\.\s+/, '').trim(); const orderedMatch = item.match(/^(\d+)\.\s+(.*)$/);
const processedContent = parseMarkdown(content); if (orderedMatch) {
return `<li value="${this.orderedListStartNumber + index}">${processedContent}</li>`; 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 { } else {
// 无序列表:移除标记,保留内容 // 无序列表:移除标记,保留内容
const content = item.replace(/^[-*+]\s+/, '').trim(); const content = item.replace(/^[-*+]\s+/, '').trim();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment