UNPKG

mongodb-rag-core

Version:

Common elements used by MongoDB Chatbot Framework components.

29 lines (27 loc) 904 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.extractMarkdownH1 = void 0; /** Extract the first H1 from a Markdown string @param mdContent - some Markdown content @returns page H1 `string` if it exists, otherwise `null` @example ```ts const mdContent = "# My Page Title"; const pageTitle = extractMarkdownH1(mdContent); console.log(pageTitle); // "My Page Title" const noTitleMdContent = "content without a h1"; const noTitle = extractMarkdownH1(noTitleMdContent); console.log(noTitle); // null ``` */ function extractMarkdownH1(mdContent) { const h1Regex = /^#\s(.+)$/gm; const matches = mdContent.match(h1Regex); if (matches && matches.length > 0) { const title = matches[0].replace("# ", ""); return title; } } exports.extractMarkdownH1 = extractMarkdownH1; //# sourceMappingURL=extractMarkdownH1.js.map