mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-09-01 20:32:19 +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) {
|
||||
let isFirstH1Handled = false;
|
||||
|
||||
content = content.replace(/<h1[^>]*>([^<]*)<\/h1>/gi, (match, text) => {
|
||||
if (title.trim() === text.trim() && !isFirstH1Handled) {
|
||||
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 ""; // remove whole H1 tag
|
||||
} else {
|
||||
isFirstH1Handled = true;
|
||||
return `<h2>${text}</h2>`;
|
||||
return title.trim() === text.trim() ? "" : convertedContent;
|
||||
}
|
||||
|
||||
return convertedContent;
|
||||
});
|
||||
return content;
|
||||
}
|
||||
|
||||
function extractHtmlTitle(content: string): string | null {
|
||||
|
Loading…
x
Reference in New Issue
Block a user