diff --git a/apps/web/src/components/ui/report/plugins/markdown-kit/markdown-kit.tsx b/apps/web/src/components/ui/report/plugins/markdown-kit/markdown-kit.tsx
index 86ab9a389..7d036dfba 100644
--- a/apps/web/src/components/ui/report/plugins/markdown-kit/markdown-kit.tsx
+++ b/apps/web/src/components/ui/report/plugins/markdown-kit/markdown-kit.tsx
@@ -2,6 +2,7 @@ import { MarkdownPlugin as PlateMarkdownPlugin, remarkMdx, remarkMention } from
import remarkGfm from 'remark-gfm';
import { calloutSerializer } from './callout-serializer';
import { metricSerializer } from './metric-serializer';
+import { toggleSerializer } from './toggle-serializer';
const MarkdownPlugin = PlateMarkdownPlugin.configure({
options: {
@@ -9,6 +10,7 @@ const MarkdownPlugin = PlateMarkdownPlugin.configure({
rules: {
callout: calloutSerializer,
metric: metricSerializer,
+ toggle: toggleSerializer,
},
},
});
diff --git a/apps/web/src/components/ui/report/plugins/markdown-kit/platejs-conversion.test.ts b/apps/web/src/components/ui/report/plugins/markdown-kit/platejs-conversion.test.ts
index b80079d73..06f5a73c6 100644
--- a/apps/web/src/components/ui/report/plugins/markdown-kit/platejs-conversion.test.ts
+++ b/apps/web/src/components/ui/report/plugins/markdown-kit/platejs-conversion.test.ts
@@ -280,6 +280,14 @@ Here's an unordered list:
expect(firstElement.type).toBe('metric');
expect(firstElement.metricId).toBe('33af38a8-c40f-437d-98ed-1ec78ce35232');
});
+
+ it('toggle', async () => {
+ const markdown = ``;
+ const elements = await markdownToPlatejs(editor, markdown);
+ const firstElement = elements[0];
+ expect(firstElement.type).toBe('toggle');
+ expect(firstElement.children[0]).toEqual({ type: 'p', children: [{ text: 'This is toggle content' }] });
+ });
});
describe('platejsToMarkdown', () => {
diff --git a/apps/web/src/components/ui/report/plugins/markdown-kit/toggle-serializer.ts b/apps/web/src/components/ui/report/plugins/markdown-kit/toggle-serializer.ts
new file mode 100644
index 000000000..a891d5f5b
--- /dev/null
+++ b/apps/web/src/components/ui/report/plugins/markdown-kit/toggle-serializer.ts
@@ -0,0 +1,47 @@
+import {
+ deserializeMd,
+ type MdNodeParser,
+ parseAttributes,
+ serializeMd,
+} from '@platejs/markdown';
+
+export const toggleSerializer: MdNodeParser<'toggle'> = {
+ serialize: (node, options) => {
+ if (!options.editor) {
+ throw new Error('Editor is required');
+ }
+
+ const content = serializeMd(options.editor, {
+ ...options,
+ value: node.children,
+ });
+
+ return {
+ type: 'html',
+ value: ``,
+ };
+ },
+ deserialize: (node, _, options) => {
+ const typedAttributes = parseAttributes(node.attributes) as {
+ content: string;
+ };
+
+ if (!options.editor) {
+ throw new Error('Editor is required');
+ }
+
+ try {
+ const deserializedContent = deserializeMd(options.editor, typedAttributes.content);
+ return {
+ type: 'toggle',
+ children: deserializedContent,
+ };
+ } catch (error) {
+ console.error('Error deserializing content', error);
+ return {
+ type: 'toggle',
+ children: [{ text: typedAttributes.content }],
+ };
+ }
+ },
+};