import { RichText } from "../types";
const toHtml = (rich_text: RichText[]) => {
const getChildren = ({ annotations, href, plain_text }: RichText) => {
const { bold, code, color, italic, strikethrough, underline } = annotations;
plain_text = plain_text
.replace(/{{/g, "")
.replace(/}}/g, "")
.replace(/\(\(/g, "")
.replace(/\)\)/g, "");
let children = plain_text;
if (bold) {
children = `${children}`;
}
if (code) {
children = `
${children}`;
}
if (strikethrough) {
children = `${children}`;
}
if (underline) {
children = `${children}`;
}
if (italic) {
children = `${children}`;
}
if (color && color !== "default") {
children = `${children}`;
}
if (href) {
children = `${children}`;
}
return `${children}`;
};
let text = [];
const length = rich_text.length;
for (let i = 0; i < length; i++) {
text.push(getChildren(rich_text[i]));
}
return text.join("");
};
export default toHtml;