"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Markdown = exports.DefaultMarkedRenderer = exports.linkify = void 0;
const tslib_1 = require("tslib");
const marked_1 = require("marked");
const react_1 = tslib_1.__importDefault(require("react"));
const render_1 = require("./render");
const linkify = (href, title, text) => `<a rel="noopener" ${render_1.DATA_SET_COMMAND}="${href}" title="${title !== null && title !== void 0 ? title : href}">${text}</a>`;
exports.linkify = linkify;
class DefaultMarkedRenderer extends marked_1.Renderer {
    link(href, title, text) {
        return (0, exports.linkify)(href, title, text);
    }
}
exports.DefaultMarkedRenderer = DefaultMarkedRenderer;
function Markdown(props) {
    const parseMarkdown = (text, renderer) => marked_1.marked.parse(text, { renderer });
    const [htmlContent, setHtmlContent] = react_1.default.useState(parseMarkdown(props.value || '', props.renderer));
    react_1.default.useEffect(() => {
        setHtmlContent(parseMarkdown(props.value || '', props.renderer));
    }, [props.renderer, props.value]);
    return react_1.default.createElement(render_1.RenderWrapper, { opener: props.opener, html: htmlContent });
}
exports.Markdown = Markdown;
//# sourceMappingURL=index.js.map