"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.serializeMarkdown = serializeMarkdown;
exports.parseMarkdown = parseMarkdown;
const yaml_1 = require("yaml");
function serializeMarkdown(frontmatter, body) {
    const yamlStr = (0, yaml_1.stringify)(frontmatter, { lineWidth: 0 }).trimEnd();
    return `---\n${yamlStr}\n---\n\n${body}\n`;
}
function parseMarkdown(raw) {
    const normalized = raw.replace(/\r\n/g, '\n');
    const match = normalized.match(/^---\n([\s\S]*?)\n---\n\n?([\s\S]*)$/);
    if (!match)
        return { frontmatter: {}, body: normalized };
    const frontmatter = (0, yaml_1.parse)(match[1], { maxAliasCount: 10 }) ?? {};
    const body = match[2].replace(/\n$/, '');
    return { frontmatter, body };
}
