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

now it will only strip the very first tag that if it matches the title,
otherwise it gets turned into a h2 tag

fixes #1016
This commit is contained in:
Panagiotis Papadopoulos 2025-01-21 00:04:05 +01:00
parent e1c949aa10
commit 1de9bc7c6f

View File

@ -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>`;
}
});