import { Text } from 'slate';
export const richTextToHTML = (content: unknown): string => {
if (Array.isArray(content)) {
return content.reduce((output, node) => {
const isTextNode = Text.isText(node);
const {
text,
bold,
code,
italic,
underline,
strikethrough,
} = node;
if (isTextNode) {
// convert straight single quotations to curly
// "\u201C" is starting double curly
// "\u201D" is ending double curly
let html = text?.replace(/'/g, '\u2019'); // single quotes
if (bold) {
html = `${html}`;
}
if (code) {
html = `${html}`;
}
if (italic) {
html = `${html}`;
}
if (underline) {
html = `${html}`;
}
if (strikethrough) {
html = `${html}`;
}
return `${output}${html}`;
}
if (node) {
let nodeHTML;
switch (node.type) {
case 'h1':
nodeHTML = `
${richTextToHTML(node.children)}
`; break; default: nodeHTML = `${node.type}: