fix new note name with markdown title like '####'

This commit is contained in:
duanfuxiang 2025-04-08 14:05:51 +08:00
parent 108a86d6c4
commit 5118b3e3a7
2 changed files with 6 additions and 3 deletions

View File

@ -45,8 +45,13 @@ function CreateNewFileButton({ message }: { message: string }) {
const app = useApp()
const [created, setCreated] = useState(false)
const cleanMarkdownTitle = (text: string): string => {
// 移除所有 # 开头的标题标记
return text.replace(/^#+\s*/g, '');
}
const handleCreate = async () => {
const firstLine = message.trimStart().split('\n')[0].trim().replace(/[\\\/:]/g, '');
const firstLine = cleanMarkdownTitle(message.trimStart().split('\n')[0].trim()).replace(/[\\/:]/g, '');
const filename = firstLine.slice(0, 200) + (firstLine.length > 200 ? '...' : '') || 'untitled';
await app.vault.create(`/${filename}.md`, message)
await app.workspace.openLinkText(filename, 'split', true)

View File

@ -172,8 +172,6 @@ export class PromptGenerator {
let filesSearchMethod = this.settings.filesSearchMethod
if (filesSearchMethod === 'auto' && this.settings.embeddingModelId && this.settings.embeddingModelId !== '') {
filesSearchMethod = 'semantic'
} else {
filesSearchMethod = 'regex'
}
const userLanguage = getFullLanguageName(getLanguage())