import escapeHTML from 'escape-html';
import {
IS_BOLD,
IS_ITALIC,
IS_STRIKETHROUGH,
IS_UNDERLINE,
IS_CODE,
IS_SUBSCRIPT,
IS_SUPERSCRIPT,
} from './RichTextNodeFormat';
import type { SerializedLexicalNode } from './types';
function getLinkForPage(doc) {
return 'implement this';
}
export function serialize(children: SerializedLexicalNode[]): string[] {
return children
.map((node): string | null => {
if (node.type === 'text') {
//isText
let text = `${escapeHTML(node.text)}`;
if (node.format & IS_BOLD) {
text = `${text}`;
}
if (node.format & IS_ITALIC) {
text = `${text}`;
}
if (node.format & IS_STRIKETHROUGH) {
text = `${text}`;
}
if (node.format & IS_UNDERLINE) {
text = `${text}`;
}
if (node.format & IS_CODE) {
text = `${text}`;
}
if (node.format & IS_SUBSCRIPT) {
text = `${text}`;
}
if (node.format & IS_SUPERSCRIPT) {
text = `${text}`;
}
return `${text}`;
}
if (!node) {
return null;
}
const serializedChildren = node.children
? serialize(node.children).join('')
: null;
switch (node.type) {
case 'linebreak':
return `
`;
case 'link':
// eslint-disable-next-line no-case-declarations
const attributes: {
doc?;
linkType?: 'custom' | 'internal';
newTab?: boolean;
nofollow?: boolean;
rel?: string;
sponsored?: boolean;
url?: string;
} = node.attributes;
if (attributes.linkType === 'custom') {
return `${serializedChildren}`;
}
return `${serializedChildren}`; //TODO: Check doc link handling
case 'list': //TODO handle properly, especially nested lists
if (node.listType === 'bullet') {
return `
${serializedChildren ? serializedChildren : '
'}