diff --git a/src/hooks/useNoteCreation.test.ts b/src/hooks/useNoteCreation.test.ts index 1616b948..5994ebee 100644 --- a/src/hooks/useNoteCreation.test.ts +++ b/src/hooks/useNoteCreation.test.ts @@ -148,6 +148,28 @@ describe('buildNoteContent', () => { }) expect(content).toBe('---\ntype: Project\nstatus: Active\n---\n\n# \n\n## Objective\n\n') }) + + it('skips the empty H1 when the template already starts with one', () => { + const content = buildNoteContent({ + title: null, + type: 'Weekly', + status: null, + template: '# Woche 2026.21\n\nWochennotiz\n', + initialEmptyHeading: true, + }) + expect(content).toBe('---\ntype: Weekly\n---\n\n# Woche 2026.21\n\nWochennotiz\n') + }) + + it('skips the empty H1 when the template starts with an H1 after leading whitespace', () => { + const content = buildNoteContent({ + title: null, + type: 'Weekly', + status: null, + template: '\n\n# Woche 2026.21\n', + initialEmptyHeading: true, + }) + expect(content).toBe('---\ntype: Weekly\n---\n\n\n\n# Woche 2026.21\n') + }) }) describe('resolveNewNote', () => { diff --git a/src/hooks/useNoteCreation.ts b/src/hooks/useNoteCreation.ts index be023ff7..07ced057 100644 --- a/src/hooks/useNoteCreation.ts +++ b/src/hooks/useNoteCreation.ts @@ -117,7 +117,8 @@ export interface TypeInstanceDefault { } function buildNoteBody({ template, initialEmptyHeading }: Pick): string { - if (initialEmptyHeading) { + const templateStartsWithH1 = template?.trimStart().startsWith('# ') ?? false + if (initialEmptyHeading && !templateStartsWithH1) { return template ? `\n# \n\n${template}` : '\n# \n\n' } return template ? `\n${template}` : ''