mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-08-10 10:22:29 +08:00
23 lines
573 B
TypeScript
23 lines
573 B
TypeScript
"use strict";
|
|
|
|
function handleH1(content: string, title: string) {
|
|
content = content.replace(/<h1[^>]*>([^<]*)<\/h1>/gi, (match, text) => {
|
|
if (title.trim() === text.trim()) {
|
|
return ""; // remove whole H1 tag
|
|
} else {
|
|
return `<h2>${text}</h2>`;
|
|
}
|
|
});
|
|
return content;
|
|
}
|
|
|
|
function extractHtmlTitle(content: string): string | null {
|
|
const titleMatch = content.match(/<title[^>]*>([^<]+)<\/title>/i);
|
|
return titleMatch ? titleMatch[1].trim() : null;
|
|
}
|
|
|
|
export default {
|
|
handleH1,
|
|
extractHtmlTitle
|
|
};
|