mirror of
https://github.com/zadam/trilium.git
synced 2025-12-27 09:44:23 +01:00
31 lines
821 B
TypeScript
31 lines
821 B
TypeScript
"use strict";
|
|
|
|
import { unescapeHtml } from "../utils.js";
|
|
|
|
function handleH1(content: string, title: string) {
|
|
let isFirstH1Handled = false;
|
|
|
|
return content.replace(/<h1[^>]*>([^<]*)<\/h1>/gi, (match, text) => {
|
|
text = unescapeHtml(text);
|
|
const convertedContent = `<h2>${text}</h2>`;
|
|
|
|
// strip away very first found h1 tag, if it matches the title
|
|
if (!isFirstH1Handled) {
|
|
isFirstH1Handled = true;
|
|
return title.trim() === text.trim() ? "" : convertedContent;
|
|
}
|
|
|
|
return convertedContent;
|
|
});
|
|
}
|
|
|
|
function extractHtmlTitle(content: string): string | null {
|
|
const titleMatch = content.match(/<title[^>]*>([^<]+)<\/title>/i);
|
|
return titleMatch ? titleMatch[1].trim() : null;
|
|
}
|
|
|
|
export default {
|
|
handleH1,
|
|
extractHtmlTitle
|
|
};
|