fix: avoid duplicate H1 when template begins with one
`buildNoteBody` unconditionally prepended an empty `# ` placeholder whenever `initialEmptyHeading` was true, which collided with templates whose first line is already an H1 (e.g. a Weekly Notes type whose template starts with `# Woche 2026.21`). The placeholder is now suppressed when the template's first non-whitespace line is `# `. Fixes: https://github.com/refactoringhq/tolaria/issues/736 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -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', () => {
|
||||
|
||||
@@ -117,7 +117,8 @@ export interface TypeInstanceDefault {
|
||||
}
|
||||
|
||||
function buildNoteBody({ template, initialEmptyHeading }: Pick<NoteContentParams, 'template' | 'initialEmptyHeading'>): 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}` : ''
|
||||
|
||||
Reference in New Issue
Block a user