buster/packages/server-utils/src/report/callout-serializer.ts

41 lines
1015 B
TypeScript
Raw Normal View History

2025-07-30 04:57:19 +08:00
import {
type MdNodeParser,
convertChildrenDeserialize,
parseAttributes,
2025-08-06 02:21:14 +08:00
serializeMd,
2025-07-30 04:57:19 +08:00
} from '@platejs/markdown';
export const calloutSerializer: MdNodeParser<'callout'> = {
serialize: (node, options) => {
// Extract the icon from the node (assuming it's stored as an attribute)
const icon = node.icon || '💡';
2025-08-06 02:21:14 +08:00
if (!options.editor) {
throw new Error('Editor is required');
}
const content = serializeMd(options.editor, {
...options,
value: node.children,
});
2025-07-30 04:57:19 +08:00
return {
2025-08-06 02:21:14 +08:00
type: 'html',
value: `<callout icon="${icon}">${content}</callout>`,
2025-07-30 04:57:19 +08:00
};
},
deserialize: (node, deco, options) => {
// Extract the icon attribute from the HTML element
const typedAttributes = parseAttributes(node.attributes) as {
icon: string;
};
// Return the PlateJS node structure
return {
type: 'callout',
icon: typedAttributes.icon,
children: convertChildrenDeserialize(node.children, deco, options),
};
},
};