"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MarkdownReactRenderer = void 0;
const tslib_1 = require("tslib");
const react_1 = tslib_1.__importStar(require("react"));
class MarkdownReactRenderer {
    constructor(options = {}) {
        this.uid = 0;
        this.options = options;
    }
    node(el, children = null, props = {}) {
        const elProps = {
            key: `marked-react-${this.uid}`,
        };
        this.incrementUID();
        return (0, react_1.createElement)(el, { ...props, ...elProps }, children);
    }
    incrementUID() {
        this.uid += 1;
    }
    heading(children, level) {
        return this.node(`h${level}`, children);
    }
    paragraph(children) {
        return this.node('p', children);
    }
    joinBase(path, base) {
        if (!base) {
            return path;
        }
        try {
            return new URL(path, base).href;
        }
        catch (_a) {
            return path;
        }
    }
    link(href, text) {
        const url = this.joinBase(href, this.options.baseURL);
        return this.node('a', text, { href: url, target: '_blank', rel: 'noopener noreferrer' });
    }
    image(src, alt, title = null) {
        const url = this.joinBase(src, this.options.baseURL);
        return this.node('img', null, { src: url, alt, title });
    }
    codespan(code, lang = null) {
        const className = lang ? `${this.options.langPrefix}${lang}` : null;
        return this.node('code', code, { className });
    }
    code(code, lang) {
        return this.node('pre', this.codespan(code, lang));
    }
    blockquote(children) {
        return this.node('blockquote', children);
    }
    list(children, ordered) {
        return this.node(ordered ? 'ol' : 'ul', children);
    }
    listItem(children) {
        return this.node('li', children);
    }
    checkbox(checked) {
        return this.node('input', null, { type: 'checkbox', disabled: true, checked });
    }
    table(children) {
        return this.node('table', children);
    }
    tableHeader(children) {
        return this.node('thead', children);
    }
    tableBody(children) {
        return this.node('tbody', children);
    }
    tableRow(children) {
        return this.node('tr', children);
    }
    tableCell(children, flags) {
        const tag = flags.header ? 'th' : 'td';
        return this.node(tag, children, { align: flags.align });
    }
    strong(children) {
        return this.node('strong', children);
    }
    em(children) {
        return this.node('em', children);
    }
    del(children) {
        return this.node('del', children);
    }
    text(text) {
        return text;
    }
    html(text) {
        return react_1.default.createElement("div", { dangerouslySetInnerHTML: { __html: text } });
    }
    hr() {
        return this.node('hr');
    }
    br() {
        return this.node('br');
    }
}
exports.MarkdownReactRenderer = MarkdownReactRenderer;
//# sourceMappingURL=render.js.map