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

chore: update

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