mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-09-01 12:27:41 +08:00
refactor(import/utils.handleH1): simplify handleH1
This commit is contained in:
parent
1de9bc7c6f
commit
2296d1a6ba
@ -3,16 +3,17 @@
|
|||||||
function handleH1(content: string, title: string) {
|
function handleH1(content: string, title: string) {
|
||||||
let isFirstH1Handled = false;
|
let isFirstH1Handled = false;
|
||||||
|
|
||||||
content = content.replace(/<h1[^>]*>([^<]*)<\/h1>/gi, (match, text) => {
|
return content.replace(/<h1[^>]*>([^<]*)<\/h1>/gi, (match, text) => {
|
||||||
if (title.trim() === text.trim() && !isFirstH1Handled) {
|
const convertedContent = `<h2>${text}</h2>`;
|
||||||
|
|
||||||
|
// strip away very first found h1 tag, if it matches the title
|
||||||
|
if (!isFirstH1Handled) {
|
||||||
isFirstH1Handled = true;
|
isFirstH1Handled = true;
|
||||||
return ""; // remove whole H1 tag
|
return title.trim() === text.trim() ? "" : convertedContent;
|
||||||
} else {
|
|
||||||
isFirstH1Handled = true;
|
|
||||||
return `<h2>${text}</h2>`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return convertedContent;
|
||||||
});
|
});
|
||||||
return content;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function extractHtmlTitle(content: string): string | null {
|
function extractHtmlTitle(content: string): string | null {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user