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iB,IAAiC,EAAA;AAChE,EAAA,MAAM,GAAM,GAAA,iBAAA,IAAI,IAAK,EAAA,EAAE,WAAY,EAAA;AACnC,EAAI,IAAA,CAAC,KAAK,OAAS,EAAA;AACjB,IAAA,IAAA,CAAK,OAAU,GAAA,GAAA;AAAA;AAEjB,EAAA,IAAA,CAAK,OAAU,GAAA,GAAA;AACjB","file":"doc-sections.cjs","sourcesContent":["import { load, dump } from 'js-yaml';\n\nexport interface DocSections {\n  frontmatter: string;\n  frontmatterObj: Record<string, any>;\n  content: string;\n  xml: string;\n}\n\nconst YAML_DUMP_OPTIONS = {\n  lineWidth: -1,\n  noRefs: true,\n  sortKeys: true\n};\n\n// Regex to match XML blocks at the bottom of the file\nconst XML_CONTAINER_REGEX = /<XML>([\\s\\S]*?)<\\/XML>/gi;\n\n// Regex to match frontmatter section\nconst FRONTMATTER_REGEX = /^---\\n([\\s\\S]*?)\\n---\\n([\\s\\S]*)$/;\n\nexport function parseDocSections(fileString: string): DocSections {\n  // First try to extract frontmatter\n  const frontmatterMatch = fileString.match(FRONTMATTER_REGEX);\n  let frontmatterRaw = '';\n  let frontmatterObj: Record<string, any> = {};\n  let contentSection = fileString;\n  let xmlSection = '';\n\n  if (!frontmatterMatch) {\n    // No frontmatter, look for XML blocks in the entire file\n    const xmlMatches = [...contentSection.matchAll(XML_CONTAINER_REGEX)];\n    if (xmlMatches.length > 0) {\n      // Combine all XML content\n      xmlSection = xmlMatches.map(m => m[1].trim()).join('\\n\\n');\n      // Remove all XML blocks from content\n      contentSection = contentSection.replace(XML_CONTAINER_REGEX, '').trim();\n    } else {\n      contentSection = fileString.trim();\n    }\n  } else {\n    frontmatterRaw = frontmatterMatch[1];\n    const rest = frontmatterMatch[2];\n\n    try {\n      frontmatterObj = load(frontmatterRaw) || {};\n    } catch {\n      // If invalid YAML, frontmatterObj remains {}\n    }\n\n    // Look for XML blocks in the rest of the content\n    const xmlMatches = [...rest.matchAll(XML_CONTAINER_REGEX)];\n    if (xmlMatches.length > 0) {\n      // Combine all XML content\n      xmlSection = xmlMatches.map(m => m[1].trim()).join('\\n\\n');\n      // Remove all XML blocks from content\n      contentSection = rest.replace(XML_CONTAINER_REGEX, '').trim();\n    } else {\n      contentSection = rest.trim();\n    }\n  }\n\n  return {\n    frontmatter: frontmatterRaw.trim(),\n    frontmatterObj,\n    content: contentSection,\n    xml: xmlSection\n  };\n}\n\nexport function rebuildDocSections(sections: DocSections): string {\n  const frontmatterStr = dump(sections.frontmatterObj, YAML_DUMP_OPTIONS);\n  let result = '';\n\n  // Add frontmatter if we have any frontmatter object properties\n  if (Object.keys(sections.frontmatterObj).length > 0) {\n    result += `---\\n${frontmatterStr}---\\n\\n`;\n  }\n\n  // Add content if present\n  if (sections.content) {\n    result += `${sections.content.trim()}\\n`;\n    // Only add extra newline if we have XML content\n    if (sections.xml) {\n      result += '\\n';\n    }\n  }\n\n  // Add XML section if present\n  if (sections.xml) {\n    result += `<XML>\\n${sections.xml.trim()}\\n</XML>\\n`;\n  }\n\n  return result;\n}\n\nexport function ensureTimestamps(meta: Record<string, any>): void {\n  const now = new Date().toISOString();\n  if (!meta.created) {\n    meta.created = now;\n  }\n  meta.updated = now;\n} "]}