craft.js icon indicating copy to clipboard operation
craft.js copied to clipboard

How do i get my html markup

Open fredrickreuben opened this issue 2 years ago • 2 comments

I am struggling to understand how to retrieve my HTML markup. Could you help me with this? Perhaps this information should be added to the documentation as well

fredrickreuben avatar Feb 06 '24 22:02 fredrickreuben


export default function renderToHTMLString (designerContent: string, title: string): Promise<string> {
    const data = getPreviewData(designerContent);
    const div = document.createElement('div');

    div.style.display = 'none';
    document.body.appendChild(div);

    const root = createRoot(div);

    flushSync(() => {
        root.render(<PreviewContent data={data}
            isRenderMode />);
    });

    return new Promise((resolve) => {
        setTimeout(() => {
            const html = div.innerHTML ?? '';
            div.remove();

            const embededHtml = getEmbededHtml(title, html);

            resolve(embededHtml);
        }, 250);
    });
}

See my sample code

reboottime avatar Feb 12 '24 15:02 reboottime

https://github.com/prevwong/craft.js/issues/42#issuecomment-796409445

Yhozen avatar Feb 20 '24 20:02 Yhozen