import { parseYaml } from "../../utils/parseYaml.mjs";

//#region ../packages/@intlayer/core/dist/esm/transpiler/markdown/getMarkdownMetadata.mjs
const getMarkdownMetadata = (markdown) => {
	try {
		const lines = markdown.split(/\r?\n/);
		const firstNonEmptyLine = lines.find((line) => line.trim() !== "");
		if (!firstNonEmptyLine || firstNonEmptyLine.trim() !== "---") return {};
		let metadataEndIndex = -1;
		for (let i = 1; i < lines.length; i++) if (lines[i].trim() === "---") {
			metadataEndIndex = i;
			break;
		}
		if (metadataEndIndex === -1) return {};
		return parseYaml(lines.slice(1, metadataEndIndex).join("\n")) ?? {};
	} catch (_e) {
		return {};
	}
};

//#endregion
export { getMarkdownMetadata };
//# sourceMappingURL=getMarkdownMetadata.mjs.map