import { useEffect, useState } from "react";
import markdown_it from "markdown-it";
const md = new markdown_it({
    html: true,
    linkify: true,
    typographer: true,
    breaks: true
});
async function parseMarkdown(text) {
    if (!text) return text;
    return md.render(text);
}
function useParseMarkdown(text) {
    const [html, setHtml] = useState('');
    const [loading, setLoading] = useState(false);
    useEffect(()=>{
        setLoading(true);
        parseMarkdown(text).then((r)=>{
            setHtml(r);
            setLoading(false);
        });
    }, [
        text
    ]);
    return {
        html,
        loading
    };
}
function convertToText(markdownText) {
    const content = markdownText;
    let temp = document.createElement('div');
    temp.innerHTML = content;
    const text = temp.innerText;
    temp = null;
    return (null == text ? void 0 : text.replace(/[\n\r]/g, '')) || '';
}
export { convertToText, parseMarkdown, useParseMarkdown };
