Skip to content

Build your personal knowledge base with Trilium Notes

refactor(import/utils.handleH1): simplify handleH1

Panagiotis Papadopoulos2296d1a6ba35
diff --git a/src/services/import/utils.ts b/src/services/import/utils.ts
index 2f4227f0a9..41c42ae221 100644
--- a/src/services/import/utils.ts
+++ b/src/services/import/utils.ts
@@ -3,16 +3,17 @@
function handleH1(content: string, title: string) {
let isFirstH1Handled = false;
- content = content.replace(/<h1[^>]*>([^<]*)<\/h1>/gi, (match, text) => {
- if (title.trim() === text.trim() && !isFirstH1Handled) {
- isFirstH1Handled = true;
- return ""; // remove whole H1 tag
- } else {
+ return content.replace(/<h1[^>]*>([^<]*)<\/h1>/gi, (match, text) => {
+ const convertedContent = `<h2>${text}</h2>`;
+
+ // strip away very first found h1 tag, if it matches the title
+ if (!isFirstH1Handled) {
isFirstH1Handled = true;
- return `<h2>${text}</h2>`;
+ return title.trim() === text.trim() ? "" : convertedContent;
}
+
+ return convertedContent;
});
- return content;
}
function extractHtmlTitle(content: string): string | null {