提交 be6fb6b6 authored 作者: 王鹏飞's avatar 王鹏飞

chore: update

上级 15a93038
......@@ -72,8 +72,8 @@
}
.message-content {
padding: 16px;
max-height: 300px;
overflow-y: auto;
// max-height: 300px;
// overflow-y: auto;
}
.message-tools {
padding: 16px;
......
......@@ -68,56 +68,51 @@ export function useSearch() {
return { messages, setMessages, isLoading, query: execute }
}
function parseInput(inputStr) {
const result = []
const regex = /^(#+)\s*(.+?)\s*(?=\n|【描述】|$)/g
const regex = /^(#+)\s*(.+?)\s*(?=\n|【描述】|$)/
const descriptionRegex = /【描述】(.*)/
const sections = []
const lines = inputStr.split('\n')
let level = 0
let currentTitle = ''
let currentChapter = ''
for (let line of lines) {
const lines = inputStr.split('\n')
lines.forEach((line) => {
const headerMatch = line.match(regex)
const descriptionMatch = line.match(descriptionRegex)
if (headerMatch) {
const header = headerMatch[0]
const newLevel = header.match(/^#+/)[0].length
const title = header.replace(/^#+\s*/, '').trim()
const header = headerMatch[1] // Capture the number of `#`
const title = headerMatch[2].trim() // Capture the title
const newLevel = header.length
// Handle level change
// Adjust section numbering based on levels
if (newLevel > level) {
// Increase section number for sub-levels
if (level === 0) {
sections.push(1)
} else {
sections.push(sections[sections.length - 1] + 1)
}
sections.push(1) // Add new sub-level
} else if (newLevel === level) {
sections[sections.length - 1] = sections[sections.length - 1] + 1
sections[sections.length - 1]++ // Increment current level
} else {
sections.splice(newLevel, sections.length - newLevel)
sections.splice(newLevel - 1) // Drop deeper levels
sections[sections.length - 1]++
}
// Generate chapter number
currentChapter = sections.join('.')
// Set level and title
level = newLevel
currentTitle = title
}
if (descriptionMatch) {
level = newLevel // Update current level
// Create chapter number and entry
const chapter = sections.join('.')
result.push({
title,
level,
desc: '', // Will be updated if a description follows
chapter: level === 1 ? '标题' : `第${chapter}章`,
})
} else if (descriptionMatch) {
const desc = descriptionMatch[1].trim()
result.push({ title: currentTitle, level, desc, chapter: `第${currentChapter}章` })
if (result.length > 0) {
result[result.length - 1].desc = desc // Attach description to the last entry
}
}
}
})
return result
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论