import { rehype } from 'rehype'; // @ts-ignore import rehypePrism from 'rehype-prism-2'; import refractor from 'refractor'; export const processHtml = (html: string, syntax: refractor.RefractorSyntax | undefined) => { return rehype() .data('settings', { fragment: true }) .use(rehypePrism, { ignoreMissing: true, syntax: syntax }) .processSync(`${html}`) .toString(); }; // function htmlEncode(html: string) { // const temp = document.createElement ('div'); // (temp.textContent !== undefined) ? (temp.textContent = html) : (temp.innerText = html); // const output = temp.innerHTML; // return output; // } export function htmlEncode(sHtml: string) { return sHtml.replace( /[<>&"]/g, (c: string) => (({ '<': '<', '>': '>', '&': '&', '"': '"' } as Record)[c]), ); } export function stopPropagation(e: React.KeyboardEvent) { e.stopPropagation(); e.preventDefault(); }