import { wrapMinimal } from '../utils.js';
export function parseComMarkdown(codigo) {
    const headings = Array.from(codigo.matchAll(/^(#{1,6})\s+(.+)$/gm)).map(m => ({
        level: m[1].length,
        text: m[2].trim()
    }));
    const codeBlocks = Array.from(codigo.matchAll(/```(\w*)\n([\s\S]*?)```/g)).map(m => ({
        lang: m[1] || 'text',
        size: m[2].length,
        lines: m[2].split('\n').length
    }));
    const links = Array.from(codigo.matchAll(/(?<!!)\[([^\]]+)\]\(([^)]+)\)/g)).map(m => ({
        text: m[1],
        url: m[2]
    }));
    const images = Array.from(codigo.matchAll(/!\[([^\]]*)\]\(([^)]+)\)/g)).map(m => ({
        alt: m[1],
        url: m[2]
    }));
    const bold = (codigo.match(/\*\*[^*]+\*\*/g) || []).length;
    const italic = (codigo.match(/(?<!\*)\*[^*\n]+\*(?!\*)/g) || []).length;
    const lists = {
        ordered: (codigo.match(/^\s*\d+\.\s+/gm) || []).length,
        unordered: (codigo.match(/^\s*[-*+]\s+/gm) || []).length
    };
    const blockquotes = (codigo.match(/^>\s+/gm) || []).length;
    const tables = (codigo.match(/^\|.+\|\s*$/gm) || []).length;
    const horizontalRules = (codigo.match(/^---$/gm) || []).length;
    const words = codigo.replace(/```[\s\S]*?```/g, '').replace(/#{1,6}\s+/g, '').replace(/[\[\]()`*_]/g, '').split(/\s+/).filter(Boolean).length;
    const chars = codigo.length;
    const frontmatter = codigo.startsWith('---') ? (() => {
        const end = codigo.indexOf('---', 3);
        if (end > 0)
            return codigo.slice(3, end).trim();
        return null;
    })() : null;
    return wrapMinimal('markdown', {
        headings,
        headingCount: headings.length,
        codeBlocks,
        codeBlockCount: codeBlocks.length,
        links,
        images,
        bold,
        italic,
        lists,
        blockquotes,
        tables,
        horizontalRules,
        words,
        chars,
        frontmatter,
        readingTimeMinutes: Math.ceil(words / 200)
    });
}
//# sourceMappingURL=markdown.js.map