"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const globals_1 = require("@jest/globals");
const MarkdownIt = require("markdown-it");
const frontmatter_1 = require("./frontmatter");
const createMarkdownIt = () => {
    const markdownIt = new MarkdownIt();
    markdownIt.use(frontmatter_1.default.plugin, {});
    return markdownIt;
};
(0, globals_1.describe)('frontmatter', () => {
    (0, globals_1.test)('should render a basic frontmatter block', () => {
        const md = createMarkdownIt();
        const input = '---\ntitle: Test\n---\n\n# Heading';
        const output = md.render(input);
        (0, globals_1.expect)(output).toContain('joplin-editable');
        (0, globals_1.expect)(output).toContain('joplin-frontmatter');
        (0, globals_1.expect)(output).toContain('joplin-source');
        (0, globals_1.expect)(output).toContain('data-joplin-language="frontmatter"');
        (0, globals_1.expect)(output).toContain('title: Test');
        (0, globals_1.expect)(output).toContain('<h1>Heading</h1>');
    });
    (0, globals_1.test)('should render frontmatter with multiple properties', () => {
        const md = createMarkdownIt();
        const input = '---\ntitle: My Document\ndate: 2024-01-01\ntags: [one, two]\n---\n\nContent here.';
        const output = md.render(input);
        (0, globals_1.expect)(output).toContain('joplin-frontmatter');
        (0, globals_1.expect)(output).toContain('title: My Document');
        (0, globals_1.expect)(output).toContain('date: 2024-01-01');
        (0, globals_1.expect)(output).toContain('tags: [one, two]');
        (0, globals_1.expect)(output).toContain('<p>Content here.</p>');
    });
    (0, globals_1.test)('should not parse frontmatter if not at document start', () => {
        const md = createMarkdownIt();
        const input = 'Some text\n\n---\ntitle: Test\n---';
        const output = md.render(input);
        // Should not contain frontmatter class
        (0, globals_1.expect)(output).not.toContain('joplin-frontmatter');
        // The --- should be treated as a horizontal rule
        (0, globals_1.expect)(output).toContain('<hr');
    });
    (0, globals_1.test)('should not parse frontmatter without closing delimiter', () => {
        const md = createMarkdownIt();
        const input = '---\ntitle: Test\n\n# Heading';
        const output = md.render(input);
        // Should not contain frontmatter class since there's no closing ---
        (0, globals_1.expect)(output).not.toContain('joplin-frontmatter');
        // The --- at the start becomes a horizontal rule
        (0, globals_1.expect)(output).toContain('<hr');
    });
    (0, globals_1.test)('should handle empty frontmatter block', () => {
        const md = createMarkdownIt();
        const input = '---\n---\n\n# Heading';
        const output = md.render(input);
        (0, globals_1.expect)(output).toContain('joplin-frontmatter');
        (0, globals_1.expect)(output).toContain('<h1>Heading</h1>');
    });
    (0, globals_1.test)('should include horizontal rule markers in rendered output', () => {
        const md = createMarkdownIt();
        const input = '---\ntitle: Test\n---\n\nContent';
        const output = md.render(input);
        // Should have the frontmatter markers (rendered as <hr>)
        (0, globals_1.expect)(output).toContain('joplin-frontmatter-marker');
    });
    (0, globals_1.test)('should have correct source-open and source-close attributes for round-trip editing', () => {
        const md = createMarkdownIt();
        const input = '---\nkey: value\n---\n\nText';
        const output = md.render(input);
        // The joplin-source should contain just the YAML content
        (0, globals_1.expect)(output).toContain('key: value');
        // The data-joplin-source-open should have the opening delimiter with newline
        (0, globals_1.expect)(output).toContain('data-joplin-source-open="---&#10;"');
        // The data-joplin-source-close should have newline + closing delimiter + newline
        (0, globals_1.expect)(output).toContain('data-joplin-source-close="&#10;---&#10;"');
    });
});
//# sourceMappingURL=frontmatter.test.js.map