Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Md/suggestion #4130

Merged
merged 3 commits into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/nice-birds-share.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@udecode/plate-markdown': patch
---

Add `ignoreSuggestionType` to default retain the original document content, excluding the content after "suggestion."
24 changes: 24 additions & 0 deletions packages/markdown/src/lib/serializer/serializeMdNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ export interface SerializeMdOptions {
* @default ['disc', 'circle', 'square']
*/
ulListStyleTypes?: string[];

/** @default 'insert' */
ignoreSuggestionType?: 'insert' | 'remove' | 'update';
}

type MarkFormats = Record<
Expand Down Expand Up @@ -273,6 +276,27 @@ export function serializeMdNode(
}
}

// TODO: test
if ((node as any).suggestion) {
const ids: string[] = Object.keys(node).filter((key) => {
return key.startsWith(`suggestion_`);
});

const activeId = ids.at(-1);

if (activeId) {
const suggestionData = (node as any)[activeId];

const type = suggestionData.type as 'insert' | 'remove' | 'update';

const { ignoreSuggestionType = 'insert' } = opts;

if (type === ignoreSuggestionType) {
return;
}
}
}

return children;
}
if (elOptions?.enabled === false) {
Expand Down