Skip to content

Build your personal knowledge base with Trilium Notes

fix(import/utils.handleH1): fix stripping of all <h1> tags that match title

Panagiotis Papadopoulos1de9bc7c6f95
diff --git a/src/services/import/utils.ts b/src/services/import/utils.ts
index ec4bbf35a6..2f4227f0a9 100644
--- a/src/services/import/utils.ts
+++ b/src/services/import/utils.ts
@@ -1,10 +1,14 @@
"use strict";
function handleH1(content: string, title: string) {
+ let isFirstH1Handled = false;
+
content = content.replace(/<h1[^>]*>([^<]*)<\/h1>/gi, (match, text) => {
- if (title.trim() === text.trim()) {
+ if (title.trim() === text.trim() && !isFirstH1Handled) {
+ isFirstH1Handled = true;
return ""; // remove whole H1 tag
} else {
+ isFirstH1Handled = true;
return `<h2>${text}</h2>`;
}
});