diff --git a/src/services/import/single.ts b/src/services/import/single.ts
index 18b22329f..4f50a686d 100644
--- a/src/services/import/single.ts
+++ b/src/services/import/single.ts
@@ -150,15 +150,16 @@ function importMarkdown(taskContext: TaskContext, file: File, parentNote: BNote)
function importHtml(taskContext: TaskContext, file: File, parentNote: BNote) {
let content = file.buffer.toString("utf-8");
-
+
+ // Try to get title from HTML first, fall back to filename
+ // We do this before sanitization since that turns all
s into
+ const htmlTitle = importUtils.extractHtmlTitle(content);
+ const title = htmlTitle || utils.getNoteTitle(file.originalname, !!taskContext.data?.replaceUnderscoresWithSpaces);
+
if (taskContext?.data?.safeImport) {
content = htmlSanitizer.sanitize(content);
}
-
- // Try to get title from HTML first, fall back to filename
- const htmlTitle = importUtils.extractHtmlTitle(content);
- const title = htmlTitle || utils.getNoteTitle(file.originalname, !!taskContext.data?.replaceUnderscoresWithSpaces);
-
+
content = importUtils.handleH1(content, title);
const {note} = noteService.createNewNote({